comparison src/com/tmate/hgkit/console/Bundle.java @ 36:205f9b59b400

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