diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2015-06-13 01:38:29 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-06-22 11:18:31 +0200 |
commit | 6b65adca2d50108fcb106904738b444fefe49fd1 (patch) | |
tree | 5a45bd2d2bcfc891c9b8c82c1483457d75f06b1b /org.eclipse.jgit.test | |
parent | 2dd4dc149ce9e6231c42eaa995c52ea3e90181dd (diff) | |
download | jgit-6b65adca2d50108fcb106904738b444fefe49fd1.tar.gz jgit-6b65adca2d50108fcb106904738b444fefe49fd1.zip |
Add a grace period for packfiles during GC
For loose objects an expiration date can be set which will save too
young objects from being deleted. Add the same for packfiles. Packfiles
which are too young are not deleted.
Bug: 468024
Change-Id: I3956411d19b47aaadc215dab360d57fa6c24635e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java | 44 |
1 files changed, 44 insertions, 0 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 0742504d23..bbd41237e2 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 @@ -45,13 +45,16 @@ package org.eclipse.jgit.internal.storage.file; import static org.junit.Assert.assertEquals; +import java.io.File; import java.io.IOException; import java.util.Collection; +import java.util.Date; import java.util.Iterator; import org.eclipse.jgit.junit.TestRepository.BranchBuilder; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.pack.PackConfig; +import org.junit.Test; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; @@ -176,6 +179,47 @@ public class GcBasicPackingTest extends GcTestCase { } } + @Test + public void testDonePruneTooYoungPacks() throws Exception { + BranchBuilder bb = tr.branch("refs/heads/master"); + bb.commit().message("M").add("M", "M").create(); + + gc.setExpireAgeMillis(0); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(0, stats.numberOfLooseObjects); + assertEquals(3, stats.numberOfPackedObjects); + assertEquals(1, stats.numberOfPackFiles); + File oldPackfile = tr.getRepository().getObjectDatabase().getPacks() + .iterator().next().getPackFile(); + + fsTick(); + bb.commit().message("B").add("B", "Q").create(); + + // The old packfile is too young to be deleted. We should end up with + // two pack files + gc.setExpire(new Date(oldPackfile.lastModified() - 1)); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(0, stats.numberOfLooseObjects); + // if objects exist in multiple packFiles then they are counted multiple + // times + assertEquals(9, stats.numberOfPackedObjects); + assertEquals(2, stats.numberOfPackFiles); + + // repack again but now without a grace period for packfiles. We should + // end up with one packfile + gc.setExpireAgeMillis(0); + gc.gc(); + stats = gc.getStatistics(); + assertEquals(0, stats.numberOfLooseObjects); + // if objects exist in multiple packFiles then they are counted multiple + // times + assertEquals(6, stats.numberOfPackedObjects); + assertEquals(1, stats.numberOfPackFiles); + + } + private void configureGc(GC myGc, boolean aggressive) { PackConfig pconfig = new PackConfig(repo); if (aggressive) { |