}
logger.debug(MessageFormat.format("GCExecutor locked idle repository {0}", repositoryName));
Git git = new Git(repository);
GarbageCollectCommand gc = git.gc();
Properties stats = gc.getStatistics();
// determine if this is a scheduled GC
Calendar cal = Calendar.getInstance();
cal.setTime(model.lastGC);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.DATE, model.gcPeriod);
Date gcDate = cal.getTime();
boolean shouldCollectGarbage = now.after(gcDate);
// determine if filesize triggered GC
long gcThreshold = FileUtils.convertSizeToLong(model.gcThreshold, 500*1024L);
long sizeOfLooseObjects = (Long) stats.get("sizeOfLooseObjects");
boolean hasEnoughGarbage = sizeOfLooseObjects >= gcThreshold;
// if we satisfy one of the requirements, GC
boolean hasGarbage = sizeOfLooseObjects > 0;
if (hasGarbage && (hasEnoughGarbage || shouldCollectGarbage)) {
long looseKB = sizeOfLooseObjects/1024L;
logger.info(MessageFormat.format("Collecting {1} KB of loose objects from {0}", repositoryName, looseKB));
// do the deed
gc.call();
garbageCollected = true;
}
} catch (Exception e) {
logger.error("Error collecting garbage in " + repositoryName, e);