worktree: retire special-case normalization of main worktree path
commit918d8ff78099004c561e0da90fa04cd629bb3b0e
authorEric Sunshine <sunshine@sunshineco.com>
Fri, 31 Jul 2020 23:32:14 +0000 (31 19:32 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 1 Aug 2020 02:56:11 +0000 (31 19:56 -0700)
tree1eb7ffd89b012f449854530f30e1d22f2bbe9dd1
parent1c4854ec7333f412cd60a5b673bb4f4e43319391
worktree: retire special-case normalization of main worktree path

In order for "git-worktree list" to present consistent results,
get_main_worktree() performs manual normalization on the repository
path (returned by get_common_dir()) after passing it through
strbuf_add_absolute_path(). In particular, it cleans up the path for
three distinct cases when the current working directory is (1) the main
worktree, (2) the .git/ subdirectory, or (3) a bare repository.

The need for such special-cases is a direct consequence of employing
strbuf_add_absolute_path() which, for the sake of efficiency, doesn't
bother normalizing the path (such as folding out redundant path
components) after making it absolute. Lack of normalization is not
typically a problem since redundant path elements make no difference
when working with paths at the filesystem level. However, when preparing
paths for presentation, possible redundant path components make it
difficult to ensure consistency.

Eliminate the need for these special cases by instead making the path
absolute via strbuf_add_real_path() which normalizes the path for us.
Once normalized, the only case we need to handle manually is converting
it to the path of the main worktree by stripping the "/.git" suffix.
This stripping of the "/.git" suffix is a regular idiom in
worktree-related code; for instance, it is employed by
get_linked_worktree(), as well.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
worktree.c