Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgStatusCollector.java @ 405:866fc3b597a0
Add an explicit constant instead of -1 to indicate 'no revision' case
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 14 Mar 2012 22:49:32 +0100 |
parents | 2747b0723867 |
children | 9c9c442b5f2e |
comparison
equal
deleted
inserted
replaced
403:2747b0723867 | 405:866fc3b597a0 |
---|---|
75 } | 75 } |
76 | 76 |
77 private ManifestRevision get(int rev) throws HgInvalidControlFileException { | 77 private ManifestRevision get(int rev) throws HgInvalidControlFileException { |
78 ManifestRevision i = cache.get(rev); | 78 ManifestRevision i = cache.get(rev); |
79 if (i == null) { | 79 if (i == null) { |
80 if (rev == -1) { | 80 if (rev == NO_REVISION) { |
81 return emptyFakeState; | 81 return emptyFakeState; |
82 } | 82 } |
83 ensureCacheSize(); | 83 ensureCacheSize(); |
84 i = new ManifestRevision(cacheNodes, cacheFilenames); | 84 i = new ManifestRevision(cacheNodes, cacheFilenames); |
85 cache.put(rev, i); | 85 cache.put(rev, i); |
87 } | 87 } |
88 return i; | 88 return i; |
89 } | 89 } |
90 | 90 |
91 private boolean cached(int revision) { | 91 private boolean cached(int revision) { |
92 return cache.containsKey(revision) || revision == -1; | 92 return cache.containsKey(revision) || revision == NO_REVISION; |
93 } | 93 } |
94 | 94 |
95 private void ensureCacheSize() { | 95 private void ensureCacheSize() { |
96 if (cache.size() > cacheMaxSize) { | 96 if (cache.size() > cacheMaxSize) { |
97 // assume usually we go from oldest to newest, hence remove oldest as most likely to be no longer necessary | 97 // assume usually we go from oldest to newest, hence remove oldest as most likely to be no longer necessary |
115 private ManifestRevision delegate; | 115 private ManifestRevision delegate; |
116 private boolean cacheHit; // range may include revisions we already know about, do not re-create them | 116 private boolean cacheHit; // range may include revisions we already know about, do not re-create them |
117 | 117 |
118 public boolean begin(int manifestRevision, Nodeid nid, int changelogRevision) { | 118 public boolean begin(int manifestRevision, Nodeid nid, int changelogRevision) { |
119 assert delegate == null; | 119 assert delegate == null; |
120 if (cache.containsKey(changelogRevision)) { // don't need to check emptyFakeState hit as revision never -1 here | 120 if (cache.containsKey(changelogRevision)) { // don't need to check emptyFakeState hit as revision never NO_REVISION here |
121 cacheHit = true; | 121 cacheHit = true; |
122 } else { | 122 } else { |
123 cache.put(changelogRevision, delegate = new ManifestRevision(cacheNodes, cacheFilenames)); | 123 cache.put(changelogRevision, delegate = new ManifestRevision(cacheNodes, cacheFilenames)); |
124 // cache may grow bigger than max size here, but it's ok as present simplistic cache clearing mechanism may | 124 // cache may grow bigger than max size here, but it's ok as present simplistic cache clearing mechanism may |
125 // otherwise remove entries we just added | 125 // otherwise remove entries we just added |
151 }, revisionsToCollect); | 151 }, revisionsToCollect); |
152 } | 152 } |
153 | 153 |
154 /*package-local*/ static ManifestRevision createEmptyManifestRevision() { | 154 /*package-local*/ static ManifestRevision createEmptyManifestRevision() { |
155 ManifestRevision fakeEmptyRev = new ManifestRevision(null, null); | 155 ManifestRevision fakeEmptyRev = new ManifestRevision(null, null); |
156 fakeEmptyRev.begin(-1, null, -1); | 156 fakeEmptyRev.begin(NO_REVISION, null, NO_REVISION); |
157 fakeEmptyRev.end(-1); | 157 fakeEmptyRev.end(NO_REVISION); |
158 return fakeEmptyRev; | 158 return fakeEmptyRev; |
159 } | 159 } |
160 | 160 |
161 /** | |
162 * Access specific manifest revision | |
163 * @param rev | |
164 * @return | |
165 * @throws HgInvalidControlFileException | |
166 */ | |
161 /*package-local*/ ManifestRevision raw(int rev) throws HgInvalidControlFileException { | 167 /*package-local*/ ManifestRevision raw(int rev) throws HgInvalidControlFileException { |
162 return get(rev); | 168 return get(rev); |
163 } | 169 } |
164 /*package-local*/ PathPool getPathPool() { | 170 /*package-local*/ PathPool getPathPool() { |
165 if (pathPool == null) { | 171 if (pathPool == null) { |
189 * | 195 * |
190 * @throws HgInvalidRevisionException if argument specifies non-existent revision index | 196 * @throws HgInvalidRevisionException if argument specifies non-existent revision index |
191 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | 197 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
192 */ | 198 */ |
193 public void change(int revisionIndex, HgStatusInspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { | 199 public void change(int revisionIndex, HgStatusInspector inspector) throws HgInvalidRevisionException, HgInvalidControlFileException { |
194 int[] parents = new int[2]; | 200 int p; |
195 repo.getChangelog().parents(revisionIndex, parents, null, null); | 201 if (revisionIndex == 0) { |
196 walk(parents[0], revisionIndex, inspector); | 202 p = NO_REVISION; |
203 } else { | |
204 int[] parents = new int[2]; | |
205 repo.getChangelog().parents(revisionIndex, parents, null, null); | |
206 // #parents call above is responsible for NO_REVISION | |
207 p = parents[0]; // hg --change alsways uses first parent, despite the fact there might be valid (-1, 18) pair of parents | |
208 } | |
209 walk(p, revisionIndex, inspector); | |
197 } | 210 } |
198 | 211 |
199 /** | 212 /** |
200 * Parameters <b>rev1</b> and <b>rev2</b> are changelog revision indexes, shall not be the same. Argument order matters. | 213 * Parameters <b>rev1</b> and <b>rev2</b> are changelog revision indexes, shall not be the same. Argument order matters. |
201 * FIXME Either rev1 or rev2 may be -1 to indicate comparison to empty repository (this is due to use of | 214 * Either rev1 or rev2 may be {@link HgRepository#NO_REVISION} to indicate comparison to empty repository |
202 * parents in #change(), I believe. Perhaps, need a constant for this? Otherwise this hidden knowledge gets | 215 * |
203 * exposed to e.g. Record | 216 * FIXME cancellation (at least exception)? |
204 * XXX cancellation? | |
205 * | 217 * |
206 * @param rev1 <em>from</em> changeset index, non-negative or {@link HgRepository#TIP} | 218 * @param rev1 <em>from</em> changeset index, non-negative or {@link HgRepository#TIP} |
207 * @param rev2 <em>to</em> changeset index, non-negative or {@link HgRepository#TIP} | 219 * @param rev2 <em>to</em> changeset index, non-negative or {@link HgRepository#TIP} |
208 * @param inspector callback for status information | 220 * @param inspector callback for status information |
209 * @throws HgInvalidRevisionException if any argument specifies non-existent revision index | 221 * @throws HgInvalidRevisionException if any argument specifies non-existent revision index |
222 rev1 = lastChangelogRevision; | 234 rev1 = lastChangelogRevision; |
223 } | 235 } |
224 if (rev2 == TIP) { | 236 if (rev2 == TIP) { |
225 rev2 = lastChangelogRevision; | 237 rev2 = lastChangelogRevision; |
226 } | 238 } |
227 if (rev1 != -1 && (HgInternals.wrongRevisionIndex(rev1) || rev1 == WORKING_COPY || rev1 == BAD_REVISION || rev1 > lastChangelogRevision)) { | 239 if (rev1 != NO_REVISION && (HgInternals.wrongRevisionIndex(rev1) || rev1 == WORKING_COPY || rev1 == BAD_REVISION || rev1 > lastChangelogRevision)) { |
228 throw new HgInvalidRevisionException(rev1); | 240 throw new HgInvalidRevisionException(rev1); |
229 } | 241 } |
230 if (rev2 != -1 && (HgInternals.wrongRevisionIndex(rev2) || rev2 == WORKING_COPY || rev2 == BAD_REVISION || rev2 > lastChangelogRevision)) { | 242 if (rev2 != NO_REVISION && (HgInternals.wrongRevisionIndex(rev2) || rev2 == WORKING_COPY || rev2 == BAD_REVISION || rev2 > lastChangelogRevision)) { |
231 throw new HgInvalidRevisionException(rev2); | 243 throw new HgInvalidRevisionException(rev2); |
232 } | 244 } |
233 if (inspector instanceof Record) { | 245 if (inspector instanceof Record) { |
234 ((Record) inspector).init(rev1, rev2, this); | 246 ((Record) inspector).init(rev1, rev2, this); |
235 } | 247 } |