git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/8] builtin/gc: move pruning of worktrees into a separate function

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 30, 2025, 10:25 UTC
Message-ID
<20250430-pks-maintenance-missing-tasks-v2-3-2580b7b8ca3a@pks.im>
In-Reply-To
<20250430-pks-maintenance-missing-tasks-v2-0-2580b7b8ca3a@pks.im>

Move pruning of worktrees into a separate function. This prepares for a subsequent commit where we introduce a new "worktree-prune" task for git-maintenance(1).

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/gc.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index ada36e210f0..005ecc3f192 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -334,6 +334,18 @@ static int maintenance_task_reflog_expire(struct maintenance_run_opts *opts UNUS
 	return run_command(&cmd);
 }
 
+static int maintenance_task_worktree_prune(struct maintenance_run_opts *opts UNUSED,
+					   struct gc_config *cfg)
+{
+	struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
+
+	prune_worktrees_cmd.git_cmd = 1;
+	strvec_pushl(&prune_worktrees_cmd.args, "worktree", "prune", "--expire", NULL);
+	strvec_push(&prune_worktrees_cmd.args, cfg->prune_worktrees_expire);
+
+	return run_command(&prune_worktrees_cmd);
+}
+
 static int too_many_loose_objects(struct gc_config *cfg)
 {
 	/*
@@ -903,16 +915,9 @@ int cmd_gc(int argc,
 		}
 	}
 
-	if (cfg.prune_worktrees_expire) {
-		struct child_process prune_worktrees_cmd = CHILD_PROCESS_INIT;
-
-		prune_worktrees_cmd.git_cmd = 1;
-		strvec_pushl(&prune_worktrees_cmd.args, "worktree", "prune", "--expire", NULL);
-		strvec_push(&prune_worktrees_cmd.args, cfg.prune_worktrees_expire);
-
-		if (run_command(&prune_worktrees_cmd))
-			die(FAILED_RUN, prune_worktrees_cmd.args.v[0]);
-	}
+	if (cfg.prune_worktrees_expire &&
+	    maintenance_task_worktree_prune(&opts, &cfg))
+		die(FAILED_RUN, "worktree");
 
 	rerere_cmd.git_cmd = 1;
 	strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
-- 
2.49.0.987.g0cc8ee98dc.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 4 of 14 in “builtin/maintenance: implement missing tasks compared to git-gc(1)”
  1. 0/8 builtin/maintenance: implement missing tasks compared to git-gc(1)Patrick Steinhardt, Apr 30, 2025
  2. 1/8 builtin/gc: fix indentation of `cmd_gc()` parametersPatrick Steinhardt, Apr 30, 2025
  3. 2/8 builtin/gc: remove global variables where it trivial to doPatrick Steinhardt, Apr 30, 2025
  4. 3/8 builtin/gc: move pruning of worktrees into a separate functionPatrick Steinhardt, Apr 30, 2025
  5. 4/8 worktree: expose function to retrieve worktree namesPatrick Steinhardt, Apr 30, 2025
  6. 5/8 builtin/maintenance: introduce "worktree-prune" taskPatrick Steinhardt, Apr 30, 2025
  7. 6/8 rerere: provide function to collect stale entriesPatrick Steinhardt, Apr 30, 2025
  8. Junio C HamanoApr 30, 2025
  9. Patrick SteinhardtMay 2, 2025
  10. Junio C HamanoMay 2, 2025
  11. Patrick SteinhardtMay 5, 2025
  12. 7/8 builtin/gc: move rerere garbage collection into separate functionPatrick Steinhardt, Apr 30, 2025
  13. 8/8 builtin/maintenance: introduce "rerere-gc" taskPatrick Steinhardt, Apr 30, 2025
  14. Derrick StoleeApr 30, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.