annotate src/org/tmatesoft/hg/repo/HgBundle.java @ 117:6c0be854d149

Enable filters for status operation (ToRepo case)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 04 Feb 2011 02:12:30 +0100
parents a3a2e5deb320
children 645829962785
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
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
24 import org.tmatesoft.hg.core.Nodeid;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
25 import org.tmatesoft.hg.internal.DataAccess;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
26 import org.tmatesoft.hg.internal.DataAccessProvider;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
27 import org.tmatesoft.hg.internal.DigestHelper;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
28 import org.tmatesoft.hg.internal.RevlogStream;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
29
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 /**
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * @see http://mercurial.selenic.com/wiki/BundleFormat
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
34 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
35 * @author TMate Software Ltd.
36
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 public class HgBundle {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 private final File bundleFile;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private final DataAccessProvider accessProvider;
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 HgBundle(DataAccessProvider dap, File bundle) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 accessProvider = dap;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 bundleFile = bundle;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46
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
47 public void changes(HgRepository hgRepo) throws IOException {
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
48 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
49 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
50 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
51 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
52 if (changelogGroup.isEmpty()) {
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
53 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
54 }
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
55 // 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
56 // 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
57 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
58 if (!hgRepo.getChangelog().isKnown(base)) {
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
59 throw new IllegalArgumentException("unknown parent");
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
60 }
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
61 // BundleFormat wiki says:
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
62 // 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
63 // (the previous, or parent patch of a given patch p is the patch that has a node equal to p's p1 field)
4e9b66b07a28 Check changelog group starts with proper (known) base
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 37
diff changeset
64 byte[] baseRevContent = hgRepo.getChangelog().content(base);
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
65 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
66 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
67 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
68 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
69 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
70 }
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
71 Changeset cs = Changeset.parse(csetContent, 0, csetContent.length);
47
b01500fe2604 Log command output to match 'hg log'
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 45
diff changeset
72 System.out.println(cs.toString());
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 baseRevContent = csetContent;
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
74 }
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
75 } 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
76 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
77 }
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
78 }
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
79
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
80 public void dump() throws IOException {
36
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 DataAccess da = accessProvider.create(bundleFile);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 try {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 LinkedList<String> names = new LinkedList<String>();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 if (!da.isEmpty()) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 System.out.println("Changelog group");
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 List<GroupElement> changelogGroup = readGroup(da);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 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
88 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
89 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 System.out.println("Manifest group");
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 List<GroupElement> manifestGroup = readGroup(da);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 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
93 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
94 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 while (!da.isEmpty()) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 int fnameLen = da.readInt();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 if (fnameLen <= 4) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 break; // null chunk, the last one.
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 byte[] fname = new byte[fnameLen - 4];
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 da.readBytes(fname, 0, fname.length);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 names.add(new String(fname));
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 List<GroupElement> fileGroup = readGroup(da);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 System.out.println(names.getLast());
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 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
106 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
107 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 System.out.println(names.size());
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 for (String s : names) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 System.out.println(s);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 } finally {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 da.done();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 }
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 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
120 int len = da.readInt();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 LinkedList<GroupElement> rv = new LinkedList<HgBundle.GroupElement>();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 while (len > 4 && !da.isEmpty()) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 byte[] nb = new byte[80];
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 da.readBytes(nb, 0, 80);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 int dataLength = len-84;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 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
127 while (dataLength > 0) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 RevlogStream.PatchRecord pr = RevlogStream.PatchRecord.read(da);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 patches.add(pr);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 dataLength -= pr.len + 12;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 rv.add(new GroupElement(nb, patches));
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 len = da.isEmpty() ? 0 : da.readInt();
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 return rv;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 static class GroupElement {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 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
140 private List<RevlogStream.PatchRecord> patches;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 GroupElement(byte[] fourNodeids, List<RevlogStream.PatchRecord> patchList) {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 assert fourNodeids != null && fourNodeids.length == 80;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 // patchList.size() > 0
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 header = fourNodeids;
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 patches = patchList;
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 public Nodeid node() {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 return Nodeid.fromBinary(header, 0);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 public Nodeid firstParent() {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 return Nodeid.fromBinary(header, 20);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 public Nodeid secondParent() {
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 return Nodeid.fromBinary(header, 40);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 }
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
157 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
158 return Nodeid.fromBinary(header, 60);
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 }
205f9b59b400 Strip parsing logic out from console frontend
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 }