annotate src/com/tmate/hgkit/console/Bundle.java @ 35:6061aa826a9e

Complete parsing of the bundle format
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Jan 2011 20:02:21 +0100
parents 51bc56c0addd
children 205f9b59b400
rev   line source
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 Artem Tikhomirov
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 */
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 package com.tmate.hgkit.console;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 import java.io.File;
35
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
7 import java.util.LinkedList;
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 import com.tmate.hgkit.fs.DataAccess;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 import com.tmate.hgkit.fs.DataAccessProvider;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 import com.tmate.hgkit.ll.Nodeid;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 /**
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * @see http://mercurial.selenic.com/wiki/BundleFormat
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 *
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 * @author artem
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 */
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18 public class Bundle {
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 public static void main(String[] args) throws Exception {
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 File bundleFile = new File("/temp/hg/hg-bundle-a78c980749e3.tmp");
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 DataAccessProvider dap = new DataAccessProvider();
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 DataAccess da = dap.create(bundleFile);
34
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
24 try {
35
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
25 LinkedList<String> names = new LinkedList<String>();
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
26 if (!da.isEmpty()) {
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
27 System.out.println("Changelog group");
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
28 readGroup(da);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
29 System.out.println("Manifest group");
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
30 readGroup(da);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
31 while (!da.isEmpty()) {
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
32 int fnameLen = da.readInt();
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
33 if (fnameLen <= 4) {
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
34 break; // null chunk, the last one.
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
35 }
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
36 byte[] fname = new byte[fnameLen - 4];
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
37 da.readBytes(fname, 0, fname.length);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
38 names.add(new String(fname));
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
39 System.out.println(names.getLast());
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
40 readGroup(da);
34
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
41 }
35
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
42 }
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
43 System.out.println(names.size());
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
44 for (String s : names) {
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
45 System.out.println(s);
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 }
34
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
47 } finally {
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
48 da.done();
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 }
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
35
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
51
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
52 private static void readGroup(DataAccess da) throws Exception {
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
53 int len = da.readInt();
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
54 while (len > 4 && !da.isEmpty()) {
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
55 byte[] nb = new byte[80];
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
56 da.readBytes(nb, 0, 80);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
57 Nodeid node = Nodeid.fromBinary(nb, 0);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
58 Nodeid p1 = Nodeid.fromBinary(nb, 20);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
59 Nodeid p2 = Nodeid.fromBinary(nb, 40);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
60 Nodeid cs = Nodeid.fromBinary(nb, 60);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
61 byte[] data = new byte[len-84];
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
62 da.readBytes(data, 0, data.length);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
63 System.out.printf("%6d %s %s %s %s\n", len, node, p1, p2, cs);
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
64 System.out.println(new String(data));
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
65 len = da.isEmpty() ? 0 : da.readInt();
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
66 }
6061aa826a9e Complete parsing of the bundle format
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 34
diff changeset
67 }
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }