# HG changeset patch # User Artem Tikhomirov # Date 1321928080 -3600 # Node ID 58725dd511b3c5854f52b4e6d771877f46c9f748 # Parent 168f1994de7e23c358266d21ba623061ce54f244 Provide access to revision's origins diff -r 168f1994de7e -r 58725dd511b3 cmdline/org/tmatesoft/hg/console/Main.java --- a/cmdline/org/tmatesoft/hg/console/Main.java Tue Nov 22 02:57:14 2011 +0100 +++ b/cmdline/org/tmatesoft/hg/console/Main.java Tue Nov 22 03:14:40 2011 +0100 @@ -99,7 +99,7 @@ // m.testParents(); // m.testEffectiveFileLog(); // m.testCatAtCsetRevision(); - m.testMergeState(); +// m.testMergeState(); // m.testFileStatus(); // m.dumpBranches(); // m.inflaterLengthException(); @@ -108,7 +108,7 @@ // m.testStatusInternals(); // m.catCompleteHistory(); // m.dumpCompleteManifestLow(); -// m.dumpCompleteManifestHigh(); + m.dumpCompleteManifestHigh(); // m.bunchOfTests(); } @@ -496,6 +496,8 @@ public void file(HgFileRevision fileRevision) { System.out.print(fileRevision.getRevision());; System.out.print(" "); + System.out.printf("%s %s", fileRevision.getParents().first().shortNotation(), fileRevision.getParents().second().shortNotation()); + System.out.print(" "); System.out.println(fileRevision.getPath()); } diff -r 168f1994de7e -r 58725dd511b3 src/org/tmatesoft/hg/core/HgFileRevision.java --- a/src/org/tmatesoft/hg/core/HgFileRevision.java Tue Nov 22 02:57:14 2011 +0100 +++ b/src/org/tmatesoft/hg/core/HgFileRevision.java Tue Nov 22 03:14:40 2011 +0100 @@ -21,6 +21,7 @@ import org.tmatesoft.hg.repo.HgRepository; import org.tmatesoft.hg.util.ByteChannel; import org.tmatesoft.hg.util.CancelledException; +import org.tmatesoft.hg.util.Pair; import org.tmatesoft.hg.util.Path; /** @@ -35,6 +36,7 @@ private final Path path; private Path origin; private Boolean isCopy = null; // null means not yet known + private Pair parents; public HgFileRevision(HgRepository hgRepo, Nodeid rev, Path p) { if (hgRepo == null || rev == null || p == null) { @@ -75,6 +77,27 @@ return null; } + /** + * Access revisions this file revision originates from. + * Note, these revisions are records in the file history, not that of the whole repository (aka changeset revisions) + * In most cases, only one parent revision would be present, only for merge revisions one can expect both. + * + * @return parent revisions of this file revision, with {@link Nodeid#NULL} for missing values. + */ + public Pair getParents() { + if (parents == null) { + HgDataFile fn = repo.getFileNode(path); + int localRevision = fn.getLocalRevision(revision); + int[] pr = new int[2]; + byte[] p1 = new byte[20], p2 = new byte[20]; + // XXX Revlog#parents is not the best method to use here + // need smth that gives Nodeids (piped through Pool from repo's context) + fn.parents(localRevision, pr, p1, p2); + parents = new Pair(Nodeid.fromBinary(p1, 0), Nodeid.fromBinary(p2, 0)); + } + return parents; + } + public void putContentTo(ByteChannel sink) throws HgDataStreamException, CancelledException { HgDataFile fn = repo.getFileNode(path); int localRevision = fn.getLocalRevision(revision);