public class GC extends Object
FileRepository
. Instances of
this class are not thread-safe. Don't use the same instance from multiple
threads.
This class started as a copy of DfsGarbageCollector from Shawn O. Pearce
adapted to FileRepositories.Modifier and Type | Class and Description |
---|---|
static class |
GC.RepoStatistics
A class holding statistical data for a FileRepository regarding how many
objects are stored as loose or packed objects
|
Constructor and Description |
---|
GC(FileRepository repo)
Creates a new garbage collector with default values.
|
Modifier and Type | Method and Description |
---|---|
Collection<PackFile> |
gc()
Runs a garbage collector on a
FileRepository . |
GC.RepoStatistics |
getStatistics()
Returns information about objects and pack files for a FileRepository.
|
void |
packRefs()
Packs all non-symbolic, loose refs into packed-refs.
|
void |
prune(Set<ObjectId> objectsToKeep)
Like "git prune" this method tries to prune all loose objects which are
unreferenced.
|
void |
prunePacked()
Like "git prune-packed" this method tries to prune all loose objects
which can be found in packs.
|
Collection<PackFile> |
repack()
Packs all objects which reachable from any of the heads into one pack
file.
|
void |
setAuto(boolean auto)
Set the
gc --auto option. |
static void |
setExecutor(ExecutorService e)
Set the executor for running auto-gc in the background.
|
void |
setExpire(Date expire)
During gc() or prune() each unreferenced, loose object which has been
created or modified after or at
expire will not be pruned. |
void |
setExpireAgeMillis(long expireAgeMillis)
During gc() or prune() each unreferenced, loose object which has been
created or modified in the last
expireAgeMillis milliseconds
will not be pruned. |
void |
setPackConfig(PackConfig pconfig)
Set the PackConfig used when (re-)writing packfiles.
|
void |
setPackExpire(Date packExpire)
During gc() or prune() packfiles which are created or modified after or
at
packExpire will not be deleted. |
void |
setPackExpireAgeMillis(long packExpireAgeMillis)
During gc() or prune() packfiles which are created or modified in the
last
packExpireAgeMillis milliseconds will not be deleted. |
GC |
setProgressMonitor(ProgressMonitor pm)
Set the progress monitor used for garbage collection methods.
|
public GC(FileRepository repo)
null
as progress monitor will be used.repo
- the repo to work onpublic static void setExecutor(ExecutorService e)
e
- the executor to be used for running auto-gcpublic Collection<PackFile> gc() throws IOException, ParseException
FileRepository
. It will
setAuto(boolean)
was set to true
gc
will
first check whether any housekeeping is required; if not, it exits
without performing any work.
If setBackground(boolean)
was set to true
collectGarbage
will start the gc in the background, and then
return immediately. In this case, errors will not be reported except in
gc.log.PackFile
's which
are newly createdIOException
ParseException
- If the configuration parameter "gc.pruneexpire" couldn't be
parsedpublic void prunePacked() throws IOException
IOException
public void prune(Set<ObjectId> objectsToKeep) throws IOException, ParseException
objectsToKeep
- a set of objects which should explicitly not be prunedIOException
ParseException
- If the configuration parameter "gc.pruneexpire" couldn't be
parsedpublic void packRefs() throws IOException
IOException
public Collection<PackFile> repack() throws IOException
IOException
- when during reading of refs, index, packfiles, objects,
reflog-entries or during writing to the packfiles
IOException
occurspublic GC.RepoStatistics getStatistics() throws IOException
IOException
public GC setProgressMonitor(ProgressMonitor pm)
pm
- a ProgressMonitor
object.public void setExpireAgeMillis(long expireAgeMillis)
expireAgeMillis
milliseconds
will not be pruned. Only older objects may be pruned. If set to 0 then
every object is a candidate for pruning.expireAgeMillis
- minimal age of objects to be pruned in milliseconds.public void setPackExpireAgeMillis(long packExpireAgeMillis)
packExpireAgeMillis
milliseconds will not be deleted.
Only older packfiles may be deleted. If set to 0 then every packfile is a
candidate for deletion.packExpireAgeMillis
- minimal age of packfiles to be deleted in milliseconds.public void setPackConfig(@NonNull PackConfig pconfig)
pconfig
- the PackConfig
used when
writing packspublic void setExpire(Date expire)
expire
will not be pruned.
Only older objects may be pruned. If set to null then every object is a
candidate for pruning.expire
- instant in time which defines object expiration
objects with modification time before this instant are expired
objects with modification time newer or equal to this instant
are not expiredpublic void setPackExpire(Date packExpire)
packExpire
will not be deleted. Only older packfiles may
be deleted. If set to null then every packfile is a candidate for
deletion.packExpire
- instant in time which defines packfile expirationpublic void setAuto(boolean auto)
gc --auto
option.
With this option, gc checks whether any housekeeping is required; if not,
it exits without performing any work. Some JGit commands run
gc --auto
after performing operations that could create many
loose objects.
Housekeeping is required if there are too many loose objects or too many
packs in the repository. If the number of loose objects exceeds the value
of the gc.auto option JGit GC consolidates all existing packs into a
single pack (equivalent to -A
option), whereas git-core would
combine all loose objects into a single pack using repack -d -l
.
Setting the value of gc.auto
to 0 disables automatic packing of
loose objects.
If the number of packs exceeds the value of gc.autoPackLimit
,
then existing packs (except those marked with a .keep file) are
consolidated into a single pack by using the -A
option of repack.
Setting gc.autoPackLimit
to 0 disables automatic consolidation of
packs.
Like git the following jgit commands run auto gc:
receive.autogc = false
auto
- defines whether gc should do automatic housekeepingCopyright © 2019 Eclipse JGit Project. All rights reserved.