@matheusbsbs / matheus-bagliano / commits / dd9609a12e
Fork 0

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>

Eric Sunshine committed Jun 10, 2020 at 02:30 UTC dd9609a12e83969be6536853b2846866dafdfc98
1 file changed +9 -6
builtin/worktree.c
+9 -6
@@ -133,6 +133,14 @@ static int should_prune_worktree(const char *id, struct strbuf *reason)
133 return 0;
134 }
135
136 +static void prune_worktree(const char *id, const char *reason)
137 +{
138 + if (show_only || verbose)
139 + printf_ln(_("Removing %s/%s: %s"), "worktrees", id, reason);
140 + if (!show_only)
141 + delete_git_dir(id);
142 +}
143 +
144 static void prune_worktrees(void)
145 {
146 struct strbuf reason = STRBUF_INIT;
@@ -146,12 +154,7 @@ static void prune_worktrees(void)
154 strbuf_reset(&reason);
155 if (!should_prune_worktree(d->d_name, &reason))
156 continue;
149 - if (show_only || verbose)
150 - printf_ln(_("Removing %s/%s: %s"),
151 - "worktrees", d->d_name, reason.buf);
152 - if (show_only)
153 - continue;
154 - delete_git_dir(d->d_name);
157 + prune_worktree(d->d_name, reason.buf);
158 }
159 closedir(dir);
160 if (!show_only)