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()
This commit is contained in:
Junio C Hamano 2020-08-10 10:23:58 -07:00
commit 197253ed32

View file

@ -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);