Browse Source

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 <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 14 years ago
parent
commit
1c3f3fdbd2
  1. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java
  2. 34
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java

@ -173,7 +173,6 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase {
dst.close(); dst.close();
} }
new FileOutputStream(packFile).close(); new FileOutputStream(packFile).close();
db.openPack(packFile, idxFile);
assertEquals(id.abbreviate(20), reader.abbreviate(id, 2)); assertEquals(id.abbreviate(20), reader.abbreviate(id, 2));

34
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java

@ -287,19 +287,31 @@ public class ObjectDirectory extends FileObjectDatabase implements
void resolve(Set<ObjectId> matches, AbbreviatedObjectId id) void resolve(Set<ObjectId> matches, AbbreviatedObjectId id)
throws IOException { 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(); PackList pList = packList.get();
if (pList == null) for (;;) {
pList = scanPacks(pList); for (PackFile p : pList.packs) {
for (PackFile p : pList.packs) { try {
try { p.resolve(matches, id, RESOLVE_ABBREV_LIMIT);
p.resolve(matches, id, RESOLVE_ABBREV_LIMIT); } catch (IOException e) {
} catch (IOException e) { // Assume the pack is corrupted.
// Assume the pack is corrupted. //
// removePack(p);
removePack(p); }
if (matches.size() > RESOLVE_ABBREV_LIMIT)
return;
} }
if (matches.size() > RESOLVE_ABBREV_LIMIT) if (matches.size() == oldSize) {
return; PackList nList = scanPacks(pList);
if (nList == pList || nList.packs.length == 0)
break;
pList = nList;
continue;
}
break;
} }
String fanOut = id.name().substring(0, 2); String fanOut = id.name().substring(0, 2);

Loading…
Cancel
Save