comparison hg4j/src/main/java/org/tmatesoft/hg/internal/RevlogDump.java @ 213:6ec4af642ba8 gradle

Project uses Gradle for build - actual changes
author Alexander Kitaev <kitaev@gmail.com>
date Tue, 10 May 2011 10:52:53 +0200
parents
children
comparison
equal deleted inserted replaced
212:edb2e2829352 213:6ec4af642ba8
1 /*
2 * Copyright (c) 2010-2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.internal;
18
19 import java.io.BufferedInputStream;
20 import java.io.DataInput;
21 import java.io.DataInputStream;
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.math.BigInteger;
25 import java.util.zip.Inflater;
26
27 /**
28 * Utility to test/debug/troubleshoot
29 *
30 * @author Artem Tikhomirov
31 * @author TMate Software Ltd.
32 */
33 public class RevlogDump {
34
35 /**
36 * Takes 3 command line arguments -
37 * repository path,
38 * path to index file (i.e. store/data/hello.c.i) in the repository (relative)
39 * and "dumpData" whether to print actual content or just revlog headers
40 */
41 public static void main(String[] args) throws Exception {
42 String repo = "/temp/hg/hello/.hg/";
43 String filename = "store/00changelog.i";
44 // String filename = "store/data/hello.c.i";
45 // String filename = "store/data/docs/readme.i";
46 boolean dumpData = true;
47 if (args.length > 1) {
48 repo = args[0];
49 filename = args[1];
50 dumpData = args.length > 2 ? "dumpData".equals(args[2]) : false;
51 }
52 //
53 DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(repo + filename))));
54 DataInput di = dis;
55 dis.mark(10);
56 int versionField = di.readInt();
57 dis.reset();
58 final int INLINEDATA = 1 << 16;
59
60 boolean inlineData = (versionField & INLINEDATA) != 0;
61 System.out.printf("%#8x, inline: %b\n", versionField, inlineData);
62 System.out.println("Index Offset Flags Packed Actual Base Rev Link Rev Parent1 Parent2 nodeid");
63 int entryCount = 0;
64 while (dis.available() > 0) {
65 long l = di.readLong();
66 long offset = l >>> 16;
67 int flags = (int) (l & 0X0FFFF);
68 int compressedLen = di.readInt();
69 int actualLen = di.readInt();
70 int baseRevision = di.readInt();
71 int linkRevision = di.readInt();
72 int parent1Revision = di.readInt();
73 int parent2Revision = di.readInt();
74 byte[] buf = new byte[32];
75 di.readFully(buf, 12, 20);
76 dis.skipBytes(12);
77 // CAN'T USE skip() here without extra precautions. E.g. I ran into situation when
78 // buffer was 8192 and BufferedInputStream was at position 8182 before attempt to skip(12).
79 // BIS silently skips available bytes and leaves me two extra bytes that ruin the rest of the code.
80 System.out.printf("%4d:%14d %6X %10d %10d %10d %10d %8d %8d %040x\n", entryCount, offset, flags, compressedLen, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, new BigInteger(buf));
81 if (inlineData) {
82 String resultString;
83 byte[] data = new byte[compressedLen];
84 di.readFully(data);
85 if (data[0] == 0x78 /* 'x' */) {
86 Inflater zlib = new Inflater();
87 zlib.setInput(data, 0, compressedLen);
88 byte[] result = new byte[actualLen*2];
89 int resultLen = zlib.inflate(result);
90 zlib.end();
91 resultString = new String(result, 0, resultLen, "UTF-8");
92 } else if (data[0] == 0x75 /* 'u' */) {
93 resultString = new String(data, 1, data.length - 1, "UTF-8");
94 } else {
95 resultString = new String(data);
96 }
97 if (dumpData) {
98 System.out.println(resultString);
99 }
100 }
101 entryCount++;
102 }
103 dis.close();
104 //
105 }
106 }