annotate src/org/tmatesoft/hg/internal/RevlogDump.java @ 294:32890bab7209

Issue 13: Report filenames as they are known in repository rather than from file system
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 14 Sep 2011 04:41:57 +0200
parents e9d275fb0bc0
children d45ad07dc94c
rev   line source
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 17
diff changeset
1 /*
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
2 * Copyright (c) 2010-2011 TMate Software Ltd
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
3 *
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
4 * This program is free software; you can redistribute it and/or modify
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
5 * it under the terms of the GNU General Public License as published by
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
6 * the Free Software Foundation; version 2 of the License.
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
7 *
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
8 * This program is distributed in the hope that it will be useful,
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
11 * GNU General Public License for more details.
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
12 *
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
13 * For information on how to redistribute this software under
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 88
diff changeset
15 * contact TMate Software at support@hg4j.com
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 17
diff changeset
16 */
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
17 package org.tmatesoft.hg.internal;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.BufferedInputStream;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.DataInput;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.DataInputStream;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.File;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.FileInputStream;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.math.BigInteger;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.zip.Inflater;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 /**
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
28 * Utility to test/debug/troubleshoot
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
29 *
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
30 * @author Artem Tikhomirov
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
31 * @author TMate Software Ltd.
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 */
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
33 public class RevlogDump {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
35 /**
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
36 * Takes 3 command line arguments -
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
37 * repository path,
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
38 * path to index file (i.e. store/data/hello.c.i) in the repository (relative)
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
39 * and "dumpData" whether to print actual content or just revlog headers
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
40 */
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public static void main(String[] args) throws Exception {
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
42 String repo = "/temp/hg/hello/.hg/";
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
43 String filename = "store/00changelog.i";
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 17
diff changeset
44 // String filename = "store/data/hello.c.i";
4
aa1912c70b36 Fix offset issue for inline revlogs. Commandline processing.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 3
diff changeset
45 // String filename = "store/data/docs/readme.i";
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
46 boolean dumpData = true;
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 73
diff changeset
47 if (args.length > 1) {
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
48 repo = args[0];
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
49 filename = args[1];
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 73
diff changeset
50 dumpData = args.length > 2 ? "dumpData".equals(args[2]) : false;
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
51 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 //
22
603806cd2dc6 Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 17
diff changeset
53 DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(new File(repo + filename))));
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 DataInput di = dis;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 dis.mark(10);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 int versionField = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 dis.reset();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 final int INLINEDATA = 1 << 16;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 boolean inlineData = (versionField & INLINEDATA) != 0;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 System.out.printf("%#8x, inline: %b\n", versionField, inlineData);
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
62 System.out.println("Index Offset Flags Packed Actual Base Rev Link Rev Parent1 Parent2 nodeid");
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 int entryCount = 0;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 while (dis.available() > 0) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 long l = di.readLong();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 long offset = l >>> 16;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 int flags = (int) (l & 0X0FFFF);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 int compressedLen = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 int actualLen = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 int baseRevision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 int linkRevision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 int parent1Revision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 int parent2Revision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 byte[] buf = new byte[32];
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 di.readFully(buf, 12, 20);
168
dd525ca65de8 Stupid defect that cost me couple of hours. What a coincidence for merge revision of interest (157) to be right on the BIS buffer boundary.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
76 dis.skipBytes(12);
dd525ca65de8 Stupid defect that cost me couple of hours. What a coincidence for merge revision of interest (157) to be right on the BIS buffer boundary.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
77 // CAN'T USE skip() here without extra precautions. E.g. I ran into situation when
dd525ca65de8 Stupid defect that cost me couple of hours. What a coincidence for merge revision of interest (157) to be right on the BIS buffer boundary.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
78 // buffer was 8192 and BufferedInputStream was at position 8182 before attempt to skip(12).
dd525ca65de8 Stupid defect that cost me couple of hours. What a coincidence for merge revision of interest (157) to be right on the BIS buffer boundary.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
79 // BIS silently skips available bytes and leaves me two extra bytes that ruin the rest of the code.
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
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));
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 if (inlineData) {
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
82 String resultString;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 byte[] data = new byte[compressedLen];
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 di.readFully(data);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 if (data[0] == 0x78 /* 'x' */) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 Inflater zlib = new Inflater();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 zlib.setInput(data, 0, compressedLen);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 byte[] result = new byte[actualLen*2];
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 int resultLen = zlib.inflate(result);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 zlib.end();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 resultString = new String(result, 0, resultLen, "UTF-8");
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
92 } else if (data[0] == 0x75 /* 'u' */) {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
93 resultString = new String(data, 1, data.length - 1, "UTF-8");
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
94 } else {
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
95 resultString = new String(data);
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
96 }
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
97 if (dumpData) {
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
98 System.out.println(resultString);
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
99 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
189
e9d275fb0bc0 Correct entry index when revlog has not inlined data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 168
diff changeset
101 entryCount++;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 dis.close();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 //
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }