Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevlogStream.java @ 342:516b817415ba
HgIgnore: regex patterns to match part of the filename do not work
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 18 Nov 2011 05:10:33 +0100 |
parents | 694ebabb5cb3 |
children | 8da7ade36c57 |
rev | line source |
---|---|
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
2 * Copyright (c) 2010-2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
13 * For information on how to redistribute this software under |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
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 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
21 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
22 import java.io.File; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
23 import java.io.IOException; |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
24 import java.util.zip.Inflater; |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 |
158
b413b16d10a5
Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
26 import org.tmatesoft.hg.core.HgBadStateException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
27 import org.tmatesoft.hg.core.Nodeid; |
300
650b45d290b1
Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
297
diff
changeset
|
28 import org.tmatesoft.hg.repo.HgInternals; |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgRepository; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
30 |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
31 |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 /** |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * ? Single RevlogStream per file per repository with accessor to record access session (e.g. with back/forward operations), |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
34 * or numerous RevlogStream with separate representation of the underlying data (cached, lazy ChunkStream)? |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
35 * |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * @see http://mercurial.selenic.com/wiki/Revlog |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @see http://mercurial.selenic.com/wiki/RevlogNG |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
38 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
39 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
52
diff
changeset
|
40 * @author TMate Software Ltd. |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 */ |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 public class RevlogStream { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
43 |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
44 /* |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
45 * makes sense for index with inline data only - actual offset of the record in the .i file (record entry + revision * record size)) |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
46 * |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
47 * long[] in fact (there are 8-bytes field in the revlog) |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
48 * However, (a) DataAccess currently doesn't operate with long seek/length |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
49 * and, of greater significance, (b) files with inlined data are designated for smaller files, |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
50 * guess, about 130 Kb, and offset there won't ever break int capacity |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
51 */ |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
52 private int[] indexRecordOffset; |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
53 private int[] baseRevisions; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
54 private boolean inline = false; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
55 private final File indexFile; |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
56 private final DataAccessProvider dataAccess; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
57 |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
58 // if we need anything else from HgRepo, might replace DAP parameter with HgRepo and query it for DAP. |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
59 public RevlogStream(DataAccessProvider dap, File indexFile) { |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
60 this.dataAccess = dap; |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
61 this.indexFile = indexFile; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
62 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
63 |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
64 /*package*/ DataAccess getIndexStream() { |
280
35125450c804
Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
264
diff
changeset
|
65 // XXX may supply a hint that I'll need really few bytes of data (perhaps, at some offset) |
35125450c804
Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
264
diff
changeset
|
66 // to avoid mmap files when only few bytes are to be read (i.e. #dataLength()) |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
67 return dataAccess.create(indexFile); |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
70 /*package*/ DataAccess getDataStream() { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
71 final String indexName = indexFile.getName(); |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
72 File dataFile = new File(indexFile.getParentFile(), indexName.substring(0, indexName.length() - 1) + "d"); |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
73 return dataAccess.create(dataFile); |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
74 } |
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
75 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
76 public int revisionCount() { |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
77 initOutline(); |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
78 return baseRevisions.length; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
79 } |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
80 |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
81 /** |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
82 * @throws HgBadStateException if internal read operation failed |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
83 */ |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
84 public int dataLength(int revision) { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
85 // XXX in fact, use of iterate() instead of this implementation may be quite reasonable. |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
86 // |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
87 final int indexSize = revisionCount(); |
280
35125450c804
Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
264
diff
changeset
|
88 DataAccess daIndex = getIndexStream(); |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
89 if (revision == TIP) { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
90 revision = indexSize - 1; |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
91 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
92 try { |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
93 int recordOffset = getIndexOffsetInt(revision); |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
94 daIndex.seek(recordOffset + 12); // 6+2+4 |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
95 int actualLen = daIndex.readInt(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
96 return actualLen; |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
97 } catch (IOException ex) { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
98 ex.printStackTrace(); // log error. FIXME better handling |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
99 throw new HgBadStateException(ex); |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
100 } finally { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
101 daIndex.done(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
102 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
103 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
104 |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
105 /** |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
106 * @throws HgBadStateException if internal read operation failed |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
107 */ |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
108 public byte[] nodeid(int revision) { |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
109 final int indexSize = revisionCount(); |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
110 if (revision == TIP) { |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
111 revision = indexSize - 1; |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
112 } |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
113 if (revision < 0 || revision >= indexSize) { |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
114 throw new IllegalArgumentException(Integer.toString(revision)); |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
115 } |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
116 DataAccess daIndex = getIndexStream(); |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
117 try { |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
118 int recordOffset = getIndexOffsetInt(revision); |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
119 daIndex.seek(recordOffset + 32); |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
120 byte[] rv = new byte[20]; |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
121 daIndex.readBytes(rv, 0, 20); |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
122 return rv; |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
123 } catch (IOException ex) { |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
124 ex.printStackTrace(); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
125 throw new HgBadStateException(); |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
126 } finally { |
88
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
127 daIndex.done(); |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
128 } |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
129 } |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
130 |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
131 /** |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
132 * Get link field from the index record. |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
133 * @throws HgBadStateException if internal read operation failed |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
134 */ |
88
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
135 public int linkRevision(int revision) { |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
136 final int last = revisionCount() - 1; |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
137 if (revision == TIP) { |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
138 revision = last; |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
139 } |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
140 if (revision < 0 || revision > last) { |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
141 throw new IllegalArgumentException(Integer.toString(revision)); |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
142 } |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
143 DataAccess daIndex = getIndexStream(); |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
144 try { |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
145 int recordOffset = getIndexOffsetInt(revision); |
88
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
146 daIndex.seek(recordOffset + 20); |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
147 int linkRev = daIndex.readInt(); |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
148 return linkRev; |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
149 } catch (IOException ex) { |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
150 ex.printStackTrace(); |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
288
diff
changeset
|
151 throw new HgBadStateException(); |
88
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
152 } finally { |
61eedab3eb3e
Status between two revisions to recognize copy/rename
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
80
diff
changeset
|
153 daIndex.done(); |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
154 } |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
155 } |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
156 |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
44
diff
changeset
|
157 // Perhaps, RevlogStream should be limited to use of plain int revisions for access, |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
44
diff
changeset
|
158 // while Nodeids should be kept on the level up, in Revlog. Guess, Revlog better keep |
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
44
diff
changeset
|
159 // map of nodeids, and once this comes true, we may get rid of this method. |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
160 // Unlike its counterpart, {@link Revlog#getLocalRevisionNumber()}, doesn't fail with exception if node not found, |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
161 /** |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
162 * @return integer in [0..revisionCount()) or {@link HgRepository#BAD_REVISION} if not found |
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
163 */ |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
164 public int findLocalRevisionNumber(Nodeid nodeid) { |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
165 // XXX this one may be implemented with iterate() once there's mechanism to stop iterations |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
166 final int indexSize = revisionCount(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
167 DataAccess daIndex = getIndexStream(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
168 try { |
24
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
169 byte[] nodeidBuf = new byte[20]; |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
170 for (int i = 0; i < indexSize; i++) { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
171 daIndex.skip(8); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
172 int compressedLen = daIndex.readInt(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
173 daIndex.skip(20); |
24
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
174 daIndex.readBytes(nodeidBuf, 0, 20); |
d4fdd1845b3f
Nodeid with array of exactly 20 bytes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
22
diff
changeset
|
175 if (nodeid.equalsTo(nodeidBuf)) { |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
176 return i; |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
177 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
178 daIndex.skip(inline ? 12 + compressedLen : 12); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
179 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
180 } catch (IOException ex) { |
243
0e01f9182e16
External cache Nodeid<->int added, Revlog.RevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
242
diff
changeset
|
181 ex.printStackTrace(); // log error. FIXME better handling. Perhaps, shall return BAD_REVISION here as well? |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
182 throw new IllegalStateException(ex); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
183 } finally { |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
184 daIndex.done(); |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
185 } |
80
4222b04f34ee
Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
77
diff
changeset
|
186 return BAD_REVISION; |
22
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
187 } |
603806cd2dc6
Status of local working dir against non-tip base revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
10
diff
changeset
|
188 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
189 |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
190 private final int REVLOGV1_RECORD_SIZE = 64; |
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
191 |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
192 // should be possible to use TIP, ALL, or -1, -2, -n notation of Hg |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
193 // ? boolean needsNodeid |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
194 public void iterate(int start, int end, boolean needData, Inspector inspector) { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
195 initOutline(); |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
196 final int indexSize = revisionCount(); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
197 if (indexSize == 0) { |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
198 return; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
199 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
200 if (end == TIP) { |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
201 end = indexSize - 1; |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
202 } |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
203 if (start == TIP) { |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
204 start = indexSize - 1; |
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
205 } |
300
650b45d290b1
Share range check code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
297
diff
changeset
|
206 HgInternals.checkRevlogRange(start, end, indexSize-1); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
207 // XXX may cache [start .. end] from index with a single read (pre-read) |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
208 |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
209 ReaderN1 r = new ReaderN1(needData, inspector); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
210 try { |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
211 r.start(end - start + 1); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
212 r.range(start, end); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
213 } catch (IOException ex) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
214 throw new HgBadStateException(ex); // FIXME need better handling |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
215 } finally { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
216 r.finish(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
217 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
218 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
219 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
220 /** |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
221 * Effective alternative to {@link #iterate(int, int, boolean, Inspector) batch read}, when only few selected |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
222 * revisions are of interest. |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
223 * @param sortedRevisions revisions to walk, in ascending order. |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
224 * @param needData whether inspector needs access to header only |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
225 * @param inspector callback to process entries |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
226 */ |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
227 public void iterate(int[] sortedRevisions, boolean needData, Inspector inspector) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
228 final int indexSize = revisionCount(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
229 if (indexSize == 0 || sortedRevisions.length == 0) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
230 return; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
231 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
232 if (sortedRevisions[0] > indexSize || sortedRevisions[sortedRevisions.length - 1] > indexSize) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
233 throw new IllegalArgumentException(String.format("Can't iterate [%d, %d] in range [0..%d]", sortedRevisions[0], sortedRevisions[sortedRevisions.length - 1], indexSize)); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
234 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
235 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
236 ReaderN1 r = new ReaderN1(needData, inspector); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
237 try { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
238 r.start(sortedRevisions.length); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
239 for (int i = 0; i < sortedRevisions.length; ) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
240 int x = i; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
241 i++; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
242 while (i < sortedRevisions.length) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
243 if (sortedRevisions[i] == sortedRevisions[i-1] + 1) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
244 i++; |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
245 } else { |
217
e39cf474ef94
Experimental support to mix-in start and end events for inspectors. Additionally, Lifecycle may serve as iteration control
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
246 break; |
e39cf474ef94
Experimental support to mix-in start and end events for inspectors. Additionally, Lifecycle may serve as iteration control
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
247 } |
e39cf474ef94
Experimental support to mix-in start and end events for inspectors. Additionally, Lifecycle may serve as iteration control
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
248 } |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
249 // commitRevisions[x..i-1] are sequential |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
250 if (!r.range(sortedRevisions[x], sortedRevisions[i-1])) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
251 return; |
51
9429c7bd1920
Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
49
diff
changeset
|
252 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
253 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
254 } catch (IOException ex) { |
158
b413b16d10a5
Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
255 throw new HgBadStateException(ex); // FIXME need better handling |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
256 } finally { |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
257 r.finish(); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
258 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
259 } |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
260 |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
261 private int getBaseRevision(int revision) { |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
262 return baseRevisions[revision]; |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
263 } |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
264 |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
265 /** |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
266 * @return offset of the revision's record in the index (.i) stream |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
267 */ |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
268 private int getIndexOffsetInt(int revision) { |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
269 return inline ? indexRecordOffset[revision] : revision * REVLOGV1_RECORD_SIZE; |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
270 } |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
271 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
272 private void initOutline() { |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
273 if (baseRevisions != null && baseRevisions.length > 0) { |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
274 return; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
275 } |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
276 DataAccess da = getIndexStream(); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
277 try { |
202
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
198
diff
changeset
|
278 if (da.isEmpty()) { |
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
198
diff
changeset
|
279 // do not fail with exception if stream is empty, it's likely intentional |
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
198
diff
changeset
|
280 baseRevisions = new int[0]; |
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
198
diff
changeset
|
281 return; |
706bcc7cfee4
Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
198
diff
changeset
|
282 } |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
283 int versionField = da.readInt(); |
170
71ddbf8603e8
Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
158
diff
changeset
|
284 da.readInt(); // just to skip next 4 bytes of offset + flags |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
285 final int INLINEDATA = 1 << 16; |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
286 inline = (versionField & INLINEDATA) != 0; |
288
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
287 IntVector resBases, resOffsets = null; |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
288 int entryCountGuess = da.length() / REVLOGV1_RECORD_SIZE; |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
289 if (inline) { |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
290 entryCountGuess >>>= 2; // pure guess, assume useful data takes 3/4 of total space |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
291 resOffsets = new IntVector(entryCountGuess, 5000); |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
292 } |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
293 resBases = new IntVector(entryCountGuess, 5000); |
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
294 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
295 long offset = 0; // first offset is always 0, thus Hg uses it for other purposes |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
296 while(true) { |
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
297 int compressedLen = da.readInt(); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
298 // 8+4 = 12 bytes total read here |
49
26e3eeaa3962
branch and user filtering for log operation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
44
diff
changeset
|
299 @SuppressWarnings("unused") |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
300 int actualLen = da.readInt(); |
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
301 int baseRevision = da.readInt(); |
5
fc265ddeab26
File content and non-effective, although working, patch application
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
4
diff
changeset
|
302 // 12 + 8 = 20 bytes read here |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
303 // int linkRevision = di.readInt(); |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
304 // int parent1Revision = di.readInt(); |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
305 // int parent2Revision = di.readInt(); |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
306 // byte[] nodeid = new byte[32]; |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
307 resBases.add(baseRevision); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
308 if (inline) { |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
309 int o = (int) offset; |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
310 if (o != offset) { |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
311 // just in case, can't happen, ever, unless HG (or some other bad tool) produces index file |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
312 // with inlined data of size greater than 2 Gb. |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
313 throw new HgBadStateException("Data too big, offset didn't fit to sizeof(int)"); |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
314 } |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
315 resOffsets.add(o + REVLOGV1_RECORD_SIZE * resOffsets.size()); |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
316 da.skip(3*4 + 32 + compressedLen); // Check: 44 (skip) + 20 (read) = 64 (total RevlogNG record size) |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
317 } else { |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
318 da.skip(3*4 + 32); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
319 } |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
320 if (da.isEmpty()) { |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
321 // fine, done then |
288
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
322 baseRevisions = resBases.toArray(true); |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
323 if (inline) { |
288
b11f6a08f748
Avoid boxing int values and list resizes on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
280
diff
changeset
|
324 indexRecordOffset = resOffsets.toArray(true); |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
325 } |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
326 break; |
10
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
327 } else { |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
328 // start reading next record |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
329 long l = da.readLong(); |
382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
9
diff
changeset
|
330 offset = l >>> 16; |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
331 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
332 } |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
333 } catch (IOException ex) { |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
334 ex.printStackTrace(); // log error |
198
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
335 // too bad, no outline then, but don't fail with NPE |
33a7d76f067b
Performance optimization: reduce memory to keep revlog cached info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
170
diff
changeset
|
336 baseRevisions = new int[0]; |
9
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
337 } finally { |
d6d2a630f4a6
Access to underlaying file data wrapped into own Access object, implemented with FileChannel and ByteBuffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
6
diff
changeset
|
338 da.done(); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
0
diff
changeset
|
339 } |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
340 } |
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
341 |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
342 /** |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
343 * operation with single file open/close and multiple diverse reads. |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
344 * XXX initOutline might need similar extraction to keen N1 format knowledge |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
345 */ |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
346 class ReaderN1 { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
347 private final Inspector inspector; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
348 private final boolean needData; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
349 private DataAccess daIndex = null, daData = null; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
350 private Lifecycle.BasicCallback cb = null; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
351 private int lastRevisionRead = BAD_REVISION; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
352 private DataAccess lastUserData; |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
353 // next are to track two major bottlenecks - patch application and actual time spent in inspector |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
354 // private long applyTime, inspectorTime; // TIMING |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
355 |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
356 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
357 public ReaderN1(boolean needData, Inspector insp) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
358 assert insp != null; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
359 this.needData = needData; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
360 inspector = insp; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
361 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
362 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
363 public void start(int totalWork) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
364 daIndex = getIndexStream(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
365 if (needData && !inline) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
366 daData = getDataStream(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
367 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
368 if (inspector instanceof Lifecycle) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
369 cb = new Lifecycle.BasicCallback(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
370 ((Lifecycle) inspector).start(totalWork, cb, cb); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
371 } |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
372 // applyTime = inspectorTime = 0; // TIMING |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
373 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
374 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
375 public void finish() { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
376 if (lastUserData != null) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
377 lastUserData.done(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
378 lastUserData = null; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
379 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
380 if (inspector instanceof Lifecycle) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
381 ((Lifecycle) inspector).finish(cb); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
382 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
383 daIndex.done(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
384 if (daData != null) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
385 daData.done(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
386 } |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
387 // System.out.printf("applyTime:%d ms, inspectorTime: %d ms\n", applyTime, inspectorTime); // TIMING |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
388 } |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
389 |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
390 public boolean range(int start, int end) throws IOException { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
391 byte[] nodeidBuf = new byte[20]; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
392 int i; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
393 // it (i.e. replace with i >= start) |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
394 if (needData && (i = getBaseRevision(start)) < start) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
395 // if lastRevisionRead in [baseRevision(start), start) can reuse lastUserData |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
396 // doesn't make sense to reuse if lastRevisionRead == start (too much to change in the cycle below). |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
397 if (lastRevisionRead != BAD_REVISION && i <= lastRevisionRead && lastRevisionRead < start) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
398 i = lastRevisionRead + 1; // start with first not-yet-read revision |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
399 } else { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
400 if (lastUserData != null) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
401 lastUserData.done(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
402 lastUserData = null; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
403 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
404 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
405 } else { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
406 // don't need to clean lastUserData as it's always null when !needData |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
407 i = start; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
408 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
409 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
410 daIndex.seek(getIndexOffsetInt(i)); |
258
e5776067b3b8
Reduce number of objects instantiated on revlog read
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
243
diff
changeset
|
411 // |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
412 // reuse some instances |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
300
diff
changeset
|
413 final Patch patch = new Patch(); |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
414 final Inflater inflater = new Inflater(); |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
415 // can share buffer between instances of InflaterDataAccess as I never read any two of them in parallel |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
416 final byte[] inflaterBuffer = new byte[1024]; |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
417 // |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
418 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
419 for (; i <= end; i++ ) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
420 if (inline && needData) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
421 // inspector reading data (though FilterDataAccess) may have affected index position |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
422 daIndex.seek(getIndexOffsetInt(i)); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
423 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
424 long l = daIndex.readLong(); // 0 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
425 long offset = i == 0 ? 0 : (l >>> 16); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
426 @SuppressWarnings("unused") |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
427 int flags = (int) (l & 0X0FFFF); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
428 int compressedLen = daIndex.readInt(); // +8 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
429 int actualLen = daIndex.readInt(); // +12 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
430 int baseRevision = daIndex.readInt(); // +16 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
431 int linkRevision = daIndex.readInt(); // +20 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
432 int parent1Revision = daIndex.readInt(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
433 int parent2Revision = daIndex.readInt(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
434 // Hg has 32 bytes here, uses 20 for nodeid, and keeps 12 last bytes empty |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
435 daIndex.readBytes(nodeidBuf, 0, 20); // +32 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
436 daIndex.skip(12); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
437 DataAccess userDataAccess = null; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
438 if (needData) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
439 int streamOffset; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
440 DataAccess streamDataAccess; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
441 if (inline) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
442 streamDataAccess = daIndex; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
443 streamOffset = getIndexOffsetInt(i) + REVLOGV1_RECORD_SIZE; // don't need to do seek as it's actual position in the index stream |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
444 } else { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
445 streamOffset = (int) offset; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
446 streamDataAccess = daData; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
447 daData.seek(streamOffset); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
448 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
449 final boolean patchToPrevious = baseRevision != i; // the only way I found to tell if it's a patch |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
450 if (streamDataAccess.isEmpty()) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
451 userDataAccess = new DataAccess(); // empty |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
452 } else { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
453 final byte firstByte = streamDataAccess.readByte(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
454 if (firstByte == 0x78 /* 'x' */) { |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
455 inflater.reset(); |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
456 userDataAccess = new InflaterDataAccess(streamDataAccess, streamOffset, compressedLen, patchToPrevious ? -1 : actualLen, inflater, inflaterBuffer); |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
457 } else if (firstByte == 0x75 /* 'u' */) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
458 userDataAccess = new FilterDataAccess(streamDataAccess, streamOffset+1, compressedLen-1); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
459 } else { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
460 // XXX Python impl in fact throws exception when there's not 'x', 'u' or '0' |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
461 // but I don't see reason not to return data as is |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
462 userDataAccess = new FilterDataAccess(streamDataAccess, streamOffset, compressedLen); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
463 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
464 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
465 // XXX |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
466 if (patchToPrevious) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
467 // this is a patch |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
300
diff
changeset
|
468 patch.read(userDataAccess); |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
469 userDataAccess.done(); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
470 // |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
471 // it shall be reset at the end of prev iteration, when it got assigned from userDataAccess |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
472 // however, actual userDataAccess and lastUserData may share Inflater object, which needs to be reset |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
473 // Alternatively, userDataAccess.done() above may be responsible to reset Inflater (if it's InflaterDataAccess) |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
474 lastUserData.reset(); |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
475 // final long startMeasuring = System.currentTimeMillis(); // TIMING |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
300
diff
changeset
|
476 byte[] userData = patch.apply(lastUserData, actualLen); |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
477 // applyTime += (System.currentTimeMillis() - startMeasuring); // TIMING |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
300
diff
changeset
|
478 patch.clear(); // do not keep any reference, allow byte[] data to be gc'd |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
479 userDataAccess = new ByteArrayDataAccess(userData); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
480 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
481 } else { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
482 if (inline) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
483 daIndex.skip(compressedLen); |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
484 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
485 } |
329
694ebabb5cb3
Refactor revlog patch mechanism, towards patch merging
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
300
diff
changeset
|
486 if (i >= start) { |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
487 // final long startMeasuring = System.currentTimeMillis(); // TIMING |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
488 inspector.next(i, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeidBuf, userDataAccess); |
264
6bb5e7ed051a
Optimize memory usage (reduce number of objects instantiated) when pooling file names and nodeids during manifest parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
263
diff
changeset
|
489 // inspectorTime += (System.currentTimeMillis() - startMeasuring); // TIMING |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
490 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
491 if (cb != null) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
492 if (cb.isStopped()) { |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
493 return false; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
494 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
495 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
496 if (userDataAccess != null) { |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
497 userDataAccess.reset(); // not sure this is necessary here, as lastUserData would get reset anyway before next use. |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
498 } |
263
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
499 if (lastUserData != null) { |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
500 lastUserData.done(); |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
501 } |
31f67be94e71
RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
258
diff
changeset
|
502 lastUserData = userDataAccess; |
242
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
503 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
504 lastRevisionRead = end; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
505 return true; |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
506 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
507 } |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
508 |
ad6a046943be
Improved reading of sparse revisions from a revlog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
223
diff
changeset
|
509 |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
510 public interface Inspector { |
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
511 // XXX boolean retVal to indicate whether to continue? |
157
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
512 // TODO specify nodeid and data length, and reuse policy (i.e. if revlog stream doesn't reuse nodeid[] for each call) |
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
513 // implementers shall not invoke DataAccess.done(), it's accomplished by #iterate at appropraite moment |
d5268ca7715b
Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
diff
changeset
|
514 void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[/*20*/] nodeid, DataAccess data); |
3
24bb4f365164
Rudimentary log functionality with basic infrastructure is in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
515 } |
0
dbd663faec1f
Basic changelog parsing
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
516 } |