annotate src/org/tmatesoft/hg/internal/RevlogDump.java @ 448:2e402c12ebc6 smartgit3

Issue 31: Revlog#walk() fails with AIOOBE when start > 0
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 06 Jun 2012 21:23:57 +0200
parents 656a6c1346ff
children f52ca9530774
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;
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
20 import java.io.ByteArrayInputStream;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.DataInput;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.DataInputStream;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.File;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.FileInputStream;
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
25 import java.io.IOException;
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
26 import java.io.UnsupportedEncodingException;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 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
28 import java.nio.ByteBuffer;
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
29 import java.nio.channels.FileChannel;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.zip.Inflater;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31
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 * Utility to test/debug/troubleshoot
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
34 *
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
35 * @author Artem Tikhomirov
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
36 * @author TMate Software Ltd.
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 */
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
38 public class RevlogDump {
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
40 /**
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
41 * Takes 3 command line arguments -
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
42 * repository path,
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
43 * 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
44 * 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
45 */
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public static void main(String[] args) throws Exception {
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
47 String repo = "/temp/hg/hello/.hg/";
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
48 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
49 // 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
50 // String filename = "store/data/docs/readme.i";
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
51 boolean dumpDataFull = true;
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
52 boolean dumpDataStats = false;
88
61eedab3eb3e Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 73
diff changeset
53 if (args.length > 1) {
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
54 repo = args[0];
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
55 filename = args[1];
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
56 dumpDataFull = args.length > 2 ? "dumpData".equals(args[2]) : false;
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
57 dumpDataStats = args.length > 2 ? "dumpDataStats".equals(args[2]) : false;
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
58 }
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
59 final boolean needRevData = dumpDataFull || dumpDataStats;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 //
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
61 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
62 DataInput di = dis;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 dis.mark(10);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 int versionField = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 dis.reset();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 final int INLINEDATA = 1 << 16;
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
68 final boolean inlineData = (versionField & INLINEDATA) != 0;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 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
70 FileChannel dataStream = null;
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
71 if (!inlineData && needRevData) {
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
72 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
73 }
73
0d279bcc4442 Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 47
diff changeset
74 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
75 int entryIndex = 0;
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 while (dis.available() > 0) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 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
78 long offset = entryIndex == 0 ? 0 : (l >>> 16);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 int flags = (int) (l & 0X0FFFF);
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 int compressedLen = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 int actualLen = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 int baseRevision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 int linkRevision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 int parent1Revision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 int parent2Revision = di.readInt();
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 byte[] buf = new byte[32];
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 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
88 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
89 // 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
90 // 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
91 // 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
92 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
93 String resultString;
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
94 byte[] data = new byte[compressedLen];
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 if (inlineData) {
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 di.readFully(data);
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
97 } else if (needRevData) {
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
98 dataStream.position(offset);
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
99 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
100 }
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
101 if (needRevData) {
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
102 if (compressedLen == 0) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
103 resultString = "<NO DATA>";
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
104 } else {
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
105 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
106 Inflater zlib = new Inflater();
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
107 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
108 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
109 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
110 zlib.end();
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
111 resultString = buildString(result, 0, resultLen, baseRevision != entryIndex, dumpDataFull);
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
112 } else if (data[0] == 0x75 /* 'u' */) {
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
113 resultString = buildString(data, 1, data.length - 1, baseRevision != entryIndex, dumpDataFull);
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
114 } else {
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
115 resultString = buildString(data, 0, data.length, baseRevision != entryIndex, dumpDataFull);
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
116 }
3
24bb4f365164 Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
117 }
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
118 System.out.println(resultString);
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
120 entryIndex++;
0
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 dis.close();
376
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
123 if (dataStream != null) {
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
124 dataStream.close();
d45ad07dc94c Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 189
diff changeset
125 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 //
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
392
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
128
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
129 private static String buildString(byte[] data, int offset, int len, boolean isPatch, boolean completeDataDump) throws IOException, UnsupportedEncodingException {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
130 if (isPatch) {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
131 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data, offset, len));
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
132 StringBuilder sb = new StringBuilder();
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
133 sb.append("<PATCH>:\n");
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
134 while (dis.available() > 0) {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
135 int s = dis.readInt();
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
136 int e = dis.readInt();
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
137 int l = dis.readInt();
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
138 sb.append(String.format("%d..%d, %d", s, e, l));
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
139 if (completeDataDump) {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
140 byte[] src = new byte[l];
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
141 dis.read(src, 0, l);
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
142 sb.append(":");
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
143 sb.append(new String(src, 0, l, "UTF-8"));
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
144 } else {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
145 dis.skipBytes(l);
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
146 }
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
147 sb.append('\n');
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
148 }
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
149 return sb.toString();
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
150 } else {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
151 if (completeDataDump) {
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
152 return new String(data, offset, len, "UTF-8");
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
153 }
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
154 return String.format("<DATA>:%d bytes", len-offset);
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
155 }
656a6c1346ff Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 376
diff changeset
156 }
0
dbd663faec1f Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 }