* NEEDSWORK: This function exists so that we can look up metadata of a * worktree without trying to access any of its internals like the refdb. It * would be preferable to instead have a corruption-tolerant function for * retrieving worktree metadata that could be used when the worktree is known * to not be in a healthy state, e.g. when creating or repairing it. */
| 183 | * to not be in a healthy state, e.g. when creating or repairing it. |
| 184 | */ |
| 185 | static struct worktree **get_worktrees_internal(int skip_reading_head) |
| 186 | { |
| 187 | struct worktree **list = NULL; |
| 188 | struct strbuf path = STRBUF_INIT; |
| 189 | DIR *dir; |
| 190 | struct dirent *d; |
| 191 | int counter = 0, alloc = 2; |
| 192 | |
| 193 | ALLOC_ARRAY(list, alloc); |
| 194 | |
| 195 | list[counter++] = get_main_worktree(skip_reading_head); |
| 196 | |
| 197 | strbuf_addf(&path, "%s/worktrees", repo_get_common_dir(the_repository)); |
| 198 | dir = opendir(path.buf); |
| 199 | strbuf_release(&path); |
| 200 | if (dir) { |
| 201 | while ((d = readdir_skip_dot_and_dotdot(dir)) != NULL) { |
| 202 | struct worktree *linked = NULL; |
| 203 | |
| 204 | if ((linked = get_linked_worktree(d->d_name, skip_reading_head))) { |
| 205 | ALLOC_GROW(list, counter + 1, alloc); |
| 206 | list[counter++] = linked; |
| 207 | } |
| 208 | } |
| 209 | closedir(dir); |
| 210 | } |
| 211 | ALLOC_GROW(list, counter + 1, alloc); |
| 212 | list[counter] = NULL; |
| 213 | |
| 214 | return list; |
| 215 | } |
| 216 | |
| 217 | struct worktree **get_worktrees(void) |
| 218 | { |
no test coverage detected