Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/Revlog.java @ 367:2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Dec 2011 15:37:27 +0100 |
parents | 189dc6dc1c3e |
children | 8107b95f4280 |
comparison
equal
deleted
inserted
replaced
366:189dc6dc1c3e | 367:2fadf8695f8a |
---|---|
135 * @param nid revision to look up | 135 * @param nid revision to look up |
136 * @return revision local index in this revlog | 136 * @return revision local index in this revlog |
137 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog | 137 * @throws HgInvalidRevisionException if supplied nodeid doesn't identify any revision from this revlog |
138 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | 138 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
139 */ | 139 */ |
140 public final int getLocalRevision(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { | 140 public final int getRevisionIndex(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { |
141 int revision = content.findLocalRevisionNumber(nid); | 141 int revision = content.findRevisionIndex(nid); |
142 if (revision == BAD_REVISION) { | 142 if (revision == BAD_REVISION) { |
143 throw new HgInvalidRevisionException(String.format("Bad revision of %s", this /*XXX HgDataFile.getPath might be more suitable here*/), nid, null); | 143 throw new HgInvalidRevisionException(String.format("Bad revision of %s", this /*XXX HgDataFile.getPath might be more suitable here*/), nid, null); |
144 } | 144 } |
145 return revision; | 145 return revision; |
146 } | 146 } |
147 | |
148 /** | |
149 * @deprecated use {@link #getRevisionIndex(Nodeid)} instead | |
150 */ | |
151 @Deprecated | |
152 public final int getLocalRevision(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { | |
153 return getRevisionIndex(nid); | |
154 } | |
155 | |
147 | 156 |
148 /** | 157 /** |
149 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog. | 158 * Note, {@link Nodeid#NULL} nodeid is not reported as known in any revlog. |
150 * | 159 * |
151 * @param nodeid | 160 * @param nodeid |
152 * @return | 161 * @return |
153 * @throws HgInvalidControlFileException if access to revlog index/data entry failed | 162 * @throws HgInvalidControlFileException if access to revlog index/data entry failed |
154 */ | 163 */ |
155 public final boolean isKnown(Nodeid nodeid) throws HgInvalidControlFileException { | 164 public final boolean isKnown(Nodeid nodeid) throws HgInvalidControlFileException { |
156 final int rn = content.findLocalRevisionNumber(nodeid); | 165 final int rn = content.findRevisionIndex(nodeid); |
157 if (BAD_REVISION == rn) { | 166 if (BAD_REVISION == rn) { |
158 return false; | 167 return false; |
159 } | 168 } |
160 if (rn < 0 || rn >= content.revisionCount()) { | 169 if (rn < 0 || rn >= content.revisionCount()) { |
161 // Sanity check | 170 // Sanity check |
167 /** | 176 /** |
168 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries) | 177 * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries) |
169 * @param nodeid | 178 * @param nodeid |
170 */ | 179 */ |
171 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { | 180 protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { |
172 rawContent(getLocalRevision(nodeid), sink); | 181 rawContent(getRevisionIndex(nodeid), sink); |
173 } | 182 } |
174 | 183 |
175 /** | 184 /** |
176 * @param revision - repo-local index of this file change (not a changelog revision number!) | 185 * @param revision - repo-local index of this file change (not a changelog revision number!) |
177 * FIXME is it necessary to have IOException along with HgException here? | 186 * FIXME is it necessary to have IOException along with HgException here? |
281 public interface Inspector { | 290 public interface Inspector { |
282 } | 291 } |
283 | 292 |
284 @Experimental | 293 @Experimental |
285 public interface RevisionInspector extends Inspector { | 294 public interface RevisionInspector extends Inspector { |
286 void next(int localRevision, Nodeid revision, int linkedRevision); | 295 void next(int revisionIndex, Nodeid revision, int linkedRevision); |
287 } | 296 } |
288 | 297 |
289 @Experimental | 298 @Experimental |
290 public interface ParentInspector extends Inspector { | 299 public interface ParentInspector extends Inspector { |
291 // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?) | 300 // XXX document whether parentX is -1 or a constant (BAD_REVISION? or dedicated?) |
292 void next(int localRevision, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2); | 301 void next(int revisionIndex, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2); |
293 } | 302 } |
294 | 303 |
295 /* | 304 /* |
296 * XXX think over if it's better to do either: | 305 * XXX think over if it's better to do either: |
297 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed | 306 * pw = getChangelog().new ParentWalker(); pw.init() and pass pw instance around as needed |
482 } | 491 } |
483 } | 492 } |
484 | 493 |
485 /** | 494 /** |
486 * Effective int to Nodeid and vice versa translation. It's advised to use this class instead of | 495 * Effective int to Nodeid and vice versa translation. It's advised to use this class instead of |
487 * multiple {@link Revlog#getLocalRevision(Nodeid)} calls. | 496 * multiple {@link Revlog#getRevisionIndex(Nodeid)} calls. |
488 * | 497 * |
489 * getLocalRevision(Nodeid) with straightforward lookup approach performs O(n/2) | 498 * getRevisionIndex(Nodeid) with straightforward lookup approach performs O(n/2) |
490 * #localRevision() is log(n), plus initialization is O(n) | 499 * #localRevision() is log(n), plus initialization is O(n) |
491 */ | 500 */ |
492 public final class RevisionMap implements RevisionInspector { | 501 public final class RevisionMap implements RevisionInspector { |
493 /* | 502 /* |
494 * in fact, initialization is much slower as it instantiates Nodeids, while #getLocalRevision | 503 * in fact, initialization is much slower as it instantiates Nodeids, while #getLocalRevision |
510 | 519 |
511 public HgRepository getRepo() { | 520 public HgRepository getRepo() { |
512 return Revlog.this.getRepo(); | 521 return Revlog.this.getRepo(); |
513 } | 522 } |
514 | 523 |
515 public void next(int localRevision, Nodeid revision, int linkedRevision) { | 524 public void next(int revisionIndex, Nodeid revision, int linkedRevision) { |
516 sequential[localRevision] = sorted[localRevision] = revision; | 525 sequential[revisionIndex] = sorted[revisionIndex] = revision; |
517 } | 526 } |
518 | 527 |
519 /** | 528 /** |
520 * @return <code>this</code> for convenience. | 529 * @return <code>this</code> for convenience. |
521 */ | 530 */ |
532 // note, values in ArrayHelper#getReversed are 1-based indexes, not 0-based | 541 // note, values in ArrayHelper#getReversed are 1-based indexes, not 0-based |
533 sorted2natural = ah.getReverse(); | 542 sorted2natural = ah.getReverse(); |
534 return this; | 543 return this; |
535 } | 544 } |
536 | 545 |
537 public Nodeid revision(int localRevision) { | 546 public Nodeid revision(int revisionIndex) { |
538 return sequential[localRevision]; | 547 return sequential[revisionIndex]; |
539 } | 548 } |
540 public int localRevision(Nodeid revision) { | 549 public int revisionIndex(Nodeid revision) { |
541 if (revision == null || revision.isNull()) { | 550 if (revision == null || revision.isNull()) { |
542 return BAD_REVISION; | 551 return BAD_REVISION; |
543 } | 552 } |
544 int x = Arrays.binarySearch(sorted, revision); | 553 int x = Arrays.binarySearch(sorted, revision); |
545 if (x < 0) { | 554 if (x < 0) { |
546 return BAD_REVISION; | 555 return BAD_REVISION; |
547 } | 556 } |
548 return sorted2natural[x]-1; | 557 return sorted2natural[x]-1; |
558 } | |
559 /** | |
560 * @deprecated use {@link #revisionIndex(Nodeid)} instead | |
561 */ | |
562 @Deprecated | |
563 public int localRevision(Nodeid revision) { | |
564 return revisionIndex(revision); | |
549 } | 565 } |
550 } | 566 } |
551 | 567 |
552 protected abstract static class ErrorHandlingInspector implements RevlogStream.Inspector, CancelSupport { | 568 protected abstract static class ErrorHandlingInspector implements RevlogStream.Inspector, CancelSupport { |
553 private Exception failure; | 569 private Exception failure; |