From: Shawn O. Pearce Date: Wed, 25 Aug 2010 00:20:50 +0000 (-0700) Subject: Fix ObjectDirectory abbreviation resolution to notice new packs X-Git-Tag: v0.9.1~82 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F1406%2F1;p=jgit.git Fix ObjectDirectory abbreviation resolution to notice new packs 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 --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java index 5e8f72b5ba..96e36a2a6b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java @@ -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)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java index eb9be38552..76fbe6e2d0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java @@ -287,19 +287,31 @@ public class ObjectDirectory extends FileObjectDatabase implements void resolve(Set 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);