annotate src/com/tmate/hgkit/console/Bundle.java @ 34:51bc56c0addd

Static Nodeid creation methods to reuse NULL id
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Jan 2011 04:03:13 +0100
parents 42585c7cd641
children 6061aa826a9e
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;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 import com.tmate.hgkit.fs.DataAccess;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 import com.tmate.hgkit.fs.DataAccessProvider;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 import com.tmate.hgkit.ll.Nodeid;
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11
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 * @see http://mercurial.selenic.com/wiki/BundleFormat
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 *
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * @author artem
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 public class Bundle {
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 public static void main(String[] args) throws Exception {
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 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
21 DataAccessProvider dap = new DataAccessProvider();
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 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
23 try {
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
24 while (!da.isEmpty()) {
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
25 int len = da.readInt();
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
26 while (len > 4) {
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
27 byte[] nb = new byte[80];
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
28 da.readBytes(nb, 0, 80);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
29 Nodeid node = Nodeid.fromBinary(nb, 0);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
30 Nodeid p1 = Nodeid.fromBinary(nb, 20);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
31 Nodeid p2 = Nodeid.fromBinary(nb, 40);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
32 Nodeid cs = Nodeid.fromBinary(nb, 60);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
33 da.skip(len - 84);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
34 System.out.printf("%6d %s %s %s %s\n", len, node, p1, p2, cs);
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
35 len = da.isEmpty() ? 0 : da.readInt();
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
36 }
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
37 System.out.println("Group done");
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 }
34
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
39 } finally {
51bc56c0addd Static Nodeid creation methods to reuse NULL id
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 32
diff changeset
40 da.done();
32
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 }
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 }
42585c7cd641 Initial dump of a bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }