| 210 | } |
| 211 | |
| 212 | static 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 | |
| 248 | static int prune(int ac, const char **av, const char *prefix, |
| 249 | struct repository *repo UNUSED) |
no test coverage detected