changeset 56:576d6e8a09f6

Analog of 'hg status --change' command
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 17 Jan 2011 05:15:13 +0100
parents 05829a70b30b
children 8b0d6f1bd6b4
files src/com/tmate/hgkit/console/Status.java src/com/tmate/hgkit/ll/HgDataFile.java src/com/tmate/hgkit/ll/Revlog.java src/com/tmate/hgkit/ll/StatusCollector.java
diffstat 4 files changed, 78 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/tmate/hgkit/console/Status.java	Mon Jan 17 04:45:09 2011 +0100
+++ b/src/com/tmate/hgkit/console/Status.java	Mon Jan 17 05:15:13 2011 +0100
@@ -45,6 +45,9 @@
 		sortAndPrint('M', r.getModified());
 		sortAndPrint('A', r.getAdded());
 		sortAndPrint('R', r.getRemoved());
+		//
+		System.out.println("\n\nTry hg status --change <rev>:");
+		sc.change(0, dump);
 //		System.out.println("\nStatus against working dir:");
 //		((LocalHgRepo) hgRepo).statusLocal(TIP, dump);
 //		System.out.println();
--- a/src/com/tmate/hgkit/ll/HgDataFile.java	Mon Jan 17 04:45:09 2011 +0100
+++ b/src/com/tmate/hgkit/ll/HgDataFile.java	Mon Jan 17 05:15:13 2011 +0100
@@ -5,10 +5,8 @@
 
 import static com.tmate.hgkit.ll.HgRepository.TIP;
 
-import java.util.Arrays;
 
 /**
- * Extends Revlog/uses RevlogStream?
  * ? name:HgFileNode?
  * @author artem
  */
@@ -59,61 +57,4 @@
 		content.iterate(start, end, false, insp);
 		getRepo().getChangelog().range(inspector, commitRevisions);
 	}
-
-	/**
-	 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query?
-	 * 
-	 * @param revision - revision to query parents, or {@link HgRepository#TIP}
-	 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1})
-	 * @param parent1 - byte[20] or null, if parent's nodeid is not needed
-	 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
-	 * @return
-	 */
-	public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) {
-		if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) {
-			throw new IllegalArgumentException(String.valueOf(revision));
-		}
-		if (parentRevisions == null || parentRevisions.length < 2) {
-			throw new IllegalArgumentException(String.valueOf(parentRevisions));
-		}
-		if (parent1 != null && parent1.length < 20) {
-			throw new IllegalArgumentException(parent1.toString());
-		}
-		if (parent2 != null && parent2.length < 20) {
-			throw new IllegalArgumentException(parent2.toString());
-		}
-		class ParentCollector implements Revlog.Inspector {
-			public int p1 = -1;
-			public int p2 = -1;
-			public byte[] nodeid;
-			
-			public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
-				p1 = parent1Revision;
-				p2 = parent2Revision;
-				this.nodeid = new byte[20];
-				// nodeid arg now comes in 32 byte from (as in file format description), however upper 12 bytes are zeros.
-				System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20);
-			}
-		};
-		ParentCollector pc = new ParentCollector();
-		content.iterate(revision, revision, false, pc);
-		parentRevisions[0] = pc.p1;
-		parentRevisions[1] = pc.p2;
-		if (parent1 != null) {
-			if (parentRevisions[0] == -1) {
-				Arrays.fill(parent1, 0, 20, (byte) 0);
-			} else {
-				content.iterate(parentRevisions[0], parentRevisions[0], false, pc);
-				System.arraycopy(pc.nodeid, 0, parent1, 0, 20);
-			}
-		}
-		if (parent2 != null) {
-			if (parentRevisions[1] == -1) {
-				Arrays.fill(parent2, 0, 20, (byte) 0);
-			} else {
-				content.iterate(parentRevisions[1], parentRevisions[1], false, pc);
-				System.arraycopy(pc.nodeid, 0, parent2, 0, 20);
-			}
-		}
-	}
 }
--- a/src/com/tmate/hgkit/ll/Revlog.java	Mon Jan 17 04:45:09 2011 +0100
+++ b/src/com/tmate/hgkit/ll/Revlog.java	Mon Jan 17 05:15:13 2011 +0100
@@ -3,6 +3,9 @@
  */
 package com.tmate.hgkit.ll;
 
+import static com.tmate.hgkit.ll.HgRepository.TIP;
+
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -78,6 +81,63 @@
 		return dataPtr[0];
 	}
 
+	/**
+	 * XXX perhaps, return value Nodeid[2] and boolean needNodeids is better (and higher level) API for this query?
+	 * 
+	 * @param revision - revision to query parents, or {@link HgRepository#TIP}
+	 * @param parentRevisions - int[2] to get local revision numbers of parents (e.g. {6, -1})
+	 * @param parent1 - byte[20] or null, if parent's nodeid is not needed
+	 * @param parent2 - byte[20] or null, if second parent's nodeid is not needed
+	 * @return
+	 */
+	public void parents(int revision, int[] parentRevisions, byte[] parent1, byte[] parent2) {
+		if (revision != TIP && !(revision >= 0 && revision < content.revisionCount())) {
+			throw new IllegalArgumentException(String.valueOf(revision));
+		}
+		if (parentRevisions == null || parentRevisions.length < 2) {
+			throw new IllegalArgumentException(String.valueOf(parentRevisions));
+		}
+		if (parent1 != null && parent1.length < 20) {
+			throw new IllegalArgumentException(parent1.toString());
+		}
+		if (parent2 != null && parent2.length < 20) {
+			throw new IllegalArgumentException(parent2.toString());
+		}
+		class ParentCollector implements Revlog.Inspector {
+			public int p1 = -1;
+			public int p2 = -1;
+			public byte[] nodeid;
+			
+			public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
+				p1 = parent1Revision;
+				p2 = parent2Revision;
+				this.nodeid = new byte[20];
+				// nodeid arg now comes in 32 byte from (as in file format description), however upper 12 bytes are zeros.
+				System.arraycopy(nodeid, nodeid.length > 20 ? nodeid.length - 20 : 0, this.nodeid, 0, 20);
+			}
+		};
+		ParentCollector pc = new ParentCollector();
+		content.iterate(revision, revision, false, pc);
+		parentRevisions[0] = pc.p1;
+		parentRevisions[1] = pc.p2;
+		if (parent1 != null) {
+			if (parentRevisions[0] == -1) {
+				Arrays.fill(parent1, 0, 20, (byte) 0);
+			} else {
+				content.iterate(parentRevisions[0], parentRevisions[0], false, pc);
+				System.arraycopy(pc.nodeid, 0, parent1, 0, 20);
+			}
+		}
+		if (parent2 != null) {
+			if (parentRevisions[1] == -1) {
+				Arrays.fill(parent2, 0, 20, (byte) 0);
+			} else {
+				content.iterate(parentRevisions[1], parentRevisions[1], false, pc);
+				System.arraycopy(pc.nodeid, 0, parent2, 0, 20);
+			}
+		}
+	}
+
 	// FIXME byte[] data might be too expensive, for few usecases it may be better to have intermediate Access object (when we don't need full data 
 	// instantly - e.g. calculate hash, or comparing two revisions
 	// XXX seems that RevlogStream is better place for this class. 
--- a/src/com/tmate/hgkit/ll/StatusCollector.java	Mon Jan 17 04:45:09 2011 +0100
+++ b/src/com/tmate/hgkit/ll/StatusCollector.java	Mon Jan 17 05:15:13 2011 +0100
@@ -24,6 +24,10 @@
 	public StatusCollector(HgRepository hgRepo) {
 		this.repo = hgRepo;
 		cache = new HashMap<Integer, ManifestRevisionInspector>();
+		ManifestRevisionInspector emptyFakeState = new ManifestRevisionInspector(-1, -1);
+		emptyFakeState.begin(-1, null);
+		emptyFakeState.end(-1);
+		cache.put(-1, emptyFakeState);
 	}
 	
 	private ManifestRevisionInspector get(int rev) {
@@ -35,7 +39,17 @@
 		}
 		return i;
 	}
+	
+	// hg status --change <rev>
+	public void change(int rev, Inspector inspector) {
+		int[] parents = new int[2];
+		repo.getChangelog().parents(rev, parents, null, null);
+		walk(parents[0], rev, inspector);
+	}
 
+	// I assume revision numbers are the same for changelog and manifest - here 
+	// user would like to pass changelog revision numbers, and I use them directly to walk manifest.
+	// if this assumption is wrong, fix this (lookup manifest revisions from changeset).
 	public void walk(int rev1, int rev2, Inspector inspector) {
 		if (rev1 == rev2) {
 			throw new IllegalArgumentException();
@@ -198,6 +212,7 @@
 
 		/**
 		 * [minRev, maxRev]
+		 * [-1,-1] also accepted (for fake empty instance)
 		 * @param minRev - inclusive
 		 * @param maxRev - inclusive
 		 */