diff src/org/tmatesoft/hg/repo/HgBundle.java @ 157:d5268ca7715b

Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 09 Mar 2011 05:22:17 +0100
parents src/com/tmate/hgkit/ll/HgBundle.java@9429c7bd1920 src/com/tmate/hgkit/ll/HgBundle.java@ba2bf656f00f
children 8c8e3f372fa1
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgBundle.java	Wed Mar 02 01:06:09 2011 +0100
+++ b/src/org/tmatesoft/hg/repo/HgBundle.java	Wed Mar 09 05:22:17 2011 +0100
@@ -21,12 +21,16 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.tmatesoft.hg.core.HgException;
 import org.tmatesoft.hg.core.Nodeid;
+import org.tmatesoft.hg.internal.ByteArrayChannel;
+import org.tmatesoft.hg.internal.ByteArrayDataAccess;
 import org.tmatesoft.hg.internal.DataAccess;
 import org.tmatesoft.hg.internal.DataAccessProvider;
 import org.tmatesoft.hg.internal.DigestHelper;
 import org.tmatesoft.hg.internal.RevlogStream;
 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
+import org.tmatesoft.hg.util.CancelledException;
 
 
 /**
@@ -45,7 +49,7 @@
 		bundleFile = bundle;
 	}
 
-	public void changes(HgRepository hgRepo) throws IOException {
+	public void changes(HgRepository hgRepo) throws HgException, IOException {
 		DataAccess da = accessProvider.create(bundleFile);
 		DigestHelper dh = new DigestHelper();
 		try {
@@ -62,17 +66,23 @@
 			// BundleFormat wiki says:
 			// Each Changelog entry patches the result of all previous patches 
 			// (the previous, or parent patch of a given patch p is the patch that has a node equal to p's p1 field)
-			byte[] baseRevContent = hgRepo.getChangelog().content(base);
+			ByteArrayChannel bac = new ByteArrayChannel();
+			hgRepo.getChangelog().rawContent(base, bac); // FIXME get DataAccess directly, to avoid
+			// extra byte[] (inside ByteArrayChannel) duplication just for the sake of subsequent ByteArrayDataChannel wrap.
+			ByteArrayDataAccess baseRevContent = new ByteArrayDataAccess(bac.toArray());
 			for (GroupElement ge : changelogGroup) {
 				byte[] csetContent = RevlogStream.apply(baseRevContent, -1, ge.patches);
 				dh = dh.sha1(ge.firstParent(), ge.secondParent(), csetContent); // XXX ge may give me access to byte[] content of nodeid directly, perhaps, I don't need DH to be friend of Nodeid?
 				if (!ge.node().equalsTo(dh.asBinary())) {
 					throw new IllegalStateException("Integrity check failed on " + bundleFile + ", node:" + ge.node());
 				}
-				RawChangeset cs = RawChangeset.parse(csetContent, 0, csetContent.length);
+				ByteArrayDataAccess csetDataAccess = new ByteArrayDataAccess(csetContent);
+				RawChangeset cs = RawChangeset.parse(csetDataAccess);
 				System.out.println(cs.toString());
-				baseRevContent = csetContent;
+				baseRevContent = csetDataAccess.reset();
 			}
+		} catch (CancelledException ex) {
+			System.out.println("Operation cancelled");
 		} finally {
 			da.done();
 		}