Skip to content

Commit eaa52b1

Browse files
Update PackBitmapIndexRemapper to handle mappings not in the new pack.
Previously, the code assumed all commits in the old pack would also be present in the new pack. This assumption caused an ArrayIndexOutOfBoundsException during remapping of ids. Fix the iterator to only return entries that may be remapped. Furthermore, update getBitmap() to return null if commit does not exist in the new pack. Change-Id: I065babe8cd39a7654c916bd01c7012135733dddf
1 parent 4c638be commit eaa52b1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
import java.util.Collections;
4747
import java.util.Iterator;
48+
import java.util.NoSuchElementException;
4849

4950
import javaewah.EWAHCompressedBitmap;
5051
import javaewah.IntIterator;
@@ -142,13 +143,24 @@ public Iterator<Entry> iterator() {
142143

143144
final Iterator<StoredBitmap> it = oldPackIndex.getBitmaps().iterator();
144145
return new Iterator<Entry>() {
146+
private Entry entry;
147+
145148
public boolean hasNext() {
146-
return it.hasNext();
149+
while (entry == null && it.hasNext()) {
150+
StoredBitmap sb = it.next();
151+
if (newPackIndex.findPosition(sb) != -1)
152+
entry = new Entry(sb, sb.getFlags());
153+
}
154+
return entry != null;
147155
}
148156

149157
public Entry next() {
150-
StoredBitmap sb = it.next();
151-
return new Entry(sb, sb.getFlags());
158+
if (!hasNext())
159+
throw new NoSuchElementException();
160+
161+
Entry res = entry;
162+
entry = null;
163+
return res;
152164
}
153165

154166
public void remove() {
@@ -171,6 +183,9 @@ public EWAHCompressedBitmap getBitmap(AnyObjectId objectId) {
171183
if (oldBitmap == null)
172184
return null;
173185

186+
if (newPackIndex.findPosition(objectId) == -1)
187+
return null;
188+
174189
inflated.clear();
175190
for (IntIterator i = oldBitmap.getBitmap().intIterator(); i.hasNext();)
176191
inflated.set(prevToNewMapping[i.next()]);

0 commit comments

Comments
 (0)