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

Function get_linked_worktree

worktree.c:141–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141struct worktree *get_linked_worktree(const char *id,
142 int skip_reading_head)
143{
144 struct worktree *worktree = NULL;
145 struct strbuf path = STRBUF_INIT;
146 struct strbuf worktree_path = STRBUF_INIT;
147
148 if (!id)
149 die("Missing linked worktree name");
150
151 repo_common_path_append(the_repository, &path, "worktrees/%s/gitdir", id);
152 if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
153 /* invalid gitdir file */
154 goto done;
155 strbuf_rtrim(&worktree_path);
156 strbuf_strip_suffix(&worktree_path, "/.git");
157
158 if (!is_absolute_path(worktree_path.buf)) {
159 strbuf_strip_suffix(&path, "gitdir");
160 strbuf_addbuf(&path, &worktree_path);
161 strbuf_realpath_forgiving(&worktree_path, path.buf, 0);
162 }
163
164 CALLOC_ARRAY(worktree, 1);
165 worktree->repo = the_repository;
166 worktree->path = strbuf_detach(&worktree_path, NULL);
167 worktree->id = xstrdup(id);
168 worktree->is_current = is_current_worktree(worktree);
169 if (!skip_reading_head)
170 add_head_info(worktree);
171
172done:
173 strbuf_release(&path);
174 strbuf_release(&worktree_path);
175 return worktree;
176}
177
178/*
179 * NEEDSWORK: This function exists so that we can look up metadata of a

Callers 2

get_worktrees_internalFunction · 0.85
add_worktreeFunction · 0.85

Calls 13

repo_common_path_appendFunction · 0.85
strbuf_read_fileFunction · 0.85
strbuf_rtrimFunction · 0.85
strbuf_strip_suffixFunction · 0.85
is_absolute_pathFunction · 0.85
strbuf_addbufFunction · 0.85
strbuf_detachFunction · 0.85
xstrdupFunction · 0.85
is_current_worktreeFunction · 0.85
add_head_infoFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected