module documentation

Git garbage collection implementation.

Class GCStats Statistics from garbage collection.
Function find_reachable_objects Find all reachable objects in the repository.
Function find_unreachable_objects Find all unreachable objects in the repository.
Function garbage_collect Run garbage collection on a repository.
Function get_prune_grace_period Read gc.pruneExpire from config and return grace period in seconds.
Function maybe_auto_gc Run automatic garbage collection if needed.
Function prune_unreachable_objects Remove unreachable objects from the repository.
Function should_run_gc Check if automatic garbage collection should run.
Constant DEFAULT_GC_AUTO Undocumented
Constant DEFAULT_GC_AUTO_PACK_LIMIT Undocumented
Constant DEFAULT_GC_PRUNE_EXPIRE Undocumented
def find_reachable_objects(object_store: BaseObjectStore, refs_container: RefsContainer, include_reflogs: bool = True, progress: Callable[[str], None] | None = None) -> set[ObjectID]:

Find all reachable objects in the repository.

Parameters
object_store:BaseObjectStoreObject store to search
refs_container:RefsContainerReference container
include_reflogs:boolWhether to include reflog entries
progress:Callable[[str], None] | NoneOptional progress callback
Returns
set[ObjectID]Set of reachable object SHAs
def find_unreachable_objects(object_store: BaseObjectStore, refs_container: RefsContainer, include_reflogs: bool = True, progress: Callable[[str], None] | None = None) -> set[ObjectID]:

Find all unreachable objects in the repository.

Parameters
object_store:BaseObjectStoreObject store to search
refs_container:RefsContainerReference container
include_reflogs:boolWhether to include reflog entries
progress:Callable[[str], None] | NoneOptional progress callback
Returns
set[ObjectID]Set of unreachable object SHAs
def garbage_collect(repo: Repo, auto: bool = False, aggressive: bool = False, prune: bool = True, grace_period: int | None = 1209600, dry_run: bool = False, progress: Callable[[str], None] | None = None) -> GCStats:

Run garbage collection on a repository.

Parameters
repo:RepoRepository to garbage collect
auto:boolWhether this is an automatic gc
aggressive:boolWhether to use aggressive settings
prune:boolWhether to prune unreachable objects
grace_period:int | NoneGrace period for pruning in seconds
dry_run:boolIf True, only report what would be done
progress:Callable[[str], None] | NoneOptional progress callback
Returns
GCStatsGCStats object with garbage collection statistics
def get_prune_grace_period(config: Config) -> int:

Read gc.pruneExpire from config and return grace period in seconds.

If gc.pruneExpire is not set, returns the default of 2 weeks.

Parameters
config:ConfigRepository configuration
Returns
intGrace period in seconds
Raises
ValueErrorIf the configured value cannot be parsed
def maybe_auto_gc(repo: Repo, config: Config | None = None, progress: Callable[[str], None] | None = None) -> bool:

Run automatic garbage collection if needed.

Parameters
repo:RepoRepository to potentially GC
config:Config | NoneConfiguration to use (defaults to repo config)
progress:Callable[[str], None] | NoneOptional progress reporting callback
Returns
boolTrue if GC was run, False otherwise
def prune_unreachable_objects(object_store: DiskObjectStore, refs_container: RefsContainer, grace_period: int | None = None, dry_run: bool = False, progress: Callable[[str], None] | None = None) -> tuple[set[ObjectID], int]:

Remove unreachable objects from the repository.

Parameters
object_store:DiskObjectStoreObject store to prune
refs_container:RefsContainerReference container
grace_period:int | NoneGrace period in seconds (objects newer than this are kept)
dry_run:boolIf True, only report what would be deleted
progress:Callable[[str], None] | NoneOptional progress callback
Returns
tuple[set[ObjectID], int]Tuple of (set of pruned object SHAs, total bytes freed)
def should_run_gc(repo: BaseRepo, config: Config | None = None) -> bool:

Check if automatic garbage collection should run.

Parameters
repo:BaseRepoRepository to check
config:Config | NoneConfiguration to use (defaults to repo config)
Returns
boolTrue if GC should run, False otherwise
DEFAULT_GC_AUTO: int =

Undocumented

Value
6700
DEFAULT_GC_AUTO_PACK_LIMIT: int =

Undocumented

Value
50
DEFAULT_GC_PRUNE_EXPIRE: int =

Undocumented

Value
1209600