MCPcopy Index your code
hub / github.com/git/git / get_worktrees_internal

Function get_worktrees_internal

worktree.c:185–215  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

183 * to not be in a healthy state, e.g. when creating or repairing it.
184 */
185static 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
217struct worktree **get_worktrees(void)
218{

Callers 4

get_worktreesFunction · 0.85
repair_worktreesFunction · 0.85

Calls 8

get_main_worktreeFunction · 0.85
strbuf_addfFunction · 0.85
repo_get_common_dirFunction · 0.85
opendirFunction · 0.85
strbuf_releaseFunction · 0.85
get_linked_worktreeFunction · 0.85
closedirFunction · 0.85

Tested by

no test coverage detected