Skip to content

Commit 197253e

Browse files
committed
Merge branch 'es/worktree-cleanup'
Code cleanup around "worktree" API implementation. * es/worktree-cleanup: worktree: retire special-case normalization of main worktree path worktree: drop bogus and unnecessary path munging worktree: drop unused code from get_linked_worktree() worktree: drop pointless strbuf_release()
2 parents 46b225f + 918d8ff commit 197253e

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

worktree.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ static struct worktree *get_main_worktree(void)
4949
struct worktree *worktree = NULL;
5050
struct strbuf worktree_path = STRBUF_INIT;
5151

52-
strbuf_add_absolute_path(&worktree_path, get_git_common_dir());
53-
if (!strbuf_strip_suffix(&worktree_path, "/.git/.") && /* in .git */
54-
!strbuf_strip_suffix(&worktree_path, "/.git")) /* in worktree */
55-
strbuf_strip_suffix(&worktree_path, "/."); /* in bare repo */
52+
strbuf_add_real_path(&worktree_path, get_git_common_dir());
53+
strbuf_strip_suffix(&worktree_path, "/.git");
5654

5755
worktree = xcalloc(1, sizeof(*worktree));
5856
worktree->path = strbuf_detach(&worktree_path, NULL);
@@ -66,8 +64,6 @@ static struct worktree *get_main_worktree(void)
6664
worktree->is_bare = (is_bare_repository_cfg == 1) ||
6765
is_bare_repository();
6866
add_head_info(worktree);
69-
70-
strbuf_release(&worktree_path);
7167
return worktree;
7268
}
7369

@@ -84,16 +80,8 @@ static struct worktree *get_linked_worktree(const char *id)
8480
if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
8581
/* invalid gitdir file */
8682
goto done;
87-
8883
strbuf_rtrim(&worktree_path);
89-
if (!strbuf_strip_suffix(&worktree_path, "/.git")) {
90-
strbuf_reset(&worktree_path);
91-
strbuf_add_absolute_path(&worktree_path, ".");
92-
strbuf_strip_suffix(&worktree_path, "/.");
93-
}
94-
95-
strbuf_reset(&path);
96-
strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id);
84+
strbuf_strip_suffix(&worktree_path, "/.git");
9785

9886
worktree = xcalloc(1, sizeof(*worktree));
9987
worktree->path = strbuf_detach(&worktree_path, NULL);

0 commit comments

Comments
 (0)