aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-11-04 18:46:19 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-11-12 14:01:28 -0800
commit3728918d72e3ff2e7540becadf719957d8d75d70 (patch)
tree4246dbda23fdc864c4693138eb31940a1092da7b /org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java
parent3e2b9b691ed30d53750cc08c2b89577b78e6d19a (diff)
downloadjgit-3728918d72e3ff2e7540becadf719957d8d75d70.tar.gz
jgit-3728918d72e3ff2e7540becadf719957d8d75d70.zip
Add internal API for note iteration
Some algorithms need to be able to iterate through all notes within a particular bucket, such as when splitting or combining a bucket. Exposing an Iterator<Note> makes this traversal possible. For a LeafBucket the iteration is simple, its over the sorted array of elements. For FanoutBucket its a bit more complex as the iteration needs to union the iterators of each fanout bucket, lazily loading any buckets that aren't already in-memory. Change-Id: I3d5279b11984f44dcf0ddb14a82a4b4e51d4632d Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java
index 2085676900..5d35355ba9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java
@@ -46,9 +46,12 @@ package org.eclipse.jgit.notes;
import static org.eclipse.jgit.lib.FileMode.TREE;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectReader;
@@ -108,6 +111,54 @@ class FanoutBucket extends InMemoryNoteBucket {
}
@Override
+ Iterator<Note> iterator(AnyObjectId objId, final ObjectReader reader)
+ throws IOException {
+ final MutableObjectId id = new MutableObjectId();
+ id.fromObjectId(objId);
+
+ return new Iterator<Note>() {
+ private int cell;
+
+ private Iterator<Note> itr;
+
+ public boolean hasNext() {
+ if (itr != null && itr.hasNext())
+ return true;
+
+ for (; cell < table.length; cell++) {
+ NoteBucket b = table[cell];
+ if (b == null)
+ continue;
+
+ try {
+ id.setByte(prefixLen >> 1, cell);
+ itr = b.iterator(id, reader);
+ } catch (IOException err) {
+ throw new RuntimeException(err);
+ }
+
+ if (itr.hasNext()) {
+ cell++;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Note next() {
+ if (hasNext())
+ return itr.next();
+ else
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ @Override
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
ObjectReader or) throws IOException {
int cell = cell(noteOn);
@@ -194,6 +245,12 @@ class FanoutBucket extends InMemoryNoteBucket {
}
@Override
+ Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader)
+ throws IOException {
+ return load(objId, reader).iterator(objId, reader);
+ }
+
+ @Override
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
ObjectReader or) throws IOException {
return load(noteOn, or).set(noteOn, noteData, or);