Thanks for your insights. So setting gc.prunePackExpire = 1.second.ago (or pruneExpire for JGit < 4.3) and running GC twice with some seconds delay should prune the unreferenced object, right?
I changed the code accordingly but the commit is still not garbage collected (note, I am running against HEAD)
@Test
public void testPruneOldOrphanCommit() throws Exception {
StoredConfig config = git.getRepository().getConfig();
config.setString("gc", null, "prunePackExpire", "1.second.ago");
config.setString("gc", null, "pruneExpire", "1.second.ago");
config.save();
ObjectId initial = git.getRepository().resolve("HEAD");
RevCommit orphan = git.commit().setMessage("orphan").call();
changeLastModified(orphan, subtractDays(new Date(), 365));
RefUpdate refUpdate = git.getRepository()
.updateRef("refs/heads/master");
refUpdate.setNewObjectId(initial);
refUpdate.forceUpdate();
FileUtils.delete(new File(git.getRepository().getDirectory(), "logs"),
FileUtils.RECURSIVE | FileUtils.RETRY);
git.gc().setExpire(new Date()).call();
Thread.sleep(4000);
git.gc().setExpire(new Date()).call();
assertNull(git.getRepository().resolve(orphan.name()));
}
From: Matthias Sohn <matthias.sohn@xxxxxxxxx>
To: R�diger Herrmann <ruediger.herrmann@xxxxxx>
Cc: Shawn Pearce <spearce@xxxxxxxxxxx>; "jgit-dev@xxxxxxxxxxx" <jgit-dev@xxxxxxxxxxx>
Sent: Thursday, April 7, 2016 1:26 PM
Subject: Re: [jgit-dev] GarbageCollectCommand does not prune unreferenced commit
in order to avoid race conditions when a pack arrives while a gc is running jgit doesn't immediately prune
garbage objects but puts them in a garbage pack which is only pruned with the next gc after a grace period
defined by gc.prunePackExpire [1] which is 1 hour by default. Before [1] this reused gc.pruneExpire
which is 2 weeks by default which led to pack file explosion, this was fixed by [1] recently.
[1] will be contained in 4.3 which I am going to release today.