diff options
author | Colby Ranger <cranger@google.com> | 2013-04-15 09:35:07 -0700 |
---|---|---|
committer | Colby Ranger <cranger@google.com> | 2013-04-15 09:35:07 -0700 |
commit | eaa52b12f542e1d52c277989533a3c1bea3cc02e (patch) | |
tree | a2eabbc3ace44add6863f76841bebcba07c4d9a6 /org.eclipse.jgit/src | |
parent | 4c638be79fde7c34ca0fcaad13d7c4f1d9c5ddd2 (diff) | |
download | jgit-eaa52b12f542e1d52c277989533a3c1bea3cc02e.tar.gz jgit-eaa52b12f542e1d52c277989533a3c1bea3cc02e.zip |
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
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java index d4981236ad..d3e1990a92 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexRemapper.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.internal.storage.file; import java.util.Collections; import java.util.Iterator; +import java.util.NoSuchElementException; import javaewah.EWAHCompressedBitmap; import javaewah.IntIterator; @@ -142,13 +143,24 @@ public class PackBitmapIndexRemapper extends PackBitmapIndex final Iterator<StoredBitmap> it = oldPackIndex.getBitmaps().iterator(); return new Iterator<Entry>() { + private Entry entry; + public boolean hasNext() { - return it.hasNext(); + while (entry == null && it.hasNext()) { + StoredBitmap sb = it.next(); + if (newPackIndex.findPosition(sb) != -1) + entry = new Entry(sb, sb.getFlags()); + } + return entry != null; } public Entry next() { - StoredBitmap sb = it.next(); - return new Entry(sb, sb.getFlags()); + if (!hasNext()) + throw new NoSuchElementException(); + + Entry res = entry; + entry = null; + return res; } public void remove() { @@ -171,6 +183,9 @@ public class PackBitmapIndexRemapper extends PackBitmapIndex if (oldBitmap == null) return null; + if (newPackIndex.findPosition(objectId) == -1) + return null; + inflated.clear(); for (IntIterator i = oldBitmap.getBitmap().intIterator(); i.hasNext();) inflated.set(prevToNewMapping[i.next()]); |