Mercurial > hg4j
annotate 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 |
rev | line source |
---|---|
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.File; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.io.IOException; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.LinkedList; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.List; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
24 import org.tmatesoft.hg.core.HgException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
25 import org.tmatesoft.hg.core.Nodeid; |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
26 import org.tmatesoft.hg.internal.ByteArrayChannel; |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
27 import org.tmatesoft.hg.internal.ByteArrayDataAccess; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
28 import org.tmatesoft.hg.internal.DataAccess; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
29 import org.tmatesoft.hg.internal.DataAccessProvider; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
30 import org.tmatesoft.hg.internal.DigestHelper; |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
31 import org.tmatesoft.hg.internal.RevlogStream; |
154
ba2bf656f00f
Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
129
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
33 import org.tmatesoft.hg.util.CancelledException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
34 |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 /** |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @see http://mercurial.selenic.com/wiki/BundleFormat |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
39 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
40 * @author TMate Software Ltd. |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 */ |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 public class HgBundle { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 private final File bundleFile; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private final DataAccessProvider accessProvider; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 public HgBundle(DataAccessProvider dap, File bundle) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 accessProvider = dap; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 bundleFile = bundle; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
52 public void changes(HgRepository hgRepo) throws HgException, IOException { |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
53 DataAccess da = accessProvider.create(bundleFile); |
41
858d1b2458cb
Check integrity for bundle changelog. Sort nodeids when calculating hash
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
39
diff
changeset
|
54 DigestHelper dh = new DigestHelper(); |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
55 try { |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
56 List<GroupElement> changelogGroup = readGroup(da); |
39
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
57 if (changelogGroup.isEmpty()) { |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
58 throw new IllegalStateException("No changelog group in the bundle"); // XXX perhaps, just be silent and/or log? |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
59 } |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
60 // XXX in fact, bundle not necessarily starts with the first revision missing in hgRepo |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
61 // need to 'scroll' till the last one common. |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
62 final Nodeid base = changelogGroup.get(0).firstParent(); |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
63 if (!hgRepo.getChangelog().isKnown(base)) { |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
64 throw new IllegalArgumentException("unknown parent"); |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
65 } |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
66 // BundleFormat wiki says: |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
67 // Each Changelog entry patches the result of all previous patches |
4e9b66b07a28
Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
37
diff
changeset
|
68 // (the previous, or parent patch of a given patch p is the patch that has a node equal to p's p1 field) |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
69 ByteArrayChannel bac = new ByteArrayChannel(); |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
70 hgRepo.getChangelog().rawContent(base, bac); // FIXME get DataAccess directly, to avoid |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
71 // extra byte[] (inside ByteArrayChannel) duplication just for the sake of subsequent ByteArrayDataChannel wrap. |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
72 ByteArrayDataAccess baseRevContent = new ByteArrayDataAccess(bac.toArray()); |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
73 for (GroupElement ge : changelogGroup) { |
43
1b26247d7367
Calculate result length of the patch operarion, when unknown
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
42
diff
changeset
|
74 byte[] csetContent = RevlogStream.apply(baseRevContent, -1, ge.patches); |
42
92c3d0920d58
Real integrity check, with exception. DigestHelper refactored to accomodate new needs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
41
diff
changeset
|
75 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? |
92c3d0920d58
Real integrity check, with exception. DigestHelper refactored to accomodate new needs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
41
diff
changeset
|
76 if (!ge.node().equalsTo(dh.asBinary())) { |
92c3d0920d58
Real integrity check, with exception. DigestHelper refactored to accomodate new needs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
41
diff
changeset
|
77 throw new IllegalStateException("Integrity check failed on " + bundleFile + ", node:" + ge.node()); |
92c3d0920d58
Real integrity check, with exception. DigestHelper refactored to accomodate new needs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
41
diff
changeset
|
78 } |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
79 ByteArrayDataAccess csetDataAccess = new ByteArrayDataAccess(csetContent); |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
80 RawChangeset cs = RawChangeset.parse(csetDataAccess); |
47
b01500fe2604
Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
45
diff
changeset
|
81 System.out.println(cs.toString()); |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
82 baseRevContent = csetDataAccess.reset(); |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
83 } |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
84 } catch (CancelledException ex) { |
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
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
85 System.out.println("Operation cancelled"); |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
86 } finally { |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
87 da.done(); |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
88 } |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
89 } |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
90 |
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
91 public void dump() throws IOException { |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 DataAccess da = accessProvider.create(bundleFile); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 try { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 LinkedList<String> names = new LinkedList<String>(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 if (!da.isEmpty()) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 System.out.println("Changelog group"); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 List<GroupElement> changelogGroup = readGroup(da); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 for (GroupElement ge : changelogGroup) { |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
99 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size()); |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 System.out.println("Manifest group"); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 List<GroupElement> manifestGroup = readGroup(da); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 for (GroupElement ge : manifestGroup) { |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
104 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size()); |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 while (!da.isEmpty()) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 int fnameLen = da.readInt(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 if (fnameLen <= 4) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 break; // null chunk, the last one. |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 byte[] fname = new byte[fnameLen - 4]; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 da.readBytes(fname, 0, fname.length); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 names.add(new String(fname)); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 List<GroupElement> fileGroup = readGroup(da); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 System.out.println(names.getLast()); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 for (GroupElement ge : fileGroup) { |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
117 System.out.printf(" %s %s %s %s; patches:%d\n", ge.node(), ge.firstParent(), ge.secondParent(), ge.cset(), ge.patches.size()); |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 System.out.println(names.size()); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 for (String s : names) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 System.out.println(s); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 } finally { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 da.done(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 private static List<GroupElement> readGroup(DataAccess da) throws IOException { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 int len = da.readInt(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 LinkedList<GroupElement> rv = new LinkedList<HgBundle.GroupElement>(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 while (len > 4 && !da.isEmpty()) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 byte[] nb = new byte[80]; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 da.readBytes(nb, 0, 80); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 int dataLength = len-84; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 LinkedList<RevlogStream.PatchRecord> patches = new LinkedList<RevlogStream.PatchRecord>(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 while (dataLength > 0) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 RevlogStream.PatchRecord pr = RevlogStream.PatchRecord.read(da); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 patches.add(pr); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 dataLength -= pr.len + 12; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 rv.add(new GroupElement(nb, patches)); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 len = da.isEmpty() ? 0 : da.readInt(); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 return rv; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 static class GroupElement { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 private byte[] header; // byte[80] takes 120 bytes, 4 Nodeids - 192 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 private List<RevlogStream.PatchRecord> patches; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 GroupElement(byte[] fourNodeids, List<RevlogStream.PatchRecord> patchList) { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 assert fourNodeids != null && fourNodeids.length == 80; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 // patchList.size() > 0 |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 header = fourNodeids; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 patches = patchList; |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 public Nodeid node() { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 return Nodeid.fromBinary(header, 0); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 public Nodeid firstParent() { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 return Nodeid.fromBinary(header, 20); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 public Nodeid secondParent() { |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 return Nodeid.fromBinary(header, 40); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 } |
37
e45e75e22523
Parse changesets from bundle's changelog group. Refactor Revlog to provide access to revision's raw content
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
36
diff
changeset
|
168 public Nodeid cset() { // cs seems to be changeset |
36
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 return Nodeid.fromBinary(header, 60); |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 } |
205f9b59b400
Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 } |