comparison src/com/tmate/hgkit/ll/HgBundle.java @ 39:4e9b66b07a28

Check changelog group starts with proper (known) base
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 01:07:05 +0100
parents e45e75e22523
children 858d1b2458cb
comparison
equal deleted inserted replaced
38:50dfc69c108e 39:4e9b66b07a28
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 try { 31 try {
32 List<GroupElement> changelogGroup = readGroup(da); 32 List<GroupElement> changelogGroup = readGroup(da);
33 byte[] baseRevContent = null; 33 if (changelogGroup.isEmpty()) {
34 throw new IllegalStateException("No changelog group in the bundle"); // XXX perhaps, just be silent and/or log?
35 }
36 // XXX in fact, bundle not necessarily starts with the first revision missing in hgRepo
37 // need to 'scroll' till the last one common.
38 final Nodeid base = changelogGroup.get(0).firstParent();
39 if (!hgRepo.getChangelog().isKnown(base)) {
40 throw new IllegalArgumentException("unknown parent");
41 }
42 // BundleFormat wiki says:
43 // Each Changelog entry patches the result of all previous patches
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 byte[] baseRevContent = hgRepo.getChangelog().content(base);
34 for (GroupElement ge : changelogGroup) { 46 for (GroupElement ge : changelogGroup) {
35 if (baseRevContent == null) {
36 // first parent is base revision, see bundlerepo.py
37 // if not prev: prev = p1 in bundlerevlog cons
38 baseRevContent = hgRepo.getChangelog().content(ge.firstParent());
39 }
40 int resultLen = 10000; // XXX calculate based on baseRevContent.length and ge.patches 47 int resultLen = 10000; // XXX calculate based on baseRevContent.length and ge.patches
41 byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches); 48 byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches);
42 Changeset cs = Changeset.parse(csetContent, 0, csetContent.length); 49 Changeset cs = Changeset.parse(csetContent, 0, csetContent.length);
43 cs.dump(); 50 cs.dump();
44 baseRevContent = csetContent; 51 baseRevContent = csetContent;