From: Patrick Steinhardt <ps@pks.im>
To: Shubham Kanodia via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Shubham Kanodia <shubham.kanodia10@gmail.com>
Subject: Re: [PATCH v2] maintenance: add prune-remote-refs task
Date: Mon, 30 Dec 2024 08:15:55 +0100 [thread overview]
Message-ID: <Z3JIpDQTDrQuoEN2@pks.im> (raw)
In-Reply-To: <pull.1838.v2.git.1735380461980.gitgitgadget@gmail.com>
On Sat, Dec 28, 2024 at 10:07:41AM +0000, Shubham Kanodia via GitGitGadget wrote:
> diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt
> index 6e6651309d3..8b3e496c8ef 100644
> --- a/Documentation/git-maintenance.txt
> +++ b/Documentation/git-maintenance.txt
> @@ -158,6 +158,26 @@ pack-refs::
> need to iterate across many references. See linkgit:git-pack-refs[1]
> for more information.
>
> +prune-remote-refs::
> + The `prune-remote-refs` task runs `git remote prune` on each remote
> + repository registered in the local repository. This task helps clean
> + up deleted remote branches, improving the performance of operations
> + that iterate through the refs. See linkgit:git-remote[1] for more
> + information. This task is disabled by default.
> ++
> +NOTE: This task is opt-in to prevent unexpected removal of remote refs
> +for users of git-maintenance. For most users, configuring `fetch.prune=true`
Do we want to make this linkgit:git-maintenance[1] even though this is
self-referential?
> +is a acceptable solution, as it will automatically clean up stale remote-tracking
> +branches during normal fetch operations. However, this task can be useful in
> +specific scenarios:
> ++
> +--
> +* When using selective fetching (e.g., `git fetch origin +foo:refs/remotes/origin/foo`)
> + where `fetch.prune` would only affect refs that are explicitly fetched.
> +* When third-party tools might perform unexpected full fetches, and you want
> + periodic cleanup independently of fetch operations.
> +--
Nicely explained. I wish we had more such documentation that is taking
the user by their hand and explains why they may or may not want to have
a specific thing.
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 4ae5196aedf..329c764f300 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -20,6 +20,7 @@
> #include "lockfile.h"
> #include "parse-options.h"
> #include "run-command.h"
> +#include "remote.h"
> #include "sigchain.h"
> #include "strvec.h"
> #include "commit.h"
> @@ -913,6 +914,30 @@ static int maintenance_opt_schedule(const struct option *opt, const char *arg,
> return 0;
> }
>
> +static int prune_remote(struct remote *remote, void *cb_data UNUSED)
> +{
> + struct child_process child = CHILD_PROCESS_INIT;
> +
> + if (!remote->url.nr)
> + return 0;
> +
> + child.git_cmd = 1;
> + strvec_pushl(&child.args, "remote", "prune", remote->name, NULL);
> +
> + return !!run_command(&child);
> +}
> +
> +static int maintenance_task_prune_remote(struct maintenance_run_opts *opts,
> + struct gc_config *cfg UNUSED)
> +{
> + if (for_each_remote(prune_remote, opts)) {
> + error(_("failed to prune remotes"));
> + return 1;
I wonder whether we should adapt the loop to be eager. Erroring out on
the first failed remote would potentially mean that none of the other
remotes may get pruned. So if you had a now-unreachable remote as first
remote then none of your remotes would be pruned.
If so, we may want to collect the names of failed remotes and print
them, as well.
Patrick
next prev parent reply other threads:[~2024-12-30 7:16 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-23 9:36 [PATCH] maintenance: add prune-remote-refs task Shubham Kanodia via GitGitGadget
2024-12-27 9:07 ` Junio C Hamano
2024-12-28 9:58 ` Shubham Kanodia
2024-12-28 16:05 ` Junio C Hamano
2024-12-28 16:24 ` Shubham Kanodia
2024-12-28 10:07 ` [PATCH v2] " Shubham Kanodia via GitGitGadget
2024-12-28 16:25 ` Junio C Hamano
2024-12-30 7:15 ` Patrick Steinhardt [this message]
2024-12-30 14:05 ` Junio C Hamano
2025-01-03 6:50 ` Shubham Kanodia
2025-01-03 7:38 ` Patrick Steinhardt
2025-01-03 18:13 ` [PATCH v3] " Shubham Kanodia via GitGitGadget
2025-01-03 19:02 ` Junio C Hamano
[not found] ` <CAG=Um+1ch1sKC0H8MJoFv=6iSK3pvA=03AKXmvhm5DG=H8T1rw@mail.gmail.com>
2025-01-07 17:29 ` Shubham Kanodia
2025-01-07 18:48 ` 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=Z3JIpDQTDrQuoEN2@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=shubham.kanodia10@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).