changeset 13:df8c67f3006a

Basic manifest parsing to analyze what's in there
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 26 Dec 2010 03:21:17 +0100
parents 181fccc176ef
children 442dc6ee647b
files src/com/tmate/hgkit/console/Manifest.java src/com/tmate/hgkit/ll/HgManifest.java src/com/tmate/hgkit/ll/HgRepository.java src/com/tmate/hgkit/ll/Nodeid.java
diffstat 4 files changed, 70 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/tmate/hgkit/console/Manifest.java	Sun Dec 26 03:21:17 2010 +0100
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010 Artem Tikhomirov 
+ */
+package com.tmate.hgkit.console;
+
+import com.tmate.hgkit.fs.RepositoryLookup;
+import com.tmate.hgkit.ll.HgRepository;
+
+/**
+ *
+ * @author artem
+ */
+public class Manifest {
+
+	public static void main(String[] args) throws Exception {
+		RepositoryLookup repoLookup = new RepositoryLookup();
+		RepositoryLookup.Options cmdLineOpts = RepositoryLookup.Options.parse(args);
+		HgRepository hgRepo = repoLookup.detect(cmdLineOpts);
+		if (hgRepo.isInvalid()) {
+			System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
+			return;
+		}
+		System.out.println(hgRepo.getLocation());
+		hgRepo.getManifest().dump();
+	}
+}
--- a/src/com/tmate/hgkit/ll/HgManifest.java	Sun Dec 26 02:17:39 2010 +0100
+++ b/src/com/tmate/hgkit/ll/HgManifest.java	Sun Dec 26 03:21:17 2010 +0100
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2010 Artem Tikhomirov 
  */
 package com.tmate.hgkit.ll;
@@ -9,7 +9,46 @@
  */
 public class HgManifest extends Revlog {
 
-	/*package-local*/ HgManifest(HgRepository hgRepo) {
+	private final RevlogStream content;
+
+	/*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) {
 		super(hgRepo);
+		this.content = content;
+	}
+
+	public void dump() {
+		Revlog.Inspector insp = new Revlog.Inspector() {
+			public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, byte[] data) {
+				System.out.println(revisionNumber);
+				int i;
+				String fname = null;
+				String flags = null;
+				Nodeid nid = null;
+				for (i = 0; i < actualLen; i++) {
+					int x = i;
+					for( ; data[i] != '\n' && i < actualLen; i++) {
+						if (fname == null && data[i] == 0) {
+							fname = new String(data, x, i - x);
+							x = i+1;
+						}
+					}
+					if (i < actualLen) {
+						assert data[i] == '\n'; 
+						int nodeidLen = i - x < 40 ? i-x : 40;
+						nid = Nodeid.fromAscii(data, x, nodeidLen);
+						if (nodeidLen + x < i) {
+							// 'x' and 'l' for executable bits and symlinks?
+							// hg --debug manifest shows 644 for each regular file in my repo
+							flags = new String(data, x + nodeidLen, i-x-nodeidLen);
+						}
+						System.out.println(nid + "\t" + fname + "\t\t" + flags);
+					}
+					nid = null;
+					fname = flags = null;
+				}
+				System.out.println();
+			}
+		};
+		content.iterate(0, -1, true, insp);
 	}
 }
--- a/src/com/tmate/hgkit/ll/HgRepository.java	Sun Dec 26 02:17:39 2010 +0100
+++ b/src/com/tmate/hgkit/ll/HgRepository.java	Sun Dec 26 03:21:17 2010 +0100
@@ -41,7 +41,8 @@
 	
 	public final HgManifest getManifest() {
 		if (this.manifest == null) {
-			this.manifest = new HgManifest(this);
+			RevlogStream content = resolve(toStoragePath("00manifest.i", false));
+			this.manifest = new HgManifest(this, content);
 		}
 		return this.manifest;
 	}
--- a/src/com/tmate/hgkit/ll/Nodeid.java	Sun Dec 26 02:17:39 2010 +0100
+++ b/src/com/tmate/hgkit/ll/Nodeid.java	Sun Dec 26 03:21:17 2010 +0100
@@ -22,7 +22,7 @@
 
 	@Override
 	public String toString() {
-		return new DigestHelper().toHexString(binaryData, 0, 20);
+		return new DigestHelper().toHexString(binaryData, 0, binaryData.length);
 	}
 
 	// binascii.unhexlify()