summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorZhen Chen <czhen@google.com>2017-02-13 15:28:10 -0800
committerZhen Chen <czhen@google.com>2017-02-13 15:33:23 -0800
commit8dd5b644dc8811ae3ba39fcfbb8babca31a1abe1 (patch)
treeba2b8ee55da41baa53513d5aeca38801675d5096 /org.eclipse.jgit
parent3d8ce05b97d11624005d4f7cd294e1a4dc4554ee (diff)
downloadjgit-8dd5b644dc8811ae3ba39fcfbb8babca31a1abe1.tar.gz
jgit-8dd5b644dc8811ae3ba39fcfbb8babca31a1abe1.zip
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java38
1 files changed, 19 insertions, 19 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
index accab731b9..8d934879e1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReader.java
@@ -165,20 +165,19 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
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 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
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 final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
}
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 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
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 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
}
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 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
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 @@ public final class DfsReader extends ObjectReader implements ObjectReuseAsIs {
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) {