Re: [PATCH v4 5/7] builtin/maintenance: introduce "worktree-prune" task
From: Christian Couder <hidden>
Date: 2025-05-06 07:41:09
On Mon, May 5, 2025 at 10:52 AM Patrick Steinhardt [off-list ref] wrote:
+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.
+ } + } + free(wtpath); + } + +out: + strvec_clear(&worktrees); + strbuf_release(&reason); + return should_prune; +}