diff options
author | David Turner <dturner@twosigma.com> | 2017-01-24 11:31:22 -0500 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2017-01-24 14:22:45 -0800 |
commit | 8bec98cec089fa488f3903e97ee6493b727d7d21 (patch) | |
tree | 3c80dadb41524f9979a52c18b8eafc9ed8051198 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | d3c4c0622f1f007e481112613acd9935d999b358 (diff) | |
download | jgit-8bec98cec089fa488f3903e97ee6493b727d7d21.tar.gz jgit-8bec98cec089fa488f3903e97ee6493b727d7d21.zip |
gc: loosen unreferenced objects
An unreferenced object might appear in a pack. This could only happen
because it was previously referenced, and then later that reference
was removed. When we gc, we copy the referenced objects into a new
pack, and delete the old pack. This would remove the unreferenced
object. Now we first create a loose object from any unreferenced
object in the doomed pack. This kicks off the two-week grace period
for that object, after which it will be collected if it's not
referenced.
This matches the behavior of regular git.
Change-Id: I59539aca1d0d83622c41aa9bfbdd72fa868ee9fb
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java index 8a9ad89600..c7e5973f3f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java @@ -55,6 +55,7 @@ import java.util.Date; import java.util.List; import org.eclipse.jgit.junit.TestRepository.BranchBuilder; +import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.pack.PackConfig; import org.junit.Test; @@ -188,16 +189,26 @@ public class GcBasicPackingTest extends GcTestCase { BranchBuilder bb = tr.branch("refs/heads/master"); bb.commit().message("M").add("M", "M").create(); + String tempRef = "refs/heads/soon-to-be-unreferenced"; + BranchBuilder bb2 = tr.branch(tempRef); + bb2.commit().message("M").add("M", "M").create(); + gc.setExpireAgeMillis(0); gc.gc(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); - assertEquals(3, stats.numberOfPackedObjects); + assertEquals(4, stats.numberOfPackedObjects); assertEquals(1, stats.numberOfPackFiles); File oldPackfile = tr.getRepository().getObjectDatabase().getPacks() .iterator().next().getPackFile(); fsTick(); + + // delete the temp ref, orphaning its commit + RefUpdate update = tr.getRepository().getRefDatabase().newUpdate(tempRef, false); + update.setForceUpdate(true); + update.delete(); + bb.commit().message("B").add("B", "Q").create(); // The old packfile is too young to be deleted. We should end up with @@ -208,7 +219,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(0, stats.numberOfLooseObjects); // if objects exist in multiple packFiles then they are counted multiple // times - assertEquals(9, stats.numberOfPackedObjects); + assertEquals(10, stats.numberOfPackedObjects); assertEquals(2, stats.numberOfPackFiles); // repack again but now without a grace period for loose objects. Since @@ -219,15 +230,19 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(0, stats.numberOfLooseObjects); // if objects exist in multiple packFiles then they are counted multiple // times - assertEquals(9, stats.numberOfPackedObjects); + assertEquals(10, stats.numberOfPackedObjects); assertEquals(2, stats.numberOfPackFiles); // repack again but now without a grace period for packfiles. We should // end up with one packfile gc.setPackExpireAgeMillis(0); + + // we want to keep newly-loosened objects though + gc.setExpireAgeMillis(-1); + gc.gc(); stats = gc.getStatistics(); - assertEquals(0, stats.numberOfLooseObjects); + assertEquals(1, stats.numberOfLooseObjects); // if objects exist in multiple packFiles then they are counted multiple // times assertEquals(6, stats.numberOfPackedObjects); |