git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ls-tree: fix --no-full-name
@ 2023-07-18 15:44 René Scharfe
  2023-07-18 16:37 ` Junio C Hamano
  0 siblings, 1 reply; 66+ messages in thread
From: René Scharfe @ 2023-07-18 15:44 UTC (permalink / raw)
  To: Git List

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>
---
 builtin/ls-tree.c          | 7 +++----
 t/t3101-ls-tree-dirname.sh | 8 ++++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 53073d64cb..f558db5f3b 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -343,7 +343,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
 	struct object_id oid;
 	struct tree *tree;
 	int i, full_tree = 0;
-	int chomp_prefix = prefix && *prefix;
+	int full_name = !prefix || !*prefix;
 	read_tree_fn_t fn = NULL;
 	enum ls_tree_cmdmode cmdmode = MODE_DEFAULT;
 	int null_termination = 0;
@@ -365,8 +365,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
 			    MODE_NAME_STATUS),
 		OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
 			    MODE_OBJECT_ONLY),
-		OPT_SET_INT(0, "full-name", &chomp_prefix,
-			    N_("use full path names"), 0),
+		OPT_BOOL(0, "full-name", &full_name, N_("use full path names")),
 		OPT_BOOL(0, "full-tree", &full_tree,
 			 N_("list entire tree; not just current directory "
 			    "(implies --full-name)")),
@@ -387,7 +386,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)

 	if (full_tree)
 		prefix = NULL;
-	options.prefix = chomp_prefix ? prefix : NULL;
+	options.prefix = full_name ? NULL : prefix;

 	/*
 	 * We wanted to detect conflicts between --name-only and
diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh
index 217006d1bf..5af2dac0e4 100755
--- a/t/t3101-ls-tree-dirname.sh
+++ b/t/t3101-ls-tree-dirname.sh
@@ -154,6 +154,14 @@ EOF
 	test_output
 '

+test_expect_success 'ls-tree --no-full-name' '
+	git -C path0 ls-tree --no-full-name $tree a >current &&
+	cat >expected <<-EOF &&
+	040000 tree X	a
+	EOF
+	test_output
+'
+
 test_expect_success 'ls-tree --full-tree' '
 	(
 		cd path1/b/c &&
--
2.41.0

^ permalink raw reply related	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2023-08-12  5:11 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 15:44 [PATCH] ls-tree: fix --no-full-name René Scharfe
2023-07-18 16:37 ` Junio C Hamano
2023-07-18 20:49   ` Junio C Hamano
2023-07-21 12:41     ` René Scharfe
2023-07-21 12:41   ` René Scharfe
2023-07-21 14:37     ` Junio C Hamano
2023-07-21 19:29       ` René Scharfe
2023-07-21 20:09         ` Junio C Hamano
2023-07-21 20:14           ` Junio C Hamano
2023-07-24 12:29           ` René Scharfe
2023-07-24 18:51             ` Junio C Hamano
2023-07-24 20:09               ` René Scharfe
2023-07-24 20:50                 ` Junio C Hamano
2023-07-28  6:12                   ` René Scharfe
2023-07-28  9:45                     ` Phillip Wood
2023-07-29 20:40                       ` René Scharfe
2023-07-31 15:31                         ` Junio C Hamano
2023-08-04 16:40                           ` Junio C Hamano
2023-08-04 19:48                             ` Phillip Wood
2023-08-05 10:40                               ` René Scharfe
2023-07-24 12:29           ` [PATCH v2 0/5] show negatability of options in short help René Scharfe
2023-07-24 12:34             ` [PATCH v2 1/5] subtree: disallow --no-{help,quiet,debug,branch,message} René Scharfe
2023-07-24 12:36             ` [PATCH v2 2/5] t1502, docs: disallow --no-help René Scharfe
2023-07-24 12:38             ` [PATCH v2 3/5] t1502: move optionspec help output to a file René Scharfe
2023-07-24 12:39             ` [PATCH v2 4/5] t1502: test option negation René Scharfe
2023-07-24 12:40             ` [PATCH v2 5/5] parse-options: show negatability of options in short help René Scharfe
2023-08-05 14:33           ` [PATCH v3 0/8] " René Scharfe
2023-08-05 14:37             ` [PATCH v3 1/8] subtree: disallow --no-{help,quiet,debug,branch,message} René Scharfe
2023-08-05 14:37             ` [PATCH v3 2/8] t1502, docs: disallow --no-help René Scharfe
2023-08-05 14:38             ` [PATCH v3 3/8] t1502: move optionspec help output to a file René Scharfe
2023-08-05 14:39             ` [PATCH v3 4/8] t1502: test option negation René Scharfe
2023-08-05 14:40             ` [PATCH v3 5/8] parse-options: show negatability of options in short help René Scharfe
2023-08-05 14:43             ` [PATCH v3 6/8] parse-options: factor out usage_indent() and usage_padding() René Scharfe
2023-08-05 14:44             ` [PATCH v3 7/8] parse-options: no --[no-]no- René Scharfe
2023-08-05 14:52             ` [PATCH v3 8/8] parse-options: simplify usage_padding() René Scharfe
2023-08-05 23:04               ` Junio C Hamano
2023-07-21 12:41   ` [PATCH] show-branch: fix --no-sparse René Scharfe
2023-07-21 14:42     ` Junio C Hamano
2023-07-21 16:30       ` René Scharfe
2023-07-21 12:41   ` [PATCH] show-branch: disallow --no-{date,topo}-order René Scharfe
2023-07-21 12:41   ` [PATCH] reset: disallow --no-{mixed,soft,hard,merge,keep} René Scharfe
2023-07-21 12:41   ` [PATCH] pack-objects: fix --no-quiet René Scharfe
2023-07-21 12:41   ` [PATCH] pack-objects: fix --no-keep-true-parents René Scharfe
2023-07-21 17:03     ` Junio C Hamano
2023-07-21 12:42   ` [PATCH] branch: disallow --no-{all,remotes} René Scharfe
2023-07-21 12:42   ` [PATCH] am: unify definition of --keep-cr and --no-keep-cr René Scharfe
2023-07-21 13:41   ` [PATCH] describe: fix --no-exact-match René Scharfe
2023-07-21 14:10     ` Junio C Hamano
2023-07-21 17:00     ` Junio C Hamano
2023-08-08 21:27     ` Jeff King
2023-08-08 21:28       ` Jeff King
2023-08-09  1:43       ` Junio C Hamano
2023-08-09 14:09         ` Jeff King
2023-08-09 16:41           ` René Scharfe
2023-08-09 19:07             ` Junio C Hamano
2023-08-10  0:26               ` Jeff King
2023-08-10  1:00                 ` Junio C Hamano
2023-08-10 19:45                   ` René Scharfe
2023-08-10  0:41             ` Jeff King
2023-08-10 19:10               ` René Scharfe
2023-08-11 15:11                 ` Jeff King
2023-08-11 17:59                   ` René Scharfe
2023-08-11 18:24                     ` Jeff King
2023-08-12  5:11                       ` René Scharfe
2023-08-11 15:13                 ` Jeff King
2023-08-11 17:59                   ` René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).