Top Description Inners Fields Constructors Methods
org.eclipse.jgit.internal.storage.file

public Class GC

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.internal.storage.pack.PackExt.BITMAP_INDEX, .PackExt.COMMIT_GRAPH, .PackExt.INDEX, .PackExt.KEEP, .PackExt.PACK, .PackExt.REVERSE_INDEX

A garbage collector for git org.eclipse.jgit.internal.storage.file.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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
public static class
GC.RepoStatistics

A class holding statistical data for a FileRepository regarding how many objects are stored as loose or packed objects

Field Summary

Modifier and TypeField and Description
private boolean
automatic

Whether gc should do automatic housekeeping

private boolean
background

Whether to run gc in a background thread

private static final Set<PackExt>
private static final int
private static final int
private static final boolean
private static final boolean
private static volatile ExecutorService
private Instant
private long
private Collection<Ref>
lastPackedRefs

the refs which existed during the last call to repack().

private long
lastRepackTime

Holds the starting time of the last repack() execution.

private static final Logger
private Instant
private long
private Boolean
private static final Set<PackExt>
private static final Pattern
private PackConfig
private ProgressMonitor
private static final String
private static final String
private final FileRepository

Constructor Summary

AccessConstructor and Description
public
GC(FileRepository
the repo to work on
repo
)

Creates a new garbage collector with default values.

Method Summary

Modifier and TypeMethod and Description
private void
private boolean
canBeSafelyDeleted(Path path, Instant threshold)

private void
private void
private void
private void
private void
deleteOldPacks(Collection<Pack>
old pack files
oldPacks
,
Collection<Pack>
new pack files
newPacks
)

Delete old pack files.

private void
deleteOrphans()

Deletes orphans

A file is considered an orphan if it is some type of index file, but there is not a corresponding pack or keep file present in the directory.

private void
private void
private Collection<Pack>
doGc()

private static boolean
equals(Ref r1, Ref r2)

private ExecutorService
public CompletableFuture<Collection<Pack>>

Returns:

the collection of org.eclipse.jgit.internal.storage.file.Pack's which are newly created
gc
()

Runs a garbage collector on a org.eclipse.jgit.internal.storage.file.FileRepository.

private Collection<Ref>

Returns:

a collection of refs pointing to live objects.
getAllRefs
()

Returns a collection of all refs and additional refs.

private long
private int
private long
private String
public GC.RepoStatistics

Returns:

information about objects and pack files for a FileRepository
getStatistics
()

Returns information about objects and pack files for a FileRepository.

private boolean
private static boolean
isHead(Ref ref)

private static boolean
isTag(Ref ref)

private Set<ObjectId>

Returns:

a set of ObjectIds of changed objects in the index
listNonHEADIndexObjects
()

Return a list of those objects in the index which differ from whats in HEAD

private Set<ObjectId>

Returns:

the ObjectIds contained in the reflog
listRefLogObjects
(Ref
the ref which log should be inspected
ref
,
long
only reflog entries not older then this time are processed
minTime
)

private void
loosen(ObjectDirectoryInserter
used to insert objects
inserter
,
ObjectReader
used to read objects
reader
,
Pack
the pack file to loosen objects for
pack
,
HashSet<ObjectId>
existing objects
existing
)

Loosen objects in a pack file which are not also in the newly-created pack files.

private boolean
public void
prune(Set<ObjectId>
a set of objects which should explicitly not be pruned
objectsToKeep
)

Like "git prune" this method tries to prune all loose objects which are unreferenced.

private void
prunePack(PackFile
the pack file to prune files for
packFile
)

Delete files associated with a single pack file.

public void
prunePacked()

Like "git prune-packed" this method tries to prune all loose objects which can be found in packs.

private void
prunePreserved()

Delete the preserved directory including all pack files within

private Set<ObjectId>
private void
removeOldPack(PackFile
the packfile to delete
packFile
,
int
delete option flags
deleteOptions
)

