Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevlogDump.java @ 587:a52f4cc56f9c
Minimize vectors re-allocating when merging patches
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 26 Apr 2013 20:04:17 +0200 |
parents | 47dfa0ec7e35 |
children |
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; |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
32 import java.util.zip.DataFormatException; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import java.util.zip.Inflater; |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 /** |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
36 * Utility to test/debug/troubleshoot |
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 * @author Artem Tikhomirov |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
39 * @author TMate Software Ltd. |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 */ |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
41 public class RevlogDump { |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
43 /** |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
44 * Takes 3 command line arguments - |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
45 * repository path, |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
46 * 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
|
47 * 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
|
48 */ |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public static void main(String[] args) throws Exception { |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
50 String repo = "/temp/hg/hello/.hg/"; |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
51 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
|
52 // 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
|
53 // String filename = "store/data/docs/readme.i"; |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
54 // 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
|
55 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
|
56 boolean dumpDataStats = false; |
88
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
73
diff
changeset
|
57 if (args.length > 1) { |
73
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
58 repo = args[0]; |
0d279bcc4442
Utility for future troubleshooting
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
47
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 } |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
63 final boolean needRevData = dumpDataFull || dumpDataStats; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 // |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
65 RevlogReader rr = new RevlogReader(new File(repo, filename)).needData(needRevData); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
66 rr.init(needRevData); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
67 System.out.printf("%#8x, inline: %b\n", rr.versionField, rr.inlineData); |
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"); |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
69 ByteBuffer data = null; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
70 while (rr.hasMore()) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
71 rr.readNext(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
72 System.out.printf("%4d:%14d %6X %10d %10d %10d %10d %8d %8d %040x\n", rr.entryIndex, rr.offset, rr.flags, rr.compressedLen, rr.actualLen, rr.baseRevision, rr.linkRevision, rr.parent1Revision, rr.parent2Revision, new BigInteger(rr.nodeid)); |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
73 if (needRevData) { |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
74 String resultString; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
75 if (rr.getDataLength() == 0) { |
376
d45ad07dc94c
Allow content dump for separate .i and .d files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
189
diff
changeset
|
76 resultString = "<NO DATA>"; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
77 } else { |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
78 data = ensureCapacity(data, rr.getDataLength()); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
79 rr.getData(data); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
80 data.flip(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
81 resultString = buildString(data, rr.isPatch(), dumpDataFull); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
82 } |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
83 if (resultString.endsWith("\n")) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
84 System.out.print(resultString); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
85 } else { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
86 System.out.println(resultString); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
87 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
90 rr.done(); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 } |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
92 |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
93 private static ByteBuffer ensureCapacity(ByteBuffer src, int requiredCap) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
94 if (src == null || src.capacity() < requiredCap) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
95 return ByteBuffer.allocate((1 + requiredCap) * 3 / 2); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
96 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
97 src.clear(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
98 return src; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
99 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
100 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
101 private static String buildString(ByteBuffer data, boolean isPatch, boolean completeDataDump) throws IOException, UnsupportedEncodingException { |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
102 if (isPatch) { |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
103 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data.array(), data.arrayOffset(), data.remaining())); |
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 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 sb.append(":"); |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
115 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
|
116 } else { |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
117 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
|
118 } |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
119 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
|
120 } |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
121 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
|
122 } else { |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
123 if (completeDataDump) { |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
124 return escape(new String(data.array(), data.arrayOffset(), data.remaining(), "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
|
125 } |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
126 return String.format("<DATA>:%d bytes", data.remaining()); |
392
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
127 } |
656a6c1346ff
Extra debug option (dumpDataStats) and patch structure decoding for RevlogDump debug utility
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
376
diff
changeset
|
128 } |
533
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
129 |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
130 private static Pattern controlCharPattern = Pattern.compile("\\p{Cntrl}"); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
131 // \p{Cntrl} A control character: [\x00-\x1F\x7F] |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
132 private static String[] replacements = new String[33]; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
133 static { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
134 for (int i = 0; i < 32; i++) { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
135 // 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
|
136 replacements[i] = String.format("\\\\%X", i); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
137 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
138 replacements[32] = String.format("\\\\%X", 127); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
139 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
140 // 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
|
141 // 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
|
142 private static boolean leaveNewlineInData = true; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
143 |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
144 private static String escape(CharSequence possiblyWithBinary) { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
145 Matcher m = controlCharPattern.matcher(possiblyWithBinary); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
146 StringBuffer rv = new StringBuffer(); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
147 while (m.find()) { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
148 char c = m.group().charAt(0); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
149 if (leaveNewlineInData && c == '\n') { |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
150 continue; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
151 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
152 int x = (int) c; |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
153 m.appendReplacement(rv, replacements[x == 127 ? 32 : x]); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
154 } |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
155 m.appendTail(rv); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
156 return rv.toString(); |
e6f72c9829a6
Generate patches using diff algorithm
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
420
diff
changeset
|
157 } |
583
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
158 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
159 public static class RevlogReader { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
160 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
161 private final File file; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
162 private boolean needRevData; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
163 private DataInputStream dis; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
164 private boolean inlineData; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
165 public int versionField; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
166 private FileChannel dataStream; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
167 public int entryIndex; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
168 private byte[] data; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
169 private int dataOffset, dataLen; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
170 public long offset; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
171 public int flags; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
172 public int baseRevision; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
173 public int linkRevision; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
174 public int parent1Revision; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
175 public int parent2Revision; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
176 public int compressedLen; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
177 public int actualLen; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
178 public byte[] nodeid = new byte[21]; // need 1 byte in the front to be 0 to avoid negative BigInts |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
179 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
180 public RevlogReader(File f) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
181 assert f.getName().endsWith(".i"); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
182 file = f; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
183 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
184 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
185 // affects #readNext() |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
186 public RevlogReader needData(boolean needData) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
187 needRevData = needData; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
188 return this; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
189 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
190 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
191 public void init(boolean mayRequireData) throws IOException { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
192 dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
193 DataInput di = dis; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
194 dis.mark(10); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
195 versionField = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
196 dis.reset(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
197 final int INLINEDATA = 1 << 16; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
198 inlineData = (versionField & INLINEDATA) != 0; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
199 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
200 dataStream = null; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
201 if (!inlineData && mayRequireData) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
202 String fname = file.getAbsolutePath(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
203 dataStream = new FileInputStream(new File(fname.substring(0, fname.length()-2) + ".d")).getChannel(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
204 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
205 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
206 entryIndex = -1; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
207 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
208 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
209 public void startFrom(int startEntryIndex) throws IOException { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
210 if (dis == null) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
211 throw new IllegalStateException("Call #init() first"); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
212 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
213 if (entryIndex != -1 && startEntryIndex != 0) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
214 throw new IllegalStateException("Can't seek once iteration has started"); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
215 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
216 if (dataStream == null) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
217 throw new IllegalStateException("Sorry, initial seek is now supported for separate .i/.d only"); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
218 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
219 long newPos = startEntryIndex * Internals.REVLOGV1_RECORD_SIZE, actualSkip; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
220 do { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
221 actualSkip = dis.skip(newPos); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
222 if (actualSkip <= 0) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
223 throw new IllegalStateException(String.valueOf(actualSkip)); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
224 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
225 newPos -= actualSkip; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
226 } while (newPos > 0); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
227 entryIndex = startEntryIndex - 1; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
228 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
229 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
230 public boolean hasMore() throws IOException { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
231 return dis.available() > 0; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
232 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
233 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
234 public void readNext() throws IOException, DataFormatException { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
235 entryIndex++; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
236 DataInput di = dis; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
237 long l = di.readLong(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
238 offset = entryIndex == 0 ? 0 : (l >>> 16); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
239 flags = (int) (l & 0x0FFFF); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
240 compressedLen = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
241 actualLen = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
242 baseRevision = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
243 linkRevision = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
244 parent1Revision = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
245 parent2Revision = di.readInt(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
246 di.readFully(nodeid, 1, 20); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
247 dis.skipBytes(12); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
248 // CAN'T USE skip() here without extra precautions. E.g. I ran into situation when |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
249 // buffer was 8192 and BufferedInputStream was at position 8182 before attempt to skip(12). |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
250 // BIS silently skips available bytes and leaves me two extra bytes that ruin the rest of the code. |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
251 data = new byte[compressedLen]; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
252 if (inlineData) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
253 di.readFully(data); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
254 } else if (needRevData) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
255 dataStream.position(offset); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
256 dataStream.read(ByteBuffer.wrap(data)); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
257 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
258 if (needRevData) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
259 if (compressedLen == 0) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
260 data = null; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
261 dataOffset = dataLen = 0; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
262 } else { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
263 if (data[0] == 0x78 /* 'x' */) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
264 Inflater zlib = new Inflater(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
265 zlib.setInput(data, 0, compressedLen); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
266 byte[] result = new byte[actualLen * 3]; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
267 int resultLen = zlib.inflate(result); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
268 zlib.end(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
269 data = result; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
270 dataOffset = 0; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
271 dataLen = resultLen; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
272 } else if (data[0] == 0x75 /* 'u' */) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
273 dataOffset = 1; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
274 dataLen = data.length - 1; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
275 } else { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
276 dataOffset = 0; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
277 dataLen = data.length; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
278 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
279 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
280 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
281 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
282 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
283 public int getDataLength() { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
284 // NOT actualLen - there are empty patch revisions (dataLen == 0, but actualLen == previous length) |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
285 // NOT compressedLen - zip data is uncompressed |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
286 return dataLen; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
287 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
288 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
289 public void getData(ByteBuffer bb) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
290 assert bb.remaining() >= dataLen; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
291 bb.put(data, dataOffset, dataLen); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
292 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
293 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
294 public boolean isPatch() { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
295 assert entryIndex != -1; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
296 return baseRevision != entryIndex; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
297 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
298 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
299 public boolean isInline() { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
300 assert dis != null; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
301 return inlineData; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
302 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
303 |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
304 public void done() throws IOException { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
305 dis.close(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
306 dis = null; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
307 if (dataStream != null) { |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
308 dataStream.close(); |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
309 dataStream = null; |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
310 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
311 } |
47dfa0ec7e35
Effective revlog patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
533
diff
changeset
|
312 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
313 } |