changeset 35:6061aa826a9e

Complete parsing of the bundle format
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Jan 2011 20:02:21 +0100
parents 51bc56c0addd
children 205f9b59b400
files src/com/tmate/hgkit/console/Bundle.java src/com/tmate/hgkit/ll/RevlogStream.java
diffstat 2 files changed, 39 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/tmate/hgkit/console/Bundle.java	Thu Jan 13 04:03:13 2011 +0100
+++ b/src/com/tmate/hgkit/console/Bundle.java	Thu Jan 13 20:02:21 2011 +0100
@@ -4,6 +4,7 @@
 package com.tmate.hgkit.console;
 
 import java.io.File;
+import java.util.LinkedList;
 
 import com.tmate.hgkit.fs.DataAccess;
 import com.tmate.hgkit.fs.DataAccessProvider;
@@ -21,23 +22,47 @@
 		DataAccessProvider dap = new DataAccessProvider();
 		DataAccess da = dap.create(bundleFile);
 		try {
-			while (!da.isEmpty()) {
-				int len = da.readInt();
-				while (len > 4) {
-					byte[] nb = new byte[80];
-					da.readBytes(nb, 0, 80);
-					Nodeid node = Nodeid.fromBinary(nb, 0);
-					Nodeid p1 = Nodeid.fromBinary(nb, 20);
-					Nodeid p2 = Nodeid.fromBinary(nb, 40);
-					Nodeid cs = Nodeid.fromBinary(nb, 60);
-					da.skip(len - 84);
-					System.out.printf("%6d %s %s %s %s\n", len, node, p1, p2, cs);
-					len = da.isEmpty() ? 0 : da.readInt();
+			LinkedList<String> names = new LinkedList<String>();
+			if (!da.isEmpty()) {
+				System.out.println("Changelog group");
+				readGroup(da);
+				System.out.println("Manifest group");
+				readGroup(da);
+				while (!da.isEmpty()) {
+					int fnameLen = da.readInt();
+					if (fnameLen <= 4) {
+						break; // null chunk, the last one.
+					}
+					byte[] fname = new byte[fnameLen - 4];
+					da.readBytes(fname, 0, fname.length);
+					names.add(new String(fname));
+					System.out.println(names.getLast());
+					readGroup(da);
 				}
-				System.out.println("Group done");
+			}
+			System.out.println(names.size());
+			for (String s : names) {
+				System.out.println(s);
 			}
 		} finally {
 			da.done();
 		}
 	}
+
+	private static void readGroup(DataAccess da) throws Exception {
+		int len = da.readInt();
+		while (len > 4 && !da.isEmpty()) {
+			byte[] nb = new byte[80];
+			da.readBytes(nb, 0, 80);
+			Nodeid node = Nodeid.fromBinary(nb, 0);
+			Nodeid p1 = Nodeid.fromBinary(nb, 20);
+			Nodeid p2 = Nodeid.fromBinary(nb, 40);
+			Nodeid cs = Nodeid.fromBinary(nb, 60);
+			byte[] data = new byte[len-84];
+			da.readBytes(data, 0, data.length);
+			System.out.printf("%6d %s %s %s %s\n", len, node, p1, p2, cs);
+			System.out.println(new String(data));
+			len = da.isEmpty() ? 0 : da.readInt();
+		}
+	}
 }
--- a/src/com/tmate/hgkit/ll/RevlogStream.java	Thu Jan 13 04:03:13 2011 +0100
+++ b/src/com/tmate/hgkit/ll/RevlogStream.java	Thu Jan 13 20:02:21 2011 +0100
@@ -304,6 +304,7 @@
 		return rv;
 	}
 
+	// @see http://mercurial.selenic.com/wiki/BundleFormat, in Changelog group description
 	static class PatchRecord { // copy of struct frag from mpatch.c
 		int start, end, len;
 		byte[] data;