Deletes old pack file, unless 'preserve-oldpacks' is set, in which case it moves the pack file to the preserved directory

private void
removeReferenced(Map<ObjectId, File>
mapping objectIds to files
id2File
,
ObjectWalk
used to walk objects
w
)

Remove all entries from a map which key is the id of an object referenced by the given ObjectWalk

public Collection<Pack>

Returns:

a collection of the newly created pack files
repack
()

Packs all objects which reachable from any of the heads into one pack file.

public void
setAuto(boolean
defines whether gc should do automatic housekeeping
auto
)

Set the gc --auto option.

pack-priv void
setBackground(boolean
whether to run the gc in a background thread.
background
)

public static void
setExecutor(ExecutorService
the executor to be used for running auto-gc
e
)

Set the executor for running auto-gc in the background.

public void
setExpire(Date
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 expired
expire
)
Deprecated since 7.2. use setExpire(Instant) instead

During gc() or prune() each unreferenced, loose object which has been created or modified after or at expire will not be pruned.

public void
setExpire(Instant
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 expired
expire
)

During gc() or prune() each unreferenced, loose object which has been created or modified after or at expire will not be pruned.

public void
setExpireAgeMillis(long
minimal age of objects to be pruned in milliseconds.
expireAgeMillis
)

During gc() or prune() each unreferenced, loose object which has been created or modified in the last expireAgeMillis milliseconds will not be pruned.

public void
setPackConfig(PackConfig
the org.eclipse.jgit.storage.pack.PackConfig used when writing packs
pconfig
)

Set the PackConfig used when (re-)writing packfiles.

public void
setPackExpire(Date
instant in time which defines packfile expiration
packExpire
)
Deprecated since 7.2. use setPackExpire(Instant) instead

During gc() or prune() packfiles which are created or modified after or at packExpire will not be deleted.

public void
setPackExpire(Instant
instant in time which defines packfile expiration
packExpire
)

During gc() or prune() packfiles which are created or modified after or at packExpire will not be deleted.

public void
setPackExpireAgeMillis(long
minimal age of packfiles to be deleted in milliseconds.
packExpireAgeMillis
)

During gc() or prune() packfiles which are created or modified in the last packExpireAgeMillis milliseconds will not be deleted.

public void
setPackKeptObjects(boolean
Whether to include objects in `.keep` files when repacking.
packKeptObjects
)

Define whether to include objects in `.keep` files when repacking.

public GC

Returns:

this
setProgressMonitor
(ProgressMonitor pm)

Set the progress monitor used for garbage collection methods.

private boolean
pack-priv boolean

Returns:

true if bloom filter should be written. Default is false.
shouldWriteBloomFilter
()

If true, generates bloom filter in the commit-graph file.

pack-priv boolean

Returns:

true if commit-graph should be written. Default is false.
shouldWriteCommitGraphWhenGc
()

If true, will rewrite the commit-graph file when gc is run.

pack-priv boolean

Returns:

true if number of loose objects > gc.auto (default 6700)
tooManyLooseObjects
()

Quickly estimate number of loose objects, SHA1 is distributed evenly so counting objects in one directory (bucket 17) is sufficient

pack-priv boolean

Returns:

true if number of packs > gc.autopacklimit (default 50)
tooManyPacks
()

Whether number of packs exceeds gc.autopacklimit

private static Optional<PackFile>
private Set<? extends ObjectId>
union(Set<ObjectId> tags, Set<ObjectId> excludedRefsHeadsTips)

pack-priv void
writeCommitGraph(Set<? extends ObjectId>
the list of wanted objects, writer walks commits starting at these. Must not be null.
wants
)

Generate a new commit-graph file when 'core.commitGraph' is true.

private Pack
writePack(Set<? extends ObjectId> want, Set<? extends ObjectId> have, Set<ObjectId> tags, Set<ObjectId> excludedRefsTips, Set<ObjectId> tagTargets, List<ObjectIdSet> excludeObjects, boolean createBitmap)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait