From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 03/11] builtin/gc: extract object database optimizations into separate function
Date: Tue, 07 Jul 2026 13:30:05 -0700 [thread overview]
Message-ID: <xmqq7bn61r1u.fsf@gitster.g> (raw)
In-Reply-To: <20260707-b4-pks-odb-optimize-v1-3-aae607667be4@pks.im> (Patrick Steinhardt's message of "Tue, 07 Jul 2026 17:32:35 +0200")
Patrick Steinhardt <ps@pks.im> writes:
> Extract the object database optimization logic from `cmd_gc()` into a
> new `maintenance_task_odb()` helper function. This is a pure refactoring
> with no intended functional change.
>
> Note that the message that notifies the user about too many loose
> objects is moved into the new function, as well. It is inherently an
> implementation detail of how the "files" source works, and as a
> consequence we'll move it around in a later commit, as well. This
> reordering means that the warning may now be printed at a different
> point in time, but it's not expected that this will have any practical
> implications.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> builtin/gc.c | 79 +++++++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 49 insertions(+), 30 deletions(-)
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 8f568003ee..2ff98fa727 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -839,6 +839,53 @@ static int gc_foreground_tasks(struct maintenance_run_opts *opts,
> return 0;
> }
>
> +static int maintenance_task_odb(struct maintenance_run_opts *opts,
> + struct gc_config *cfg,
> + struct strvec *repack_args)
> +{
> + struct child_process repack_cmd = CHILD_PROCESS_INIT;
> + int ret;
> +
> + if (the_repository->repository_format_precious_objects)
> + return 0;
> +
> + repack_cmd.git_cmd = 1;
> + repack_cmd.odb_to_close = the_repository->objects;
> + strvec_pushv(&repack_cmd.args, repack_args->v);
> + if (run_command(&repack_cmd)) {
> + ret = error(FAILED_RUN, repack_args->v[0]);
> + goto out;
> + }
> +
> + if (cfg->prune_expire) {
> + struct child_process prune_cmd = CHILD_PROCESS_INIT;
> +
> + strvec_pushl(&prune_cmd.args, "prune", "--expire", NULL);
> + /* run `git prune` even if using cruft packs */
> + strvec_push(&prune_cmd.args, cfg->prune_expire);
> + if (opts->quiet)
> + strvec_push(&prune_cmd.args, "--no-progress");
> + if (repo_has_promisor_remote(the_repository))
> + strvec_push(&prune_cmd.args,
> + "--exclude-promisor-objects");
> + prune_cmd.git_cmd = 1;
> +
> + if (run_command(&prune_cmd)) {
> + ret = error(FAILED_RUN, prune_cmd.args.v[0]);
> + goto out;
> + }
> + }
> +
> + if (opts->auto_flag && too_many_loose_objects(cfg->gc_auto_threshold))
> + warning(_("There are too many unreachable loose objects; "
> + "run 'git prune' to remove them."));
> +
> + ret = 0;
> +
> +out:
> + return ret;
> +}
> +
> int cmd_gc(int argc,
> const char **argv,
> const char *prefix,
> @@ -1018,32 +1065,8 @@ int cmd_gc(int argc,
> 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;
> -
> - repack_cmd.git_cmd = 1;
> - repack_cmd.odb_to_close = the_repository->objects;
> - strvec_pushv(&repack_cmd.args, repack_args.v);
> - if (run_command(&repack_cmd))
> - die(FAILED_RUN, repack_args.v[0]);
> -
> - if (cfg.prune_expire) {
> - struct child_process prune_cmd = CHILD_PROCESS_INIT;
> -
> - strvec_pushl(&prune_cmd.args, "prune", "--expire", NULL);
> - /* run `git prune` even if using cruft packs */
> - strvec_push(&prune_cmd.args, cfg.prune_expire);
> - if (opts.quiet)
> - strvec_push(&prune_cmd.args, "--no-progress");
> - if (repo_has_promisor_remote(the_repository))
> - strvec_push(&prune_cmd.args,
> - "--exclude-promisor-objects");
> - prune_cmd.git_cmd = 1;
> -
> - if (run_command(&prune_cmd))
> - die(FAILED_RUN, prune_cmd.args.v[0]);
> - }
> - }
> + if (maintenance_task_odb(&opts, &cfg, &repack_args))
> + die(NULL);
Instead of giving the "fatal:" message here from this function, the
new code lets the helper function issue an "error:", so we do not
want to say an extra "fatal:" from die(), so this die(NULL) may be a
good thing to do.
next prev parent reply other threads:[~2026-07-07 20:30 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 15:32 [PATCH 00/11] odb: make optimizations pluggable Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 01/11] odb: run "pre-auto-gc" hook for all maintenance tasks Patrick Steinhardt
2026-07-07 19:55 ` Junio C Hamano
2026-07-08 7:55 ` Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 02/11] builtin/gc: move worktree and rerere tasks before object optimizations Patrick Steinhardt
2026-07-07 20:27 ` Junio C Hamano
2026-07-07 15:32 ` [PATCH 03/11] builtin/gc: extract object database optimizations into separate function Patrick Steinhardt
2026-07-07 20:30 ` Junio C Hamano [this message]
2026-07-07 15:32 ` [PATCH 04/11] builtin/gc: make repack arguments self-contained Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 05/11] builtin/gc: inline config values specific to the "files" backend Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 06/11] builtin/gc: introduce object database optimization options Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 07/11] builtin/gc: move geometric repacking into `odb_optimize()` Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 08/11] builtin/gc: introduce `odb_optimize_required()` Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 09/11] builtin/gc: refactor ODB optimizations to operate on "files" source Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 10/11] builtin/gc: fix signedness issues in ODB-related functionality Patrick Steinhardt
2026-07-07 15:32 ` [PATCH 11/11] odb: make optimizations pluggable Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 00/12] " Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 01/12] t7900: simplify how we check for maintenance tasks Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 02/12] odb: run "pre-auto-gc" hook for all " Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 03/12] builtin/gc: move worktree and rerere tasks before object optimizations Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 04/12] builtin/gc: extract object database optimizations into separate function Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 05/12] builtin/gc: make repack arguments self-contained Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 06/12] builtin/gc: inline config values specific to the "files" backend Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 07/12] builtin/gc: introduce object database optimization options Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 08/12] builtin/gc: move geometric repacking into `odb_optimize()` Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 09/12] builtin/gc: introduce `odb_optimize_required()` Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 10/12] builtin/gc: refactor ODB optimizations to operate on "files" source Patrick Steinhardt
2026-07-13 5:52 ` [PATCH v2 11/12] builtin/gc: fix signedness issues in ODB-related functionality Patrick Steinhardt
2026-07-13 16:28 ` Junio C Hamano
2026-07-13 5:52 ` [PATCH v2 12/12] odb: make optimizations pluggable Patrick Steinhardt
2026-07-13 16:34 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq7bn61r1u.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox