Mercurial > hg4j
annotate src/org/tmatesoft/hg/repo/HgManifest.java @ 299:45dc79e545f5
Recognize flag options (options with no arguments) in command line sample apps
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 17 Sep 2011 13:26:52 +0200 |
parents | 6dbbc53fc46d |
children | 650b45d290b1 |
rev | line source |
---|---|
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
1 /* |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
2 * Copyright (c) 2010-2011 TMate Software Ltd |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
3 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
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:
28
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:
28
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:
28
diff
changeset
|
7 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
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:
28
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:
28
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:
28
diff
changeset
|
11 * GNU General Public License for more details. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
12 * |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
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:
28
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:
77
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
18 |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
20 |
232
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
21 import java.io.ByteArrayOutputStream; |
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
|
22 import java.io.IOException; |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
23 import java.util.ArrayList; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
24 import java.util.Arrays; |
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
|
25 |
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
|
26 import org.tmatesoft.hg.core.HgBadStateException; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
27 import org.tmatesoft.hg.core.Nodeid; |
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
|
28 import org.tmatesoft.hg.internal.DataAccess; |
266
0a2f445de774
Improve manifest parsing: reduce number of arrays instantiated for Nodeid
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
264
diff
changeset
|
29 import org.tmatesoft.hg.internal.DigestHelper; |
232
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
30 import org.tmatesoft.hg.internal.Experimental; |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
31 import org.tmatesoft.hg.internal.Lifecycle; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
32 import org.tmatesoft.hg.internal.Pool; |
77
c677e1593919
Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
33 import org.tmatesoft.hg.internal.RevlogStream; |
232
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
34 import org.tmatesoft.hg.util.Path; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
35 |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 /** |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
39 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
28
diff
changeset
|
40 * @author TMate Software Ltd. |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 */ |
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 public class HgManifest extends Revlog { |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
43 private RevisionMapper revisionMap; |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
44 |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
45 public enum Flags { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
46 Exec, Link; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
47 |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
48 static Flags parse(String flags) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
49 if ("x".equalsIgnoreCase(flags)) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
50 return Exec; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
51 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
52 if ("l".equalsIgnoreCase(flags)) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
53 return Link; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
54 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
55 if (flags == null) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
56 return null; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
57 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
58 throw new IllegalStateException(flags); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
59 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
60 |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
61 static Flags parse(byte[] data, int start, int length) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
62 if (length == 0) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
63 return null; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
64 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
65 if (length == 1) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
66 if (data[start] == 'x') { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
67 return Exec; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
68 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
69 if (data[start] == 'l') { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
70 return Link; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
71 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
72 // FALL THROUGH |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
73 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
74 throw new IllegalStateException(new String(data, start, length)); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
75 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
76 |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
77 String nativeString() { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
78 if (this == Exec) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
79 return "x"; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
80 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
81 if (this == Link) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
82 return "l"; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
83 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
84 throw new IllegalStateException(toString()); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
85 } |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
86 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
88 /*package-local*/ HgManifest(HgRepository hgRepo, RevlogStream content) { |
21
e929cecae4e1
Refactor to move revlog content to base class
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
20
diff
changeset
|
89 super(hgRepo, content); |
13
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
90 } |
df8c67f3006a
Basic manifest parsing to analyze what's in there
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
2
diff
changeset
|
91 |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
92 /** |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
93 * |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
94 * @param start changelog (not manifest!) revision to begin with |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
95 * @param end changelog (not manifest!) revision to stop, inclusive. |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
96 * @param inspector can't be <code>null</code> |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
97 */ |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
98 public void walk(int start, int end, final Inspector inspector) { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
99 if (inspector == null) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
100 throw new IllegalArgumentException(); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
101 } |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
102 int start0 = fromChangelog(start); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
103 int end0 = fromChangelog(end); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
104 content.iterate(start0, end0, true, new ManifestParser(inspector)); |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
105 } |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
106 |
254
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
107 /** |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
108 * "Sparse" iteration of the manifest |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
109 * |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
110 * @param inspector |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
111 * @param localRevisions local changeset revisions to visit |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
112 */ |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
113 public void walk(final Inspector inspector, int... localRevisions) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
114 if (inspector == null || localRevisions == null) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
115 throw new IllegalArgumentException(); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
116 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
117 int[] manifestLocalRevs = new int[localRevisions.length]; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
118 boolean needsSort = false; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
119 for (int i = 0; i < localRevisions.length; i++) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
120 final int manifestLocalRev = fromChangelog(localRevisions[i]); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
121 manifestLocalRevs[i] = manifestLocalRev; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
122 if (i > 0 && manifestLocalRevs[i-1] > manifestLocalRev) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
123 needsSort = true; |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
124 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
125 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
126 if (needsSort) { |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
127 Arrays.sort(manifestLocalRevs); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
128 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
129 content.iterate(manifestLocalRevs, true, new ManifestParser(inspector)); |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
130 } |
a620f0663a37
Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
232
diff
changeset
|
131 |
232
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
132 // manifest revision number that corresponds to the given changeset |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
133 /*package-local*/ int fromChangelog(int revisionNumber) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
134 if (HgInternals.wrongLocalRevision(revisionNumber)) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
135 throw new IllegalArgumentException(String.valueOf(revisionNumber)); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
136 } |
257
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
137 if (revisionNumber == HgRepository.WORKING_COPY || revisionNumber == HgRepository.BAD_REVISION) { |
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
138 throw new IllegalArgumentException("Can't use constants like WORKING_COPY or BAD_REVISION"); |
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
139 } |
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
140 // revisionNumber == TIP is processed by RevisionMapper |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
141 if (revisionMap == null) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
142 revisionMap = new RevisionMapper(getRepo()); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
143 content.iterate(0, TIP, false, revisionMap); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
144 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
145 return revisionMap.at(revisionNumber); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
146 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
147 |
232
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
148 /** |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
149 * Extracts file revision as it was known at the time of given changeset. |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
150 * |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
151 * @param revisionNumber local changeset index |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
152 * @param file path to file in question |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
153 * @return file revision or <code>null</code> if manifest at specified revision doesn't list such file |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
154 */ |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
155 @Experimental(reason="Perhaps, HgDataFile shall own this method") |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
156 public Nodeid getFileRevision(int revisionNumber, final Path file) { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
157 int rev = fromChangelog(revisionNumber); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
158 final Nodeid[] rv = new Nodeid[] { null }; |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
159 content.iterate(rev, rev, true, new RevlogStream.Inspector() { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
160 |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
161 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
162 ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
163 try { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
164 byte b; |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
165 while (!data.isEmpty() && (b = data.readByte()) != '\n') { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
166 if (b != 0) { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
167 bos.write(b); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
168 } else { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
169 String fname = new String(bos.toByteArray()); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
170 bos.reset(); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
171 if (file.toString().equals(fname)) { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
172 byte[] nid = new byte[40]; |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
173 data.readBytes(nid, 0, 40); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
174 rv[0] = Nodeid.fromAscii(nid, 0, 40); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
175 break; |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
176 } |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
177 // else skip to the end of line |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
178 while (!data.isEmpty() && (b = data.readByte()) != '\n') |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
179 ; |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
180 } |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
181 } |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
182 } catch (IOException ex) { |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
183 throw new HgBadStateException(ex); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
184 } |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
185 } |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
186 }); |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
187 return rv[0]; |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
188 } |
b7347daa50e3
Allow to cat a file with changeset revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
222
diff
changeset
|
189 |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
190 public interface Inspector { |
222
373e07cd3991
Due to discrepancy in manifest and changelor indexes, wrong manifest revisions got cached and compared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
191 boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision); |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
192 /** |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
193 * @deprecated switch to {@link Inspector2#next(Nodeid, Path, Flags)} |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
194 */ |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
195 @Deprecated |
19
40532cdc92fc
Inspector (visitor) for manifest
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
16
diff
changeset
|
196 boolean next(Nodeid nid, String fname, String flags); |
222
373e07cd3991
Due to discrepancy in manifest and changelor indexes, wrong manifest revisions got cached and compared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
197 boolean end(int manifestRevision); |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 } |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
199 |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
200 @Experimental(reason="Explore Path alternative for filenames and enum for flags") |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
201 public interface Inspector2 extends Inspector { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
202 boolean next(Nodeid nid, Path fname, Flags flags); |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
203 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
204 |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
205 /** |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
206 * When Pool uses Strings directly, |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
207 * ManifestParser creates new String instance with new char[] value, and does byte->char conversion. |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
208 * For cpython repo, walk(0..10k), there are over 16 million filenames, of them only 3020 unique. |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
209 * This means there are 15.9 million useless char[] instances and byte->char conversions |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
210 * |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
211 * When String (Path) is wrapped into {@link PathProxy}, there's extra overhead of byte[] representation |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
212 * of the String, but these are only for unique Strings (Paths) (3020 in the example above). Besides, I save |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
213 * useless char[] and byte->char conversions. |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
214 */ |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
215 private static class PathProxy { |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
216 private byte[] data; |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
217 private int start; |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
218 private final int hash, length; |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
219 private Path result; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
220 |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
221 public PathProxy(byte[] data, int start, int length) { |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
222 this.data = data; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
223 this.start = start; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
224 this.length = length; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
225 |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
226 // copy from String.hashCode(). In fact, not necessarily match result of String(data).hashCode |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
227 // just need some nice algorithm here |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
228 int h = 0; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
229 byte[] d = data; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
230 for (int i = 0, off = start, len = length; i < len; i++) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
231 h = 31 * h + d[off++]; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
232 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
233 hash = h; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
234 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
235 |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
236 @Override |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
237 public boolean equals(Object obj) { |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
238 if (false == obj instanceof PathProxy) { |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
239 return false; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
240 } |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
241 PathProxy o = (PathProxy) obj; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
242 if (o.result != null && result != null) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
243 return result.equals(o.result); |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
244 } |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
245 if (o.length != length || o.hash != hash) { |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
246 return false; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
247 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
248 for (int i = 0, x = o.start, y = start; i < length; i++) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
249 if (o.data[x++] != data[y++]) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
250 return false; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
251 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
252 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
253 return true; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
254 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
255 @Override |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
256 public int hashCode() { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
257 return hash; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
258 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
259 |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
260 public Path freeze() { |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
261 if (result == null) { |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
262 result = Path.create(new String(data, start, length)); |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
263 // release reference to bigger data array, make a copy of relevant part only |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
264 // use original bytes, not those from String above to avoid cache misses due to different encodings |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
265 byte[] d = new byte[length]; |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
266 System.arraycopy(data, start, d, 0, length); |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
267 data = d; |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
268 start = 0; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
269 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
270 return result; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
271 } |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
272 } |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
273 |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
274 private static class ManifestParser implements RevlogStream.Inspector { |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
275 private boolean gtg = true; // good to go |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
276 private final Inspector inspector; |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
277 private final Inspector2 inspector2; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
278 private Pool<Nodeid> nodeidPool, thisRevPool; |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
279 private final Pool<PathProxy> fnamePool; |
266
0a2f445de774
Improve manifest parsing: reduce number of arrays instantiated for Nodeid
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
264
diff
changeset
|
280 private byte[] nodeidLookupBuffer = new byte[20]; // get reassigned each time new Nodeid is added to pool |
262
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
281 |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
282 public ManifestParser(Inspector delegate) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
283 assert delegate != null; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
284 inspector = delegate; |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
285 inspector2 = delegate instanceof Inspector2 ? (Inspector2) delegate : null; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
286 nodeidPool = new Pool<Nodeid>(); |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
287 fnamePool = new Pool<PathProxy>(); |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
288 thisRevPool = new Pool<Nodeid>(); |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
289 } |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
290 |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
291 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
292 if (!gtg) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
293 return; |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
294 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
295 try { |
222
373e07cd3991
Due to discrepancy in manifest and changelor indexes, wrong manifest revisions got cached and compared
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
296 gtg = gtg && inspector.begin(revisionNumber, new Nodeid(nodeid, true), linkRevision); |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
297 Path fname = null; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
298 Flags flags = null; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
299 Nodeid nid = null; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
300 int i; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
301 byte[] data = da.byteArray(); |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
302 for (i = 0; gtg && i < actualLen; i++) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
303 int x = i; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
304 for( ; data[i] != '\n' && i < actualLen; i++) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
305 if (fname == null && data[i] == 0) { |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
306 PathProxy px = fnamePool.unify(new PathProxy(data, x, i - x)); |
268
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
307 // if (cached = fnamePool.unify(px))== px then cacheMiss, else cacheHit |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
308 // cpython 0..10k: hits: 15 989 152, misses: 3020 |
c5980f287cc4
Use StringProxy when parsing manifest to minimize number of useless conversions and array instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
267
diff
changeset
|
309 fname = px.freeze(); |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
310 x = i+1; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
311 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
312 } |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
313 if (i < actualLen) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
314 assert data[i] == '\n'; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
315 int nodeidLen = i - x < 40 ? i-x : 40; // if > 40, there are flags |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
316 DigestHelper.ascii2bin(data, x, nodeidLen, nodeidLookupBuffer); // ignore return value as it's unlikely to have NULL in manifest |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
317 nid = new Nodeid(nodeidLookupBuffer, false); // this Nodeid is for pool lookup only, mock object |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
318 Nodeid cached = nodeidPool.unify(nid); |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
319 if (cached == nid) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
320 // buffer now belongs to the cached nodeid |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
321 nodeidLookupBuffer = new byte[20]; |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
322 } else { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
323 nid = cached; // use existing version, discard the lookup object |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
324 } // for cpython 0..10k, cache hits are 15 973 301, vs 18871 misses. |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
325 thisRevPool.record(nid); // memorize revision for the next iteration. |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
326 if (nodeidLen + x < i) { |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
327 // 'x' and 'l' for executable bits and symlinks? |
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
328 // hg --debug manifest shows 644 for each regular file in my repo |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
329 // for cpython 0..10k, there are 4361062 flag checks, and there's only 1 unique flag |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
330 flags = Flags.parse(data, x + nodeidLen, i-x-nodeidLen); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
331 } else { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
332 flags = null; |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
333 } |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
334 if (inspector2 == null) { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
335 String flagString = flags == null ? null : flags.nativeString(); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
336 gtg = inspector.next(nid, fname.toString(), flagString); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
337 } else { |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
338 gtg = inspector2.next(nid, fname, flags); |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
339 } |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
340 } |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
341 nid = null; |
285
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
342 fname = null; |
6dbbc53fc46d
Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
268
diff
changeset
|
343 flags = null; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
344 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
345 gtg = gtg && inspector.end(revisionNumber); |
262
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
346 // |
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
347 // keep only actual file revisions, found at this version |
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
348 // (next manifest is likely to refer to most of them, although in specific cases |
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
349 // like commit in another branch a lot may be useless) |
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
350 nodeidPool.clear(); |
267
ec921ef0628e
Revert manifest parser changes - no single string and back to HashMap Pool
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
266
diff
changeset
|
351 Pool<Nodeid> t = nodeidPool; |
262
3dcd3dd90c77
Improve manifest parsing: decode bytes to chars once, minimize arraycopy on String instantiation, keep set of file revisions from previous manifest only
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
257
diff
changeset
|
352 nodeidPool = thisRevPool; |
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:
262
diff
changeset
|
353 thisRevPool = t; |
196
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
354 } catch (IOException ex) { |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
355 throw new HgBadStateException(ex); |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
356 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
357 } |
e2115da4cf6a
Pool objects to avoid memory polution with duplicates
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
157
diff
changeset
|
358 } |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
359 |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
360 private static class RevisionMapper implements RevlogStream.Inspector, Lifecycle { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
361 |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
362 private final int changelogRevisions; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
363 private int[] changelog2manifest; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
364 private final HgRepository repo; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
365 |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
366 public RevisionMapper(HgRepository hgRepo) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
367 repo = hgRepo; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
368 changelogRevisions = repo.getChangelog().getRevisionCount(); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
369 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
370 |
257
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
371 // respects TIP |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
372 public int at(int revisionNumber) { |
257
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
373 if (revisionNumber == TIP) { |
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
374 revisionNumber = changelogRevisions - 1; |
f39fb6b3cc76
Handle revision constants correctly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
254
diff
changeset
|
375 } |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
376 if (changelog2manifest != null) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
377 return changelog2manifest[revisionNumber]; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
378 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
379 return revisionNumber; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
380 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
381 |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
382 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
383 if (changelog2manifest != null) { |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
384 // next assertion is not an error, rather assumption check, which is too development-related to be explicit exception - |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
385 // I just wonder if there are manifests that have two entries pointing to single changeset. It seems unrealistic, though - |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
386 // changeset records one and only one manifest nodeid |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
387 assert changelog2manifest[linkRevision] == -1 : String.format("revision:%d, link:%d, already linked to revision:%d", revisionNumber, linkRevision, changelog2manifest[linkRevision]); |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
388 changelog2manifest[linkRevision] = revisionNumber; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
389 } else { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
390 if (revisionNumber != linkRevision) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
391 changelog2manifest = new int[changelogRevisions]; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
392 Arrays.fill(changelog2manifest, -1); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
393 for (int i = 0; i < revisionNumber; changelog2manifest[i] = i, i++) |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
394 ; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
395 changelog2manifest[linkRevision] = revisionNumber; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
396 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
397 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
398 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
399 |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
400 public void start(int count, Callback callback, Object token) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
401 if (count != changelogRevisions) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
402 assert count < changelogRevisions; // no idea what to do if manifest has more revisions than changelog |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
403 // the way how manifest may contain more revisions than changelog, as I can imagine, is a result of |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
404 // some kind of an import tool (e.g. from SVN or CVS), that creates manifest and changelog independently. |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
405 // Note, it's pure guess, I didn't see such repository yet (although the way manifest revisions |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
406 // in cpython repo are numbered makes me think aforementioned way) |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
407 changelog2manifest = new int[changelogRevisions]; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
408 Arrays.fill(changelog2manifest, -1); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
409 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
410 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
411 |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
412 public void finish(Object token) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
413 if (changelog2manifest == null) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
414 return; |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
415 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
416 // I assume there'd be not too many revisions we don't know manifest of |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
417 ArrayList<Integer> undefinedChangelogRevision = new ArrayList<Integer>(); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
418 for (int i = 0; i < changelog2manifest.length; i++) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
419 if (changelog2manifest[i] == -1) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
420 undefinedChangelogRevision.add(i); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
421 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
422 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
423 for (int u : undefinedChangelogRevision) { |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
424 Nodeid manifest = repo.getChangelog().range(u, u).get(0).manifest(); |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
218
diff
changeset
|
425 // FIXME calculate those missing effectively (e.g. cache and sort nodeids to speed lookup |
218
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
426 // right away in the #next (may refactor ParentWalker's sequential and sorted into dedicated helper and reuse here) |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
427 changelog2manifest[u] = repo.getManifest().getLocalRevision(manifest); |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
428 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
429 } |
047b1dec7a04
Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
196
diff
changeset
|
430 } |
2
08db726a0fb7
Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
431 } |