Re: [PATCH 02/11] builtin/gc: move worktree and rerere tasks before object optimizations
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 7, 2026, 20:27 UTC
- Message-ID
- <xmqqbjci1r6z.fsf@gitster.g>
- In-Reply-To
- <20260707-b4-pks-odb-optimize-v1-2-aae607667be4@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 15 quoted lines
> In subsequent patches we'll consolidate all tasks that relate to > maintenance of the object database and move it into the "files" backend. > The relevant code is somewhat scattered though, as several other tasks > are interspersed between. > > Refactor the code so that all object database optimizations are grouped > together, which requires us to move worktree pruning and rerere garbage > collection around. In theory, rearranging this code can have an effect > on the object database optimizations: > > - Rerere entries really shouldn't impact garbage collection at all, as > these entries are not stored in the object database. > > - The index and HEAD reference of pruned worktrees may reference > objects that become unreachable.
Over time "gc" (and more prominently, "maintenance") ceased to be about object database optimization but about general housekeeping operations to keep your repository healthy. rerere database, reflog, packed-refs and reftable compaction are all outside the scope of object database optimization. Grouping these inside the umbrella "gc/maintenance" framework would be a good first step to make parts of them pluggable.
Show 44 quoted lines
> That being said, the impact should be overall rather negligible. If the
> user was asking us to prune objects with immediate expiration time then
> we might now prune objects that were previously still kept alive by the
> worktree. But besides being a very specific edge case, it's arguably not
> even the wrong thing to also prune any potentially-unreachable objects
> immediately.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> builtin/gc.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 77d0a5c948..8f568003ee 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1011,6 +1011,13 @@ int cmd_gc(int argc,
> if (opts.detach <= 0 && !skip_foreground_tasks)
> gc_foreground_tasks(&opts, &cfg);
>
> + if (cfg.prune_worktrees_expire &&
> + maintenance_task_worktree_prune(&opts, &cfg))
> + die(FAILED_RUN, "worktree");
> +
> + if (maintenance_task_rerere_gc(&opts, &cfg))
> + die(FAILED_RUN, "rerere");
> +
> if (!the_repository->repository_format_precious_objects) {
> struct child_process repack_cmd = CHILD_PROCESS_INIT;
>
> @@ -1038,13 +1045,6 @@ int cmd_gc(int argc,
> }
> }
>
> - if (cfg.prune_worktrees_expire &&
> - maintenance_task_worktree_prune(&opts, &cfg))
> - die(FAILED_RUN, "worktree");
> -
> - if (maintenance_task_rerere_gc(&opts, &cfg))
> - die(FAILED_RUN, "rerere");
> -
> report_garbage = report_pack_garbage;
> odb_reprepare(the_repository->objects);
> if (pack_garbage.nr > 0) {