Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgChangelog.java @ 242:ad6a046943be
Improved reading of sparse revisions from a revlog
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 23 Jun 2011 15:19:07 +0200 |
parents | 883300108179 |
children | a6d19adc2636 |
comparison
equal
deleted
inserted
replaced
241:d3ab16739736 | 242:ad6a046943be |
---|---|
63 final RawCsetCollector c = new RawCsetCollector(end - start + 1); | 63 final RawCsetCollector c = new RawCsetCollector(end - start + 1); |
64 range(start, end, c); | 64 range(start, end, c); |
65 return c.result; | 65 return c.result; |
66 } | 66 } |
67 | 67 |
68 /** | |
69 * Access individual revisions. Note, regardless of supplied revision order, inspector gets | |
70 * changesets strictly in the order they are in the changelog. | |
71 * @param inspector callback to get changesets | |
72 * @param revisions revisions to read, unrestricted ordering. | |
73 */ | |
68 public void range(final HgChangelog.Inspector inspector, final int... revisions) { | 74 public void range(final HgChangelog.Inspector inspector, final int... revisions) { |
69 if (revisions == null || revisions.length == 0) { | 75 Arrays.sort(revisions); |
76 rangeInternal(inspector, revisions); | |
77 } | |
78 | |
79 /** | |
80 * Friends-only version of {@link #range(Inspector, int...)}, when callers know array is sorted | |
81 */ | |
82 /*package-local*/ void rangeInternal(HgChangelog.Inspector inspector, int[] sortedRevisions) { | |
83 if (sortedRevisions == null || sortedRevisions.length == 0) { | |
70 return; | 84 return; |
71 } | 85 } |
72 RevlogStream.Inspector i = new RevlogStream.Inspector() { | 86 if (inspector == null) { |
73 private final RawCsetParser delegate = new RawCsetParser(inspector); | 87 throw new IllegalArgumentException(); |
74 | 88 } |
75 public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) { | 89 content.iterate(sortedRevisions, true, new RawCsetParser(inspector)); |
76 if (Arrays.binarySearch(revisions, revisionNumber) >= 0) { | |
77 delegate.next(revisionNumber, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeid, da); | |
78 } | |
79 } | |
80 }; | |
81 Arrays.sort(revisions); | |
82 content.iterate(revisions[0], revisions[revisions.length - 1], true, i); | |
83 } | 90 } |
84 | 91 |
85 public RawChangeset changeset(Nodeid nid) { | 92 public RawChangeset changeset(Nodeid nid) { |
86 int x = getLocalRevision(nid); | 93 int x = getLocalRevision(nid); |
87 return range(x, x).get(0); | 94 return range(x, x).get(0); |