diff src/com/tmate/hgkit/ll/HgBundle.java @ 37:e45e75e22523

Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 00:49:58 +0100
parents 205f9b59b400
children 4e9b66b07a28
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/HgBundle.java	Thu Jan 13 23:31:39 2011 +0100
+++ b/src/com/tmate/hgkit/ll/HgBundle.java	Fri Jan 14 00:49:58 2011 +0100
@@ -26,7 +26,29 @@
 		bundleFile = bundle;
 	}
 
-	public void read() throws IOException {
+	public void changes(HgRepository hgRepo) throws IOException {
+		DataAccess da = accessProvider.create(bundleFile);
+		try {
+			List<GroupElement> changelogGroup = readGroup(da);
+			byte[] baseRevContent = null;
+			for (GroupElement ge : changelogGroup) {
+				if (baseRevContent == null) {
+					// first parent is base revision, see bundlerepo.py
+					// if not prev: prev = p1 in bundlerevlog cons
+					baseRevContent = hgRepo.getChangelog().content(ge.firstParent());
+				}
+				int resultLen = 10000; // XXX calculate based on baseRevContent.length and ge.patches
+				byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches);
+				Changeset cs = Changeset.parse(csetContent, 0, csetContent.length);
+				cs.dump();
+				baseRevContent = csetContent;
+			}
+		} finally {
+			da.done();
+		}
+	}
+
+	public void dump() throws IOException {
 		DataAccess da = accessProvider.create(bundleFile);
 		try {
 			LinkedList<String> names = new LinkedList<String>();
@@ -34,12 +56,12 @@
 				System.out.println("Changelog group");
 				List<GroupElement> changelogGroup = readGroup(da);
 				for (GroupElement ge : changelogGroup) {
-					System.out.printf("  %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cs(), ge.patches.size());
+					System.out.printf("  %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size());
 				}
 				System.out.println("Manifest group");
 				List<GroupElement> manifestGroup = readGroup(da);
 				for (GroupElement ge : manifestGroup) {
-					System.out.printf("  %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cs(), ge.patches.size());
+					System.out.printf("  %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size());
 				}
 				while (!da.isEmpty()) {
 					int fnameLen = da.readInt();
@@ -52,7 +74,7 @@
 					List<GroupElement> fileGroup = readGroup(da);
 					System.out.println(names.getLast());
 					for (GroupElement ge : fileGroup) {
-						System.out.printf("  %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cs(), ge.patches.size());
+						System.out.printf("  %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size());
 					}
 				}
 			}
@@ -103,9 +125,8 @@
 		public Nodeid secondParent() {
 			return Nodeid.fromBinary(header, 40);
 		}
-		public Nodeid cs() {
+		public Nodeid cset() { // cs seems to be changeset
 			return Nodeid.fromBinary(header, 60);
 		}
-
 	}
 }