Re: [PATCH v4 5/7] builtin/maintenance: introduce "worktree-prune" task
- From
Christian Couder <christian.couder@gmail.com>
- Date
- May 6, 2025, 07:40 UTC
- Message-ID
- <CAP8UFD2cuMxdpGFuBoKirw2mko6gt-djndqqZy92NypPiiFCYQ@mail.gmail.com>
- In-Reply-To
- <20250505-pks-maintenance-missing-tasks-v4-5-141f4df906a1@pks.im>
On Mon, May 5, 2025 at 10:52 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 28 quoted lines
> +static int worktree_prune_condition(struct gc_config *cfg)
> +{
> + struct strvec worktrees = STRVEC_INIT;
> + struct strbuf reason = STRBUF_INIT;
> + timestamp_t expiry_date;
> + int should_prune = 0;
> + int limit = 1;
> +
> + git_config_get_int("maintenance.worktree-prune.auto", &limit);
> + if (limit <= 0) {
> + should_prune = limit < 0;
> + goto out;
> + }
> +
> + if (parse_expiry_date(cfg->prune_worktrees_expire, &expiry_date) ||
> + get_worktree_names(the_repository, &worktrees) < 0)
> + goto out;
> +
> + for (size_t i = 0; i < worktrees.nr; i++) {
> + char *wtpath;
> +
> + strbuf_reset(&reason);
> + if (should_prune_worktree(worktrees.v[i], &reason, &wtpath, expiry_date)) {
> + limit--;
> +
> + if (!limit) {
> + should_prune = 1;
> + goto out;Eric noticed in a previous round that wtpath is leaked in this `goto out` path, and it seems to me that it's still the case.
Show 10 quoted lines
> + } > + } > + free(wtpath); > + } > + > +out: > + strvec_clear(&worktrees); > + strbuf_release(&reason); > + return should_prune; > +}