From 1c3f3fdbd237f1f344c8ea081a47c698f47a0de6 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 24 Aug 2010 17:20:50 -0700 Subject: [PATCH] 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 --- .../jgit/storage/file/AbbreviationTest.java | 1 - .../jgit/storage/file/ObjectDirectory.java | 34 +++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) 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 5e8f72b5b..96e36a2a6 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 eb9be3855..76fbe6e2d 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);