diff src/com/tmate/hgkit/ll/HgBundle.java @ 42:92c3d0920d58

Real integrity check, with exception. DigestHelper refactored to accomodate new needs
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 04:29:03 +0100
parents 858d1b2458cb
children 1b26247d7367
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/HgBundle.java	Fri Jan 14 04:14:08 2011 +0100
+++ b/src/com/tmate/hgkit/ll/HgBundle.java	Fri Jan 14 04:29:03 2011 +0100
@@ -48,8 +48,10 @@
 				int resultLen = 10000; // XXX calculate based on baseRevContent.length and ge.patches
 				byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches);
 				// wiki suggests sha1_digest(min(p1,p2) ++ max(p1,p2) ++ final_text),
-				String digest = 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?
-				System.out.println("Node: " + ge.node() + ", digest: " + digest);
+				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());
+				}
 				Changeset cs = Changeset.parse(csetContent, 0, csetContent.length);
 				cs.dump();
 				baseRevContent = csetContent;