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

[PATCH v2 3/7] worktree: make high-level pruning re-usable

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 10, 2020, 06:30 UTC
Message-ID
<20200610063049.74666-4-sunshine@sunshineco.com>
In-Reply-To
<20200610063049.74666-1-sunshine@sunshineco.com>

The low-level logic for removing a worktree is well encapsulated in delete_git_dir(). However, high-level details related to pruning a worktree -- such as dealing with verbosity and dry-run mode -- are not encapsulated. Factor out this high-level logic into its own function so it can be re-used as new worktree corruption detectors are added.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 builtin/worktree.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 35d38607e7..706ac68751 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -133,6 +133,14 @@ static int should_prune_worktree(const char *id, struct strbuf *reason)
 	return 0;
 }
 
+static void prune_worktree(const char *id, const char *reason)
+{
+	if (show_only || verbose)
+		printf_ln(_("Removing %s/%s: %s"), "worktrees", id, reason);
+	if (!show_only)
+		delete_git_dir(id);
+}
+
 static void prune_worktrees(void)
 {
 	struct strbuf reason = STRBUF_INIT;
@@ -146,12 +154,7 @@ static void prune_worktrees(void)
 		strbuf_reset(&reason);
 		if (!should_prune_worktree(d->d_name, &reason))
 			continue;
-		if (show_only || verbose)
-			printf_ln(_("Removing %s/%s: %s"),
-				  "worktrees", d->d_name, reason.buf);
-		if (show_only)
-			continue;
-		delete_git_dir(d->d_name);
+		prune_worktree(d->d_name, reason.buf);
 	}
 	closedir(dir);
 	if (!show_only)
-- 
2.27.0.90.gabb59f83a2
Previous: Eric SunshineNext: Eric Sunshine
Message 7 of 13 in “worktree: tighten duplicate path detection”
  1. 0/7 worktree: tighten duplicate path detectionEric Sunshine, Jun 10, 2020
  2. 1/7 worktree: factor out repeated string literalEric Sunshine, Jun 10, 2020
  3. 2/7 worktree: give "should be pruned?" function more meaningful nameEric Sunshine, Jun 10, 2020
  4. 6/7 worktree: generalize candidate worktree path validationEric Sunshine, Jun 10, 2020
  5. Shourya ShuklaJun 10, 2020
  6. Eric SunshineJun 10, 2020
  7. 3/7 worktree: make high-level pruning re-usableEric Sunshine, Jun 10, 2020
  8. 5/7 worktree: prune linked worktree referencing main worktree pathEric Sunshine, Jun 10, 2020
  9. 7/7 worktree: make "move" refuse to move atop missing registered worktreeEric Sunshine, Jun 10, 2020
  10. 4/7 worktree: prune duplicate entries referencing same worktree pathEric Sunshine, Jun 10, 2020
  11. Shourya ShuklaJun 10, 2020
  12. Eric SunshineJun 10, 2020
  13. Junio C HamanoJun 10, 2020

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.