annotate src/org/tmatesoft/hg/internal/RevlogDump.java @ 387:cdea37239b01

Issue 23: HgInvalidRevisionException for svn imported repository (changeset 0 references nullid manifest). Tests
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 13 Feb 2012 15:11:27 +0100
parents d45ad07dc94c
children 656a6c1346ff
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;
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
25 import java.nio.ByteBuffer;
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
26 import java.nio.channels.FileChannel;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.zip.Inflater;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 /**
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
30 * Utility to test/debug/troubleshoot
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
31 *
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
32 * @author Artem Tikhomirov
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
33 * @author TMate Software Ltd.
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 public class RevlogDump {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
37 /**
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
38 * Takes 3 command line arguments -
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
39 * repository path,
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
40 * 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
41 * 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
42 */
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 public static void main(String[] args) throws Exception {
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
44 String repo = "/temp/hg/hello/.hg/";
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
45 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
46 // 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
47 // String filename = "store/data/docs/readme.i";
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
48 boolean dumpData = true;
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 73
diff changeset
49 if (args.length > 1) {
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
50 repo = args[0];
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
51 filename = args[1];
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 73
diff changeset
52 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
53 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 //
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
55 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
56 DataInput di = dis;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 dis.mark(10);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 int versionField = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 dis.reset();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 final int INLINEDATA = 1 << 16;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
62 final boolean inlineData = (versionField & INLINEDATA) != 0;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 System.out.printf("%#8x, inline: %b\n", versionField, inlineData);
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
64 FileChannel dataStream = null;
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
65 if (!inlineData && dumpData) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
66 dataStream = new FileInputStream(new File(repo, filename.substring(0, filename.length()-2) + ".d")).getChannel();
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
67 }
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
68 System.out.println("Index Offset Flags Packed Actual Base Rev Link Rev Parent1 Parent2 nodeid");
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
69 int entryIndex = 0;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 while (dis.available() > 0) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 long l = di.readLong();
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
72 long offset = entryIndex == 0 ? 0 : (l >>> 16);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 int flags = (int) (l & 0X0FFFF);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 int compressedLen = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 int actualLen = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 int baseRevision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 int linkRevision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 int parent1Revision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 int parent2Revision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 byte[] buf = new byte[32];
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 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
82 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
83 // 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
84 // 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
85 // BIS silently skips available bytes and leaves me two extra bytes that ruin the rest of the code.
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
86 System.out.printf("%4d:%14d %6X %10d %10d %10d %10d %8d %8d %040x\n", entryIndex, offset, flags, compressedLen, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, new BigInteger(buf));
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
87 String resultString;
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
88 byte[] data = new byte[compressedLen];
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 if (inlineData) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 di.readFully(data);
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
91 } else if (dumpData) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
92 dataStream.position(offset);
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
93 dataStream.read(ByteBuffer.wrap(data));
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
94 }
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
95 if (dumpData) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
96 if (compressedLen == 0) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
97 resultString = "<NO DATA>";
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
98 } else {
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
99 if (data[0] == 0x78 /* 'x' */) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
100 Inflater zlib = new Inflater();
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
101 zlib.setInput(data, 0, compressedLen);
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
102 byte[] result = new byte[actualLen*2];
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
103 int resultLen = zlib.inflate(result);
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
104 zlib.end();
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
105 resultString = new String(result, 0, resultLen, "UTF-8");
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
106 } else if (data[0] == 0x75 /* 'u' */) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
107 resultString = new String(data, 1, data.length - 1, "UTF-8");
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
108 } else {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
109 resultString = new String(data);
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
110 }
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
111 }
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
112 System.out.println(resultString);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
114 entryIndex++;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 dis.close();
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
117 if (dataStream != null) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
118 dataStream.close();
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
119 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 //
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 }