aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorChris Aniszczyk <caniszczyk@gmail.com>2010-11-13 12:32:59 -0500
committerCode Review <codereview-daemon@eclipse.org>2010-11-13 12:32:59 -0500
commit9f2bde653ffbbc86351e81c3aaa5b010a71d997a (patch)
tree28a9518356e05e600384d20b4715858662729a47 /org.eclipse.jgit/src
parente9002a45cebabb1bbe6b49da5f93e386b1d68225 (diff)
parent3728918d72e3ff2e7540becadf719957d8d75d70 (diff)
downloadjgit-9f2bde653ffbbc86351e81c3aaa5b010a71d997a.tar.gz
jgit-9f2bde653ffbbc86351e81c3aaa5b010a71d997a.zip
Merge "Add internal API for note iteration"
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java57
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java24
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteBucket.java4
3 files changed, 85 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);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java
index 40be45f433..67bb3c8a04 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java
@@ -47,6 +47,8 @@ import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH;
import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
@@ -103,6 +105,28 @@ class LeafBucket extends InMemoryNoteBucket {
return 0 <= idx ? notes[idx].getData() : null;
}
+ @Override
+ Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader) {
+ return new Iterator<Note>() {
+ private int idx;
+
+ public boolean hasNext() {
+ return idx < cnt;
+ }
+
+ public Note next() {
+ if (hasNext())
+ return notes[idx++];
+ else
+ throw new NoSuchElementException();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
ObjectReader or) throws IOException {
int p = search(noteOn);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteBucket.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteBucket.java
index f5465148a8..e13067cc12 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteBucket.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteBucket.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.notes;
import java.io.IOException;
+import java.util.Iterator;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
@@ -60,6 +61,9 @@ abstract class NoteBucket {
abstract ObjectId get(AnyObjectId objId, ObjectReader reader)
throws IOException;
+ abstract Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader)
+ throws IOException;
+
abstract InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
ObjectReader reader) throws IOException;