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>
tags/v0.9.1
Shawn O. Pearce 13 years ago
parent
commit
1c3f3fdbd2

+ 0
- 1
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/AbbreviationTest.java View 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));


+ 23
- 11
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java View 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);

Loading…
Cancel
Save