@ -111,6 +111,8 @@ import org.eclipse.jgit.util.SystemReader;
public class GC {
public class GC {
private static final String PRUNE_EXPIRE_DEFAULT = "2.weeks.ago" ; //$NON-NLS-1$
private static final String PRUNE_EXPIRE_DEFAULT = "2.weeks.ago" ; //$NON-NLS-1$
private static final String PRUNE_PACK_EXPIRE_DEFAULT = "1.hour.ago" ; //$NON-NLS-1$
private final FileRepository repo ;
private final FileRepository repo ;
private ProgressMonitor pm ;
private ProgressMonitor pm ;
@ -119,6 +121,10 @@ public class GC {
private Date expire ;
private Date expire ;
private long packExpireAgeMillis = - 1 ;
private Date packExpire ;
private PackConfig pconfig = null ;
private PackConfig pconfig = null ;
/ * *
/ * *
@ -186,7 +192,7 @@ public class GC {
* /
* /
private void deleteOldPacks ( Collection < PackFile > oldPacks ,
private void deleteOldPacks ( Collection < PackFile > oldPacks ,
Collection < PackFile > newPacks ) throws ParseException {
Collection < PackFile > newPacks ) throws ParseException {
long e xpireDate = getExpireDate ( ) ;
long packE xpireDate = getPack ExpireDate ( ) ;
oldPackLoop : for ( PackFile oldPack : oldPacks ) {
oldPackLoop : for ( PackFile oldPack : oldPacks ) {
String oldName = oldPack . getPackName ( ) ;
String oldName = oldPack . getPackName ( ) ;
// check whether an old pack file is also among the list of new
// check whether an old pack file is also among the list of new
@ -196,7 +202,7 @@ public class GC {
continue oldPackLoop ;
continue oldPackLoop ;
if ( ! oldPack . shouldBeKept ( )
if ( ! oldPack . shouldBeKept ( )
& & oldPack . getPackFile ( ) . lastModified ( ) < e xpireDate) {
& & oldPack . getPackFile ( ) . lastModified ( ) < packE xpireDate) {
oldPack . close ( ) ;
oldPack . close ( ) ;
prunePack ( oldName ) ;
prunePack ( oldName ) ;
}
}
@ -449,6 +455,26 @@ public class GC {
return expireDate ;
return expireDate ;
}
}
private long getPackExpireDate ( ) throws ParseException {
long packExpireDate = Long . MAX_VALUE ;
if ( packExpire = = null & & packExpireAgeMillis = = - 1 ) {
String prunePackExpireStr = repo . getConfig ( ) . getString (
ConfigConstants . CONFIG_GC_SECTION , null ,
ConfigConstants . CONFIG_KEY_PRUNEPACKEXPIRE ) ;
if ( prunePackExpireStr = = null )
prunePackExpireStr = PRUNE_PACK_EXPIRE_DEFAULT ;
packExpire = GitDateParser . parse ( prunePackExpireStr , null ,
SystemReader . getInstance ( ) . getLocale ( ) ) ;
packExpireAgeMillis = - 1 ;
}
if ( packExpire ! = null )
packExpireDate = packExpire . getTime ( ) ;
if ( packExpireAgeMillis ! = - 1 )
packExpireDate = System . currentTimeMillis ( ) - packExpireAgeMillis ;
return packExpireDate ;
}
/ * *
/ * *
* Remove all entries from a map which key is the id of an object referenced
* Remove all entries from a map which key is the id of an object referenced
* by the given ObjectWalk
* by the given ObjectWalk
@ -982,6 +1008,20 @@ public class GC {
expire = null ;
expire = null ;
}
}
/ * *
* During gc ( ) or prune ( ) packfiles which are created or modified in the
* last < code > packExpireAgeMillis < / code > milliseconds will not be deleted .
* Only older packfiles may be deleted . If set to 0 then every packfile is a
* candidate for deletion .
*
* @param packExpireAgeMillis
* minimal age of packfiles to be deleted in milliseconds .
* /
public void setPackExpireAgeMillis ( long packExpireAgeMillis ) {
this . packExpireAgeMillis = packExpireAgeMillis ;
expire = null ;
}
/ * *
/ * *
* Set the PackConfig used when ( re - ) writing packfiles . This allows to
* Set the PackConfig used when ( re - ) writing packfiles . This allows to
* influence how packs are written and to implement something similar to
* influence how packs are written and to implement something similar to
@ -1011,4 +1051,18 @@ public class GC {
this . expire = expire ;
this . expire = expire ;
expireAgeMillis = - 1 ;
expireAgeMillis = - 1 ;
}
}
/ * *
* During gc ( ) or prune ( ) packfiles which are created or modified after or
* at < code > packExpire < / code > will not be deleted . Only older packfiles may
* be deleted . If set to null then every packfile is a candidate for
* deletion .
*
* @param packExpire
* instant in time which defines packfile expiration
* /
public void setPackExpire ( Date packExpire ) {
this . packExpire = packExpire ;
packExpireAgeMillis = - 1 ;
}
}
}