Mercurial > jhg
annotate src/org/tmatesoft/hg/core/HgFileRevision.java @ 520:1ee452f31187
Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 21 Dec 2012 21:20:26 +0100 |
parents | 934037edbea0 |
children | 6526d8adbc0f |
rev | line source |
---|---|
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
396
0ae53c32ecef
Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
2 * Copyright (c) 2011-2012 TMate Software Ltd |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.core; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import org.tmatesoft.hg.repo.HgDataFile; |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
20 import org.tmatesoft.hg.repo.HgManifest; |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
21 import org.tmatesoft.hg.repo.HgManifest.Flags; |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import org.tmatesoft.hg.repo.HgRepository; |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
23 import org.tmatesoft.hg.repo.HgRuntimeException; |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import org.tmatesoft.hg.util.ByteChannel; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.util.CancelledException; |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
26 import org.tmatesoft.hg.util.Pair; |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.util.Path; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 /** |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 * Keeps together information about specific file revision |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 * |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * @author Artem Tikhomirov |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * @author TMate Software Ltd. |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 */ |
249
4c3b9f679412
Deprecated HgLogCommand.FileRevision gone, top-level HgFileRevision is bright and shiny replacement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
237
diff
changeset
|
35 public final class HgFileRevision { |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 private final HgRepository repo; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 private final Nodeid revision; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 private final Path path; |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
39 private Path origin; |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
40 private Boolean isCopy = null; // null means not yet known |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
41 private Pair<Nodeid, Nodeid> parents; |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
42 private Flags flags; // null unless set/extracted |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
43 |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
44 /** |
431
12f668401613
FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
45 * New description of a file revision from a specific repository. |
12f668401613
FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
46 * |
12f668401613
FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
427
diff
changeset
|
47 * <p>Although this constructor is public, and clients can use it to construct own file revisions to pass e.g. to commands, its use is discouraged. |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
48 * |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
49 * @param hgRepo repository |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
50 * @param rev file revision |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
51 * @param manifestEntryFlags file flags at this revision (optional, may be null) |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
52 * @param p path of the file at the given revision |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
53 */ |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
54 public HgFileRevision(HgRepository hgRepo, Nodeid rev, HgManifest.Flags manifestEntryFlags, Path p) { |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 if (hgRepo == null || rev == null || p == null) { |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 // since it's package local, it is our code to blame for non validated arguments |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
57 throw new IllegalArgumentException(); |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 } |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 repo = hgRepo; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 revision = rev; |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
61 flags = manifestEntryFlags; |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 path = p; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 } |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
64 |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
65 // this cons shall be used when we know whether p was a copy. Perhaps, shall pass Map<Path,Path> instead to stress orig argument is not optional |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
66 HgFileRevision(HgRepository hgRepo, Nodeid rev, HgManifest.Flags flags, Path p, Path orig) { |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
67 this(hgRepo, rev, flags, p); |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
68 isCopy = Boolean.valueOf(orig == null); |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
69 origin = orig; |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
70 } |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 |
518
0d5e1ea7955e
Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
514
diff
changeset
|
72 HgFileRevision(HgDataFile fileNode, Nodeid fileRevision, Path origin) { |
514
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
73 this(fileNode.getRepo(), fileRevision, null, fileNode.getPath(), origin); |
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
74 } |
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
75 |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 public Path getPath() { |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 return path; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 } |
364
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
79 |
514
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
80 /** |
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
81 * Revision of the file |
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
82 * @return never <code>null</code> |
5dcb4581c8ef
Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
444
diff
changeset
|
83 */ |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 public Nodeid getRevision() { |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 return revision; |
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
87 |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
88 /** |
444
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
89 * Extract flags of the file as recorded in the manifest for this file revision |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
90 * @return whether regular file, executable or a symbolic link |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
91 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
92 */ |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
93 public HgManifest.Flags getFileFlags() throws HgRuntimeException { |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
94 if (flags == null) { |
444
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
95 /* |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
96 * Note, for uses other than HgManifestCommand or HgChangesetFileSneaker, when no flags come through the cons, |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
97 * it's possible to face next shortcoming: |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
98 * Imagine csetA and csetB, with corresponding manifestA and manifestB, the file didn't change (revision/nodeid is the same) |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
99 * but flag of the file has changed (e.g. became executable). Since HgFileRevision doesn't keep reference to |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
100 * an actual manifest revision, but only file's, and it's likely the flags returned from this method would |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
101 * yield result as from manifestA (i.e. no flag change in manifestB ever noticed). |
b3b1db9301a2
Few comments that emerged while working on examples
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
431
diff
changeset
|
102 */ |
415
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
103 HgDataFile df = repo.getFileNode(path); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
104 int revIdx = df.getRevisionIndex(revision); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
105 flags = df.getFlags(revIdx); |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
106 } |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
107 return flags; |
ee8264d80747
Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
396
diff
changeset
|
108 } |
364
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
109 |
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
110 public boolean wasCopied() throws HgException { |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
111 if (isCopy == null) { |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
112 checkCopy(); |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
113 } |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
114 return isCopy.booleanValue(); |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
115 } |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
116 /** |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
117 * @return <code>null</code> if {@link #wasCopied()} is <code>false</code>, name of the copy source otherwise. |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
118 */ |
364
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
119 public Path getOriginIfCopy() throws HgException { |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
120 if (wasCopied()) { |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
121 return origin; |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
122 } |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
123 return null; |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
124 } |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
125 |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
126 /** |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
127 * Access revisions this file revision originates from. |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
128 * Note, these revisions are records in the file history, not that of the whole repository (aka changeset revisions) |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
129 * In most cases, only one parent revision would be present, only for merge revisions one can expect both. |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
130 * |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
131 * @return parent revisions of this file revision, with {@link Nodeid#NULL} for missing values. |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
132 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
133 */ |
427
31a89587eb04
FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
134 public Pair<Nodeid, Nodeid> getParents() throws HgRuntimeException { |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
135 if (parents == null) { |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
136 HgDataFile fn = repo.getFileNode(path); |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
364
diff
changeset
|
137 int revisionIndex = fn.getRevisionIndex(revision); |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
138 int[] pr = new int[2]; |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
139 byte[] p1 = new byte[20], p2 = new byte[20]; |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
140 // XXX Revlog#parents is not the best method to use here |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
141 // need smth that gives Nodeids (piped through Pool<Nodeid> from repo's context) |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
364
diff
changeset
|
142 fn.parents(revisionIndex, pr, p1, p2); |
345
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
143 parents = new Pair<Nodeid, Nodeid>(Nodeid.fromBinary(p1, 0), Nodeid.fromBinary(p2, 0)); |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
144 } |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
145 return parents; |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
146 } |
58725dd511b3
Provide access to revision's origins
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
316
diff
changeset
|
147 |
396
0ae53c32ecef
Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
148 public void putContentTo(ByteChannel sink) throws HgException, CancelledException { |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 HgDataFile fn = repo.getFileNode(path); |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
364
diff
changeset
|
150 int revisionIndex = fn.getRevisionIndex(revision); |
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
364
diff
changeset
|
151 fn.contentWithFilters(revisionIndex, sink); |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 } |
519
934037edbea0
Few toString() implementations to ease debug
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
518
diff
changeset
|
153 |
934037edbea0
Few toString() implementations to ease debug
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
518
diff
changeset
|
154 @Override |
934037edbea0
Few toString() implementations to ease debug
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
518
diff
changeset
|
155 public String toString() { |
934037edbea0
Few toString() implementations to ease debug
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
518
diff
changeset
|
156 return String.format("HgFileRevision(%s, %s)", getPath().toString(), revision.shortNotation()); |
934037edbea0
Few toString() implementations to ease debug
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
518
diff
changeset
|
157 } |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 |
396
0ae53c32ecef
Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
159 private void checkCopy() throws HgException { |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
160 HgDataFile fn = repo.getFileNode(path); |
364
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
161 if (fn.isCopy()) { |
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
162 if (fn.getRevision(0).equals(revision)) { |
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
163 // this HgFileRevision represents first revision of the copy |
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
164 isCopy = Boolean.TRUE; |
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
165 origin = fn.getCopySourceName(); |
ac8e1ce67730
Expose errors dealign with Mercurial internals with Exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
166 return; |
316
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
167 } |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
168 } |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
169 isCopy = Boolean.FALSE; |
ee6b467c1a5f
Supply HGFileRevision with copy information when possible, calculate it otherwise
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
249
diff
changeset
|
170 } |
231
1792b37650f2
Introduced access to conflict resolution information (merge state)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 } |