summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2020-08-10 10:23:58 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-08-10 10:23:58 -0700
commit197253ed32040dda8354614312ef9b5687d7ccae (patch)
tree9faf2bfe9003e47242d0808d6e8060ffcddc08c0
parentMerge branch 'jk/strvec' (diff)
parentworktree: retire special-case normalization of main worktree path (diff)
downloadtgif-197253ed32040dda8354614312ef9b5687d7ccae.tar.xz
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()
-rw-r--r--worktree.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/worktree.c b/worktree.c
index cba2e54598..62217b4a6b 100644
--- a/worktree.c
+++ b/worktree.c
@@ -49,10 +49,8 @@ static struct worktree *get_main_worktree(void)
struct worktree *worktree = NULL;
struct strbuf worktree_path = STRBUF_INIT;
- strbuf_add_absolute_path(&worktree_path, get_git_common_dir());
- if (!strbuf_strip_suffix(&worktree_path, "/.git/.") && /* in .git */
- !strbuf_strip_suffix(&worktree_path, "/.git")) /* in worktree */
- strbuf_strip_suffix(&worktree_path, "/."); /* in bare repo */
+ strbuf_add_real_path(&worktree_path, get_git_common_dir());
+ strbuf_strip_suffix(&worktree_path, "/.git");
worktree = xcalloc(1, sizeof(*worktree));
worktree->path = strbuf_detach(&worktree_path, NULL);
@@ -66,8 +64,6 @@ static struct worktree *get_main_worktree(void)
worktree->is_bare = (is_bare_repository_cfg == 1) ||
is_bare_repository();
add_head_info(worktree);
-
- strbuf_release(&worktree_path);
return worktree;
}
@@ -84,16 +80,8 @@ static struct worktree *get_linked_worktree(const char *id)
if (strbuf_read_file(&worktree_path, path.buf, 0) <= 0)
/* invalid gitdir file */
goto done;
-
strbuf_rtrim(&worktree_path);
- if (!strbuf_strip_suffix(&worktree_path, "/.git")) {
- strbuf_reset(&worktree_path);
- strbuf_add_absolute_path(&worktree_path, ".");
- strbuf_strip_suffix(&worktree_path, "/.");
- }
-
- strbuf_reset(&path);
- strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id);
+ strbuf_strip_suffix(&worktree_path, "/.git");
worktree = xcalloc(1, sizeof(*worktree));
worktree->path = strbuf_detach(&worktree_path, NULL);