changeset 345:58725dd511b3

Provide access to revision's origins
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Nov 2011 03:14:40 +0100
parents 168f1994de7e
children 6d2c6b2469fc
files cmdline/org/tmatesoft/hg/console/Main.java src/org/tmatesoft/hg/core/HgFileRevision.java
diffstat 2 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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());
 			}
 			
--- 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<Nodeid, Nodeid> 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<Nodeid, Nodeid> 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<Nodeid> from repo's context)
+			fn.parents(localRevision, pr, p1, p2);
+			parents = new Pair<Nodeid, Nodeid>(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);