diff src/com/tmate/hgkit/ll/HgManifest.java @ 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 08db726a0fb7
children 254078595653
line wrap: on
line diff
--- 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);
 	}
 }