Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevlogDump.java @ 558:154718ae23ed
Annotate: refactor/reuse range handling code
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 25 Feb 2013 18:41:44 +0100 |
parents | e6f72c9829a6 |
children | 47dfa0ec7e35 |
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 /* |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
2 * Copyright (c) 2010-2013 TMate Software Ltd |
73
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; |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
30 import java.util.regex.Matcher; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
31 import java.util.regex.Pattern; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import java.util.zip.Inflater; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 |
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 * Utility to test/debug/troubleshoot |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
36 * |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
37 * @author Artem Tikhomirov |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
38 * @author TMate Software Ltd. |
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 public class RevlogDump { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
42 /** |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
43 * Takes 3 command line arguments - |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
44 * repository path, |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
45 * 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
|
46 * 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
|
47 */ |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 public static void main(String[] args) throws Exception { |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
49 String repo = "/temp/hg/hello/.hg/"; |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
50 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
|
51 // 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
|
52 // String filename = "store/data/docs/readme.i"; |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
53 System.out.println(escape("abc\0def\nzxc\tmnb")); |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
54 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
|
55 boolean dumpDataStats = false; |
88
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
73
diff
changeset
|
56 if (args.length > 1) { |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
57 repo = args[0]; |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 } |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
62 final boolean needRevData = dumpDataFull || dumpDataStats; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 // |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
64 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
|
65 DataInput di = dis; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 dis.mark(10); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 int versionField = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 dis.reset(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 final int INLINEDATA = 1 << 16; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
71 final boolean inlineData = (versionField & INLINEDATA) != 0; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 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
|
73 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
|
74 if (!inlineData && needRevData) { |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
75 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
|
76 } |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
77 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
|
78 int entryIndex = 0; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 while (dis.available() > 0) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 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
|
81 long offset = entryIndex == 0 ? 0 : (l >>> 16); |
420
6c22bdc0bdfd
Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
394
diff
changeset
|
82 int flags = (int) (l & 0x0FFFF); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 int compressedLen = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 int actualLen = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 int baseRevision = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 int linkRevision = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 int parent1Revision = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 int parent2Revision = di.readInt(); |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 byte[] buf = new byte[32]; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 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
|
91 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
|
92 // 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
|
93 // 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
|
94 // 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
|
95 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
|
96 String resultString; |
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
97 byte[] data = new byte[compressedLen]; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 if (inlineData) { |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 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
|
100 } else if (needRevData) { |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
101 dataStream.position(offset); |
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
102 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
|
103 } |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
104 if (needRevData) { |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
105 if (compressedLen == 0) { |
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
106 resultString = "<NO DATA>"; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
107 } else { |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
108 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
|
109 Inflater zlib = new Inflater(); |
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 } 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
|
116 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
|
117 } 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
|
118 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
|
119 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
120 } |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
121 System.out.println(resultString); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 } |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
123 entryIndex++; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 dis.close(); |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
126 if (dataStream != null) { |
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
127 dataStream.close(); |
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
128 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 // |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 } |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
131 |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 sb.append(":"); |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
146 sb.append(escape(new String(src, 0, l, "UTF-8"))); |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
147 } else { |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
148 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
|
149 } |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
150 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
|
151 } |
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 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
|
153 } else { |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
154 if (completeDataDump) { |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
155 return escape(new String(data, offset, len, "UTF-8")); |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
156 } |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
157 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
|
158 } |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
159 } |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
160 |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
161 private static Pattern controlCharPattern = Pattern.compile("\\p{Cntrl}"); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
162 // \p{Cntrl} A control character: [\x00-\x1F\x7F] |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
163 private static String[] replacements = new String[33]; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
164 static { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
165 for (int i = 0; i < 32; i++) { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
166 // no idea why need FOUR backslashes to get only one in printout |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
167 replacements[i] = String.format("\\\\%X", i); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
168 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
169 replacements[32] = String.format("\\\\%X", 127); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
170 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
171 // handy to get newline-separated data printed on newlines. |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
172 // set to false for non-printable data (e.g. binaries, where \n doesn't make sense) |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
173 private static boolean leaveNewlineInData = true; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
174 |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
175 private static String escape(CharSequence possiblyWithBinary) { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
176 Matcher m = controlCharPattern.matcher(possiblyWithBinary); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
177 StringBuffer rv = new StringBuffer(); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
178 while (m.find()) { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
179 char c = m.group().charAt(0); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
180 if (leaveNewlineInData && c == '\n') { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
181 continue; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
182 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
183 int x = (int) c; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
184 m.appendReplacement(rv, replacements[x == 127 ? 32 : x]); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
185 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
186 m.appendTail(rv); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
187 return rv.toString(); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
188 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 } |