Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2020-06-10 09:30:45 +0300
committerJunio C Hamano <gitster@pobox.com>2020-06-10 20:54:49 +0300
commitdd9609a12e83969be6536853b2846866dafdfc98 (patch)
treea38dbe4a27e2b78efcef19a21f3f381387f9848f /builtin/worktree.c
parent1b14d40b385580a366c92f8c2a9373e6fd7cb26f (diff)
worktree: make high-level pruning re-usable
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
-rw-r--r--builtin/worktree.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 0402f244ea..9284e490b9 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)