comparison 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
comparison
equal deleted inserted replaced
34:51bc56c0addd 35:6061aa826a9e
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;
7 8
8 import com.tmate.hgkit.fs.DataAccess; 9 import com.tmate.hgkit.fs.DataAccess;
9 import com.tmate.hgkit.fs.DataAccessProvider; 10 import com.tmate.hgkit.fs.DataAccessProvider;
10 import com.tmate.hgkit.ll.Nodeid; 11 import com.tmate.hgkit.ll.Nodeid;
11 12
19 public static void main(String[] args) throws Exception { 20 public static void main(String[] args) throws Exception {
20 File bundleFile = new File("/temp/hg/hg-bundle-a78c980749e3.tmp"); 21 File bundleFile = new File("/temp/hg/hg-bundle-a78c980749e3.tmp");
21 DataAccessProvider dap = new DataAccessProvider(); 22 DataAccessProvider dap = new DataAccessProvider();
22 DataAccess da = dap.create(bundleFile); 23 DataAccess da = dap.create(bundleFile);
23 try { 24 try {
24 while (!da.isEmpty()) { 25 LinkedList<String> names = new LinkedList<String>();
25 int len = da.readInt(); 26 if (!da.isEmpty()) {
26 while (len > 4) { 27 System.out.println("Changelog group");
27 byte[] nb = new byte[80]; 28 readGroup(da);
28 da.readBytes(nb, 0, 80); 29 System.out.println("Manifest group");
29 Nodeid node = Nodeid.fromBinary(nb, 0); 30 readGroup(da);
30 Nodeid p1 = Nodeid.fromBinary(nb, 20); 31 while (!da.isEmpty()) {
31 Nodeid p2 = Nodeid.fromBinary(nb, 40); 32 int fnameLen = da.readInt();
32 Nodeid cs = Nodeid.fromBinary(nb, 60); 33 if (fnameLen <= 4) {
33 da.skip(len - 84); 34 break; // null chunk, the last one.
34 System.out.printf("%6d %s %s %s %s\n", len, node, p1, p2, cs); 35 }
35 len = da.isEmpty() ? 0 : da.readInt(); 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);
36 } 41 }
37 System.out.println("Group done"); 42 }
43 System.out.println(names.size());
44 for (String s : names) {
45 System.out.println(s);
38 } 46 }
39 } finally { 47 } finally {
40 da.done(); 48 da.done();
41 } 49 }
42 } 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 }
43 } 68 }