Mercurial > hg4j
comparison src/org/tmatesoft/hg/repo/Revlog.java @ 393:728708de3597
Resolve FIXMEs
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 21 Feb 2012 19:18:40 +0100 |
parents | b015f3918120 |
children | f52ca9530774 d0e5dc3cae6e |
comparison
equal
deleted
inserted
replaced
392:656a6c1346ff | 393:728708de3597 |
---|---|
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 getRevisionIndex(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { | 140 public final int getRevisionIndex(Nodeid nid) throws HgInvalidControlFileException, HgInvalidRevisionException { |
141 int revision = content.findRevisionIndex(nid); | 141 int revision = content.findRevisionIndex(nid); |
142 if (revision == BAD_REVISION) { | 142 if (revision == BAD_REVISION) { |
143 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this /*FIXME HgDataFile.getPath might be more suitable here*/), nid, null); | 143 // using toString() to identify revlog. HgDataFile.toString includes path, HgManifest and HgChangelog instances |
144 // are fine with default (class name) | |
145 // Perhaps, more tailored description method would be suitable here | |
146 throw new HgInvalidRevisionException(String.format("Can't find revision %s in %s", nid.shortNotation(), this), nid, null); | |
144 } | 147 } |
145 return revision; | 148 return revision; |
146 } | 149 } |
147 | 150 |
148 /** | 151 /** |
342 } | 345 } |
343 | 346 |
344 public void init() throws HgInvalidControlFileException { | 347 public void init() throws HgInvalidControlFileException { |
345 final int revisionCount = Revlog.this.getRevisionCount(); | 348 final int revisionCount = Revlog.this.getRevisionCount(); |
346 firstParent = new Nodeid[revisionCount]; | 349 firstParent = new Nodeid[revisionCount]; |
347 // although branches/merges are less frequent, and most of secondParent would be -1/null, some sort of | 350 // TODO [post 1.0] Branches/merges are less frequent, and most of secondParent would be -1/null, hence |
348 // SparseOrderedList might be handy, provided its inner structures do not overweight simplicity of an array | 351 // IntMap might be better alternative here, but need to carefully analyze (test) whether this brings |
349 // FIXME IntMap is right candidate? | 352 // real improvement (IntMap has 2n capacity, and element lookup is log(n) instead of array's constant) |
350 secondParent = new Nodeid[revisionCount]; | 353 secondParent = new Nodeid[revisionCount]; |
351 // | 354 // |
352 sequential = new Nodeid[revisionCount]; | 355 sequential = new Nodeid[revisionCount]; |
353 sorted = new Nodeid[revisionCount]; | 356 sorted = new Nodeid[revisionCount]; |
354 Revlog.this.walk(0, TIP, this); | 357 Revlog.this.walk(0, TIP, this); |
366 if (x < 0) { | 369 if (x < 0) { |
367 throw new HgBadStateException(); | 370 throw new HgBadStateException(); |
368 } | 371 } |
369 } | 372 } |
370 | 373 |
371 // FIXME need to decide whether Nodeid(00 * 20) is always known or not | 374 /** |
372 // right now Nodeid.NULL is not recognized as known if passed to this method, | 375 * Tells whether supplied revision is from the walker's associated revlog. |
373 // caller is supposed to make explicit check | 376 * Note, {@link Nodeid#NULL}, although implicitly present as parent of a first revision, is not recognized as known. |
377 * @param nid revision to check, not <code>null</code> | |
378 * @return <code>true</code> if revision matches any revision in this revlog | |
379 */ | |
374 public boolean knownNode(Nodeid nid) { | 380 public boolean knownNode(Nodeid nid) { |
375 return Arrays.binarySearch(sorted, nid) >= 0; | 381 return Arrays.binarySearch(sorted, nid) >= 0; |
376 } | 382 } |
377 | 383 |
378 /** | 384 /** |
478 assert firstParent.length == sequential.length; | 484 assert firstParent.length == sequential.length; |
479 // to use == instead of equals, take the same Nodeid instance we used to fill all the arrays. | 485 // to use == instead of equals, take the same Nodeid instance we used to fill all the arrays. |
480 final Nodeid canonicalNode = sequential[i]; | 486 final Nodeid canonicalNode = sequential[i]; |
481 i++; // no need to check node itself. child nodes may appear in sequential only after revision in question | 487 i++; // no need to check node itself. child nodes may appear in sequential only after revision in question |
482 for (; i < sequential.length; i++) { | 488 for (; i < sequential.length; i++) { |
483 // FIXME likely, not very effective. | 489 // TODO [post 1.0] likely, not very effective. |
484 // May want to optimize it with another (Tree|Hash)Set, created on demand on first use, | 490 // May want to optimize it with another (Tree|Hash)Set, created on demand on first use, |
485 // however, need to be careful with memory usage | 491 // however, need to be careful with memory usage |
486 if (firstParent[i] == canonicalNode || secondParent[i] == canonicalNode) { | 492 if (firstParent[i] == canonicalNode || secondParent[i] == canonicalNode) { |
487 return true; | 493 return true; |
488 } | 494 } |