ls-tree: fix --no-full-name

Since 61fdbcf98b (ls-tree: migrate to parse-options, 2009-11-13) git ls-tree has accepted the option --no-full-name, but it does the same as --full-name, contrary to convention. That's because it's defined using OPT_SET_INT with a value of 0, where the negative variant sets 0 as well. Turn --no-full-name into the opposite of --full-name by using OPT_BOOL instead and storing the option's status directly in a variable named "full_name" instead of in negated form in "chomp_prefix". Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 18, 2023 at 17:44 UTC 991c552916d3c8fa464acfca135b4235e11792bf
2 files changed +11 -4
builtin/ls-tree.c
+3 -4
@@ -343,7 +343,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
343 struct object_id oid;
344 struct tree *tree;
345 int i, full_tree = 0;
346 - int chomp_prefix = prefix && *prefix;
346 + int full_name = !prefix || !*prefix;
347 read_tree_fn_t fn = NULL;
348 enum ls_tree_cmdmode cmdmode = MODE_DEFAULT;
349 int null_termination = 0;
@@ -365,8 +365,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
365 MODE_NAME_STATUS),
366 OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
367 MODE_OBJECT_ONLY),
368 - OPT_SET_INT(0, "full-name", &chomp_prefix,
369 - N_("use full path names"), 0),
368 + OPT_BOOL(0, "full-name", &full_name, N_("use full path names")),
369 OPT_BOOL(0, "full-tree", &full_tree,
370 N_("list entire tree; not just current directory "
371 "(implies --full-name)")),
@@ -387,7 +386,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
386
387 if (full_tree)
388 prefix = NULL;
390 - options.prefix = chomp_prefix ? prefix : NULL;
389 + options.prefix = full_name ? NULL : prefix;
390
391 /*
392 * We wanted to detect conflicts between --name-only and
t/t3101-ls-tree-dirname.sh
+8
@@ -154,6 +154,14 @@ EOF
154 test_output
155 '
156
157 +test_expect_success 'ls-tree --no-full-name' '
158 + git -C path0 ls-tree --no-full-name $tree a >current &&
159 + cat >expected <<-EOF &&
160 + 040000 tree X a
161 + EOF
162 + test_output
163 +'
164 +
165 test_expect_success 'ls-tree --full-tree' '
166 (
167 cd path1/b/c &&