Merge "DfsReader: Fallback to regular size read if size index throws"
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
index 95050d4..dfea5c1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
@@ -359,10 +359,11 @@ abstract class EntriesIterator implements Iterator<MutableEntry> {
private long returnedNumber = 0;
/**
- * Default constructor.
- *
- * @param objectCount the number of objects in the PackFile.
- */
+ * Construct an iterator that can move objectCount times forward.
+ *
+ * @param objectCount
+ * the number of objects in the PackFile.
+ */
protected EntriesIterator(long objectCount) {
this.objectCount = objectCount;
}
@@ -379,17 +380,54 @@ public boolean hasNext() {
*/
@Override
public MutableEntry next() {
- readNext(entry);
+ readNext();
returnedNumber++;
return entry;
}
/**
* Used by subclasses to load the next entry into the MutableEntry.
+ * <p>
+ * Subclasses are expected to populate the entry with
+ * {@link #setIdBuffer} and {@link #setOffset}.
+ */
+ protected abstract void readNext();
+
+
+ /**
+ * Copies to the entry an {@link ObjectId} from the int buffer and
+ * position idx
*
- * @param entry the container of the next Iterator entry.
- */
- protected abstract void readNext(MutableEntry entry);
+ * @param raw
+ * the raw data
+ * @param idx
+ * the index into {@code raw}
+ */
+ protected void setIdBuffer(int[] raw, int idx) {
+ entry.idBuffer.fromRaw(raw, idx);
+ }
+
+ /**
+ * Copies to the entry an {@link ObjectId} from the byte array at
+ * position idx.
+ *
+ * @param raw
+ * the raw data
+ * @param idx
+ * the index into {@code raw}
+ */
+ protected void setIdBuffer(byte[] raw, int idx) {
+ entry.idBuffer.fromRaw(raw, idx);
+ }
+
+ /**
+ * Sets the {@code offset} to the entry
+ *
+ * @param offset the offset in the pack file
+ */
+ protected void setOffset(long offset) {
+ entry.offset = offset;
+ }
@Override
public void remove() {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
index 99f3315..be48358 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java
@@ -259,15 +259,15 @@ private EntriesIteratorV1(PackIndexV1 packIndex) {
}
@Override
- protected void readNext(MutableEntry entry) {
+ protected void readNext() {
for (; levelOne < packIndex.idxdata.length; levelOne++) {
if (packIndex.idxdata[levelOne] == null)
continue;
if (levelTwo < packIndex.idxdata[levelOne].length) {
- entry.offset = NB.decodeUInt32(packIndex.idxdata[levelOne],
- levelTwo);
+ super.setOffset(NB.decodeUInt32(packIndex.idxdata[levelOne],
+ levelTwo));
this.levelTwo += Constants.OBJECT_ID_LENGTH + 4;
- entry.idBuffer.fromRaw(packIndex.idxdata[levelOne],
+ super.setIdBuffer(packIndex.idxdata[levelOne],
levelTwo - Constants.OBJECT_ID_LENGTH);
return;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java
index f23380d..36e54fc 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java
@@ -302,7 +302,7 @@ private EntriesIteratorV2(PackIndexV2 packIndex) {
}
@Override
- protected void readNext(MutableEntry entry) {
+ protected void readNext() {
for (; levelOne < packIndex.names.length; levelOne++) {
if (levelTwo < packIndex.names[levelOne].length) {
int idx = levelTwo / (Constants.OBJECT_ID_LENGTH / 4) * 4;
@@ -312,9 +312,9 @@ protected void readNext(MutableEntry entry) {
idx = (8 * (int) (offset & ~IS_O64));
offset = NB.decodeUInt64(packIndex.offset64, idx);
}
- entry.offset = offset;
+ super.setOffset(offset);
this.levelTwo += Constants.OBJECT_ID_LENGTH / 4;
- entry.idBuffer.fromRaw(packIndex.names[levelOne],
+ super.setIdBuffer(packIndex.names[levelOne],
levelTwo - Constants.OBJECT_ID_LENGTH / 4);
return;
}