MCPcopy Create free account
hub / github.com/git/git / prune_worktrees

Function prune_worktrees

builtin/worktree.c:212–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212static void prune_worktrees(void)
213{
214 struct strbuf reason = STRBUF_INIT;
215 struct strbuf main_path = STRBUF_INIT;
216 struct string_list kept = STRING_LIST_INIT_DUP;
217 char *path;
218 DIR *dir;
219 struct dirent *d;
220
221 path = repo_git_path(the_repository, "worktrees");
222 dir = opendir(path);
223 free(path);
224 if (!dir)
225 return;
226 while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) {
227 char *path;
228 strbuf_reset(&reason);
229 if (should_prune_worktree(d->d_name, &reason, &path, expire))
230 prune_worktree(d->d_name, reason.buf);
231 else if (path)
232 string_list_append_nodup(&kept, path)->util = xstrdup(d->d_name);
233 }
234 closedir(dir);
235
236 strbuf_add_absolute_path(&main_path, repo_get_common_dir(the_repository));
237 /* massage main worktree absolute path to match 'gitdir' content */
238 strbuf_strip_suffix(&main_path, "/.");
239 string_list_append_nodup(&kept, strbuf_detach(&main_path, NULL));
240 prune_dups(&kept);
241 string_list_clear(&kept, 1);
242
243 if (!show_only)
244 delete_worktrees_dir_if_empty();
245 strbuf_release(&reason);
246}
247
248static int prune(int ac, const char **av, const char *prefix,
249 struct repository *repo UNUSED)

Callers 1

pruneFunction · 0.85

Calls 15

repo_git_pathFunction · 0.85
opendirFunction · 0.85
should_prune_worktreeFunction · 0.85
prune_worktreeFunction · 0.85
string_list_append_nodupFunction · 0.85
xstrdupFunction · 0.85
closedirFunction · 0.85
strbuf_add_absolute_pathFunction · 0.85
repo_get_common_dirFunction · 0.85
strbuf_strip_suffixFunction · 0.85
strbuf_detachFunction · 0.85

Tested by

no test coverage detected