comparison src/com/tmate/hgkit/ll/HgBundle.java @ 41:858d1b2458cb

Check integrity for bundle changelog. Sort nodeids when calculating hash
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 04:14:08 +0100
parents 4e9b66b07a28
children 92c3d0920d58
comparison
equal deleted inserted replaced
40:21e26da142fa 41:858d1b2458cb
26 bundleFile = bundle; 26 bundleFile = bundle;
27 } 27 }
28 28
29 public void changes(HgRepository hgRepo) throws IOException { 29 public void changes(HgRepository hgRepo) throws IOException {
30 DataAccess da = accessProvider.create(bundleFile); 30 DataAccess da = accessProvider.create(bundleFile);
31 DigestHelper dh = new DigestHelper();
31 try { 32 try {
32 List<GroupElement> changelogGroup = readGroup(da); 33 List<GroupElement> changelogGroup = readGroup(da);
33 if (changelogGroup.isEmpty()) { 34 if (changelogGroup.isEmpty()) {
34 throw new IllegalStateException("No changelog group in the bundle"); // XXX perhaps, just be silent and/or log? 35 throw new IllegalStateException("No changelog group in the bundle"); // XXX perhaps, just be silent and/or log?
35 } 36 }
44 // (the previous, or parent patch of a given patch p is the patch that has a node equal to p's p1 field) 45 // (the previous, or parent patch of a given patch p is the patch that has a node equal to p's p1 field)
45 byte[] baseRevContent = hgRepo.getChangelog().content(base); 46 byte[] baseRevContent = hgRepo.getChangelog().content(base);
46 for (GroupElement ge : changelogGroup) { 47 for (GroupElement ge : changelogGroup) {
47 int resultLen = 10000; // XXX calculate based on baseRevContent.length and ge.patches 48 int resultLen = 10000; // XXX calculate based on baseRevContent.length and ge.patches
48 byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches); 49 byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches);
50 // wiki suggests sha1_digest(min(p1,p2) ++ max(p1,p2) ++ final_text),
51 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?
52 System.out.println("Node: " + ge.node() + ", digest: " + digest);
49 Changeset cs = Changeset.parse(csetContent, 0, csetContent.length); 53 Changeset cs = Changeset.parse(csetContent, 0, csetContent.length);
50 cs.dump(); 54 cs.dump();
51 baseRevContent = csetContent; 55 baseRevContent = csetContent;
52 } 56 }
53 } finally { 57 } finally {