]> source.dussan.org Git - jgit.git/commitdiff
Fix ObjectDirectory abbreviation resolution to notice new packs 06/1406/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 25 Aug 2010 00:20:50 +0000 (17:20 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 25 Aug 2010 00:37:07 +0000 (17:37 -0700)
If we can't resolve an abbreviation, it might be because there is
a new pack file we haven't picked up yet.  Try scanning the packs
again and recheck each pack if there were differences from the last
scan we did.

Because of this, we don't have to open a pack during the test where
we generate a pack on the fly.  We'll miss on the first loop during
which the PackList is the NO_PACKS magic initialization constant,
and pick up the newly created index during this retry logic.

Change-Id: I7b97efb29a695ee60c90818be380f7ea23ad13a3
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java

index 5e8f72b5ba470197c0ca8255f193d3a5c9d2469f..96e36a2a6b2ad1cde3ef51577fe6ad755bff02ee 100644 (file)
@@ -173,7 +173,6 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase {
                        dst.close();
                }
                new FileOutputStream(packFile).close();
-               db.openPack(packFile, idxFile);
 
                assertEquals(id.abbreviate(20), reader.abbreviate(id, 2));
 
index eb9be385522d465e16335cba1d2b7a87b41e113e..76fbe6e2d000c96292bd78303c46d8a4c115e0e2 100644 (file)
@@ -287,19 +287,31 @@ public class ObjectDirectory extends FileObjectDatabase implements
 
        void resolve(Set<ObjectId> matches, AbbreviatedObjectId id)
                        throws IOException {
+               // Go through the packs once. If we didn't find any resolutions
+               // scan for new packs and check once more.
+               //
+               int oldSize = matches.size();
                PackList pList = packList.get();
-               if (pList == null)
-                       pList = scanPacks(pList);
-               for (PackFile p : pList.packs) {
-                       try {
-                               p.resolve(matches, id, RESOLVE_ABBREV_LIMIT);
-                       } catch (IOException e) {
-                               // Assume the pack is corrupted.
-                               //
-                               removePack(p);
+               for (;;) {
+                       for (PackFile p : pList.packs) {
+                               try {
+                                       p.resolve(matches, id, RESOLVE_ABBREV_LIMIT);
+                               } catch (IOException e) {
+                                       // Assume the pack is corrupted.
+                                       //
+                                       removePack(p);
+                               }
+                               if (matches.size() > RESOLVE_ABBREV_LIMIT)
+                                       return;
                        }
-                       if (matches.size() > RESOLVE_ABBREV_LIMIT)
-                               return;
+                       if (matches.size() == oldSize) {
+                               PackList nList = scanPacks(pList);
+                               if (nList == pList || nList.packs.length == 0)
+                                       break;
+                               pList = nList;
+                               continue;
+                       }
+                       break;
                }
 
                String fanOut = id.name().substring(0, 2);