Refactor skip garbage pack logic into a method
There are multiple places in DfsReader to skip garbage pack if both of the following conditions satisfied: * AvoidUnreachable flag is set * The pack is a garabge pack Refactor them into a shared private method. Change-Id: I67d6bb601db55f904437c807c6a3c36f0a723265 Signed-off-by: Zhen Chen <czhen@google.com>
This commit is contained in:
parent
3d8ce05b97
commit
8dd5b644dc
|
@ -165,20 +165,19 @@ public Collection<ObjectId> resolve(AbbreviatedObjectId id)
|
|||
throws IOException {
|
||||
if (id.isComplete())
|
||||
return Collections.singleton(id.toObjectId());
|
||||
boolean noGarbage = avoidUnreachable;
|
||||
HashSet<ObjectId> matches = new HashSet<ObjectId>(4);
|
||||
PackList packList = db.getPackList();
|
||||
resolveImpl(packList, id, noGarbage, matches);
|
||||
resolveImpl(packList, id, matches);
|
||||
if (matches.size() < MAX_RESOLVE_MATCHES && packList.dirty()) {
|
||||
resolveImpl(db.scanPacks(packList), id, noGarbage, matches);
|
||||
resolveImpl(db.scanPacks(packList), id, matches);
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
|
||||
private void resolveImpl(PackList packList, AbbreviatedObjectId id,
|
||||
boolean noGarbage, HashSet<ObjectId> matches) throws IOException {
|
||||
HashSet<ObjectId> matches) throws IOException {
|
||||
for (DfsPackFile pack : packList.packs) {
|
||||
if (noGarbage && pack.isGarbage()) {
|
||||
if (skipGarbagePack(pack)) {
|
||||
continue;
|
||||
}
|
||||
pack.resolve(this, matches, id, MAX_RESOLVE_MATCHES);
|
||||
|
@ -192,20 +191,19 @@ private void resolveImpl(PackList packList, AbbreviatedObjectId id,
|
|||
public boolean has(AnyObjectId objectId) throws IOException {
|
||||
if (last != null && last.hasObject(this, objectId))
|
||||
return true;
|
||||
boolean noGarbage = avoidUnreachable;
|
||||
PackList packList = db.getPackList();
|
||||
if (hasImpl(packList, objectId, noGarbage)) {
|
||||
if (hasImpl(packList, objectId)) {
|
||||
return true;
|
||||
} else if (packList.dirty()) {
|
||||
return hasImpl(db.scanPacks(packList), objectId, noGarbage);
|
||||
return hasImpl(db.scanPacks(packList), objectId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasImpl(PackList packList, AnyObjectId objectId,
|
||||
boolean noGarbage) throws IOException {
|
||||
private boolean hasImpl(PackList packList, AnyObjectId objectId)
|
||||
throws IOException {
|
||||
for (DfsPackFile pack : packList.packs) {
|
||||
if (pack == last || (noGarbage && pack.isGarbage()))
|
||||
if (pack == last || skipGarbagePack(pack))
|
||||
continue;
|
||||
if (pack.hasObject(this, objectId)) {
|
||||
last = pack;
|
||||
|
@ -228,13 +226,12 @@ public ObjectLoader open(AnyObjectId objectId, int typeHint)
|
|||
}
|
||||
|
||||
PackList packList = db.getPackList();
|
||||
boolean noGarbage = avoidUnreachable;
|
||||
ldr = openImpl(packList, objectId, noGarbage);
|
||||
ldr = openImpl(packList, objectId);
|
||||
if (ldr != null) {
|
||||
return checkType(ldr, objectId, typeHint);
|
||||
}
|
||||
if (packList.dirty()) {
|
||||
ldr = openImpl(db.scanPacks(packList), objectId, noGarbage);
|
||||
ldr = openImpl(db.scanPacks(packList), objectId);
|
||||
if (ldr != null) {
|
||||
return checkType(ldr, objectId, typeHint);
|
||||
}
|
||||
|
@ -254,10 +251,10 @@ private static ObjectLoader checkType(ObjectLoader ldr, AnyObjectId id,
|
|||
return ldr;
|
||||
}
|
||||
|
||||
private ObjectLoader openImpl(PackList packList, AnyObjectId objectId,
|
||||
boolean noGarbage) throws IOException {
|
||||
private ObjectLoader openImpl(PackList packList, AnyObjectId objectId)
|
||||
throws IOException {
|
||||
for (DfsPackFile pack : packList.packs) {
|
||||
if (pack == last || (noGarbage && pack.isGarbage())) {
|
||||
if (pack == last || skipGarbagePack(pack)) {
|
||||
continue;
|
||||
}
|
||||
ObjectLoader ldr = pack.get(this, objectId);
|
||||
|
@ -332,7 +329,6 @@ private <T extends ObjectId> void findAllImpl(PackList packList,
|
|||
}
|
||||
int lastIdx = 0;
|
||||
DfsPackFile lastPack = packs[lastIdx];
|
||||
boolean noGarbage = avoidUnreachable;
|
||||
|
||||
OBJECT_SCAN: for (Iterator<T> it = pending.iterator(); it.hasNext();) {
|
||||
T t = it.next();
|
||||
|
@ -351,7 +347,7 @@ private <T extends ObjectId> void findAllImpl(PackList packList,
|
|||
if (i == lastIdx)
|
||||
continue;
|
||||
DfsPackFile pack = packs[i];
|
||||
if (noGarbage && pack.isGarbage())
|
||||
if (skipGarbagePack(pack))
|
||||
continue;
|
||||
try {
|
||||
long p = pack.findOffset(this, t);
|
||||
|
@ -371,6 +367,10 @@ private <T extends ObjectId> void findAllImpl(PackList packList,
|
|||
last = lastPack;
|
||||
}
|
||||
|
||||
private boolean skipGarbagePack(DfsPackFile pack) {
|
||||
return avoidUnreachable && pack.isGarbage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends ObjectId> AsyncObjectLoaderQueue<T> open(
|
||||
Iterable<T> objectIds, final boolean reportMissing) {
|
||||
|
|
Loading…
Reference in New Issue