GC.prune(Set<ObjectId>): return early if objects directory is empty

Change-Id: Id56b102604c4e0437230e3e7c59c0a3a1b676256
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2017-01-30 00:52:33 +01:00
parent 8fd500e20c
commit a11bb03127
1 changed files with 33 additions and 30 deletions

View File

@ -364,45 +364,48 @@ public void prune(Set<ObjectId> objectsToKeep) throws IOException,
Set<ObjectId> indexObjects = null; Set<ObjectId> indexObjects = null;
File objects = repo.getObjectsDirectory(); File objects = repo.getObjectsDirectory();
String[] fanout = objects.list(); String[] fanout = objects.list();
if (fanout != null && fanout.length > 0) { if (fanout == null || fanout.length == 0) {
pm.beginTask(JGitText.get().pruneLooseUnreferencedObjects, return;
fanout.length); }
try { pm.beginTask(JGitText.get().pruneLooseUnreferencedObjects,
for (String d : fanout) { fanout.length);
pm.update(1); try {
if (d.length() != 2) for (String d : fanout) {
pm.update(1);
if (d.length() != 2)
continue;
File[] entries = new File(objects, d).listFiles();
if (entries == null)
continue;
for (File f : entries) {
String fName = f.getName();
if (fName.length() != Constants.OBJECT_ID_STRING_LENGTH - 2)
continue; continue;
File[] entries = new File(objects, d).listFiles(); if (repo.getFS().lastModified(f) >= expireDate)
if (entries == null)
continue; continue;
for (File f : entries) { try {
String fName = f.getName(); ObjectId id = ObjectId.fromString(d + fName);
if (fName.length() != Constants.OBJECT_ID_STRING_LENGTH - 2) if (objectsToKeep.contains(id))
continue; continue;
if (repo.getFS().lastModified(f) >= expireDate) if (indexObjects == null)
indexObjects = listNonHEADIndexObjects();
if (indexObjects.contains(id))
continue; continue;
try { deletionCandidates.put(id, f);
ObjectId id = ObjectId.fromString(d + fName); } catch (IllegalArgumentException notAnObject) {
if (objectsToKeep.contains(id)) // ignoring the file that does not represent loose
continue; // object
if (indexObjects == null) continue;
indexObjects = listNonHEADIndexObjects();
if (indexObjects.contains(id))
continue;
deletionCandidates.put(id, f);
} catch (IllegalArgumentException notAnObject) {
// ignoring the file that does not represent loose
// object
continue;
}
} }
} }
} finally {
pm.endTask();
} }
} finally {
pm.endTask();
} }
if (deletionCandidates.isEmpty())
if (deletionCandidates.isEmpty()) {
return; return;
}
// From the set of current refs remove all those which have been handled // From the set of current refs remove all those which have been handled
// during last repack(). Only those refs will survive which have been // during last repack(). Only those refs will survive which have been