@ -55,6 +55,7 @@ import java.util.Date;
import java.util.List ;
import java.util.List ;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder ;
import org.eclipse.jgit.junit.TestRepository.BranchBuilder ;
import org.eclipse.jgit.lib.RefUpdate ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.storage.pack.PackConfig ;
import org.eclipse.jgit.storage.pack.PackConfig ;
import org.junit.Test ;
import org.junit.Test ;
@ -188,16 +189,26 @@ public class GcBasicPackingTest extends GcTestCase {
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
BranchBuilder bb = tr . branch ( "refs/heads/master" ) ;
bb . commit ( ) . message ( "M" ) . add ( "M" , "M" ) . create ( ) ;
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 . setExpireAgeMillis ( 0 ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 3 , stats . numberOfPackedObjects ) ;
assertEquals ( 4 , stats . numberOfPackedObjects ) ;
assertEquals ( 1 , stats . numberOfPackFiles ) ;
assertEquals ( 1 , stats . numberOfPackFiles ) ;
File oldPackfile = tr . getRepository ( ) . getObjectDatabase ( ) . getPacks ( )
File oldPackfile = tr . getRepository ( ) . getObjectDatabase ( ) . getPacks ( )
. iterator ( ) . next ( ) . getPackFile ( ) ;
. iterator ( ) . next ( ) . getPackFile ( ) ;
fsTick ( ) ;
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 ( ) ;
bb . commit ( ) . message ( "B" ) . add ( "B" , "Q" ) . create ( ) ;
// The old packfile is too young to be deleted. We should end up with
// 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 ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
// if objects exist in multiple packFiles then they are counted multiple
// if objects exist in multiple packFiles then they are counted multiple
// times
// times
assertEquals ( 9 , stats . numberOfPackedObjects ) ;
assertEquals ( 10 , stats . numberOfPackedObjects ) ;
assertEquals ( 2 , stats . numberOfPackFiles ) ;
assertEquals ( 2 , stats . numberOfPackFiles ) ;
// repack again but now without a grace period for loose objects. Since
// 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 ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
// if objects exist in multiple packFiles then they are counted multiple
// if objects exist in multiple packFiles then they are counted multiple
// times
// times
assertEquals ( 9 , stats . numberOfPackedObjects ) ;
assertEquals ( 10 , stats . numberOfPackedObjects ) ;
assertEquals ( 2 , stats . numberOfPackFiles ) ;
assertEquals ( 2 , stats . numberOfPackFiles ) ;
// repack again but now without a grace period for packfiles. We should
// repack again but now without a grace period for packfiles. We should
// end up with one packfile
// end up with one packfile
gc . setPackExpireAgeMillis ( 0 ) ;
gc . setPackExpireAgeMillis ( 0 ) ;
// we want to keep newly-loosened objects though
gc . setExpireAgeMillis ( - 1 ) ;
gc . gc ( ) ;
gc . gc ( ) ;
stats = gc . getStatistics ( ) ;
stats = gc . getStatistics ( ) ;
assertEquals ( 0 , stats . numberOfLooseObjects ) ;
assertEquals ( 1 , stats . numberOfLooseObjects ) ;
// if objects exist in multiple packFiles then they are counted multiple
// if objects exist in multiple packFiles then they are counted multiple
// times
// times
assertEquals ( 6 , stats . numberOfPackedObjects ) ;
assertEquals ( 6 , stats . numberOfPackedObjects ) ;