Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 36:205f9b59b400 | 37:e45e75e22523 |
|---|---|
| 24 public HgBundle(DataAccessProvider dap, File bundle) { | 24 public HgBundle(DataAccessProvider dap, File bundle) { |
| 25 accessProvider = dap; | 25 accessProvider = dap; |
| 26 bundleFile = bundle; | 26 bundleFile = bundle; |
| 27 } | 27 } |
| 28 | 28 |
| 29 public void read() throws IOException { | 29 public void changes(HgRepository hgRepo) throws IOException { |
| 30 DataAccess da = accessProvider.create(bundleFile); | |
| 31 try { | |
| 32 List<GroupElement> changelogGroup = readGroup(da); | |
| 33 byte[] baseRevContent = null; | |
| 34 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 | |
| 41 byte[] csetContent = RevlogStream.apply(baseRevContent, resultLen, ge.patches); | |
| 42 Changeset cs = Changeset.parse(csetContent, 0, csetContent.length); | |
| 43 cs.dump(); | |
| 44 baseRevContent = csetContent; | |
| 45 } | |
| 46 } finally { | |
| 47 da.done(); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 public void dump() throws IOException { | |
| 30 DataAccess da = accessProvider.create(bundleFile); | 52 DataAccess da = accessProvider.create(bundleFile); |
| 31 try { | 53 try { |
| 32 LinkedList<String> names = new LinkedList<String>(); | 54 LinkedList<String> names = new LinkedList<String>(); |
| 33 if (!da.isEmpty()) { | 55 if (!da.isEmpty()) { |
| 34 System.out.println("Changelog group"); | 56 System.out.println("Changelog group"); |
| 35 List<GroupElement> changelogGroup = readGroup(da); | 57 List<GroupElement> changelogGroup = readGroup(da); |
| 36 for (GroupElement ge : changelogGroup) { | 58 for (GroupElement ge : changelogGroup) { |
| 37 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cs(), ge.patches.size()); | 59 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size()); |
| 38 } | 60 } |
| 39 System.out.println("Manifest group"); | 61 System.out.println("Manifest group"); |
| 40 List<GroupElement> manifestGroup = readGroup(da); | 62 List<GroupElement> manifestGroup = readGroup(da); |
| 41 for (GroupElement ge : manifestGroup) { | 63 for (GroupElement ge : manifestGroup) { |
| 42 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cs(), ge.patches.size()); | 64 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size()); |
| 43 } | 65 } |
| 44 while (!da.isEmpty()) { | 66 while (!da.isEmpty()) { |
| 45 int fnameLen = da.readInt(); | 67 int fnameLen = da.readInt(); |
| 46 if (fnameLen <= 4) { | 68 if (fnameLen <= 4) { |
| 47 break; // null chunk, the last one. | 69 break; // null chunk, the last one. |
| 50 da.readBytes(fname, 0, fname.length); | 72 da.readBytes(fname, 0, fname.length); |
| 51 names.add(new String(fname)); | 73 names.add(new String(fname)); |
| 52 List<GroupElement> fileGroup = readGroup(da); | 74 List<GroupElement> fileGroup = readGroup(da); |
| 53 System.out.println(names.getLast()); | 75 System.out.println(names.getLast()); |
| 54 for (GroupElement ge : fileGroup) { | 76 for (GroupElement ge : fileGroup) { |
| 55 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cs(), ge.patches.size()); | 77 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size()); |
| 56 } | 78 } |
| 57 } | 79 } |
| 58 } | 80 } |
| 59 System.out.println(names.size()); | 81 System.out.println(names.size()); |
| 60 for (String s : names) { | 82 for (String s : names) { |
| 101 return Nodeid.fromBinary(header, 20); | 123 return Nodeid.fromBinary(header, 20); |
| 102 } | 124 } |
| 103 public Nodeid secondParent() { | 125 public Nodeid secondParent() { |
| 104 return Nodeid.fromBinary(header, 40); | 126 return Nodeid.fromBinary(header, 40); |
| 105 } | 127 } |
| 106 public Nodeid cs() { | 128 public Nodeid cset() { // cs seems to be changeset |
| 107 return Nodeid.fromBinary(header, 60); | 129 return Nodeid.fromBinary(header, 60); |
| 108 } | 130 } |
| 109 | |
| 110 } | 131 } |
| 111 } | 132 } |
