ls-tree: simplify prefix handling
commit7b7203e78af7bfe431b9aadd7b726775ed442b3c
authorRené Scharfe <l.s.r@web.de>
Fri, 7 Jul 2023 18:34:31 +0000 (7 20:34 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jul 2023 18:57:13 +0000 (7 11:57 -0700)
treeee8b53f2a7c26461e77d6f5a9c6137b40e87cc94
parent061c58647eb4b3f0e2c898333577d4b2af115b1d
ls-tree: simplify prefix handling

git ls-tree has two prefixes: The one handed to cmd_ls_tree(), i.e. the
current subdirectory in the repository (if any) and the "display" prefix
used by the show_tree_*() functions.  The option --full-name clears the
last one, i.e. it shows full paths, and --full-tree clears both, i.e. it
acts as if the command was started in the root of the repository.

The show_tree_*() functions use the ls_tree_options members chomp_prefix
and ls_tree_prefix to determine their prefix values.  Calculate it once
in cmd_ls_tree() instead, once the main prefix value is finalized.

This allows chomp_prefix to become a local variable.  Stop using
strlen(3) to determine its initial value -- we only care whether we got
a non-empty string, not precisely how long it is.

Rename ls_tree_prefix to prefix to demonstrate that we converted all
users and because the ls_tree_ part is no longer necessary since
030a3d5d9e (ls-tree: use a "struct options", 2023-01-12) turned it from
a global variable to a struct member.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/ls-tree.c