git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 04/75] parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 27, 2018, 16:25 UTC
Message-ID
<20181227162536.15895-5-pclouds@gmail.com>
In-Reply-To
<20181227162536.15895-1-pclouds@gmail.com>

parse-options can unambiguously find an abbreviation only if it sees all available options. This is usually the case when you use parse_options(). But there are other callers like blame or shortlog which uses parse_options_start() in combination with a custom option parser, like rev-list. parse-options cannot see all options in this case and will get abbrev detection wrong. Disable it.

t7800 needs update because --symlink no longer expands to --symlinks and will be passed down to git-diff, which will not recognize it. I still think this is the correct thing to do. But if --symlink has been actually used in the wild, we would just add an option alias for it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c     | 3 ++-
 t/t7800-difftool.sh | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 4cbcefc262..81e66b9374 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -265,7 +265,8 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
 		}
 		if (!rest) {
 			/* abbreviated? */
-			if (!strncmp(long_name, arg, arg_end - arg)) {
+			if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&
+			    !strncmp(long_name, arg, arg_end - arg)) {
 is_abbreviated:
 				if (abbrev_option) {
 					/*
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 22b9199d59..bb9a7f4ff9 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -546,7 +546,7 @@ do
 done >actual
 EOF
 
-test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
+test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '
 	cat >expect <<-EOF &&
 	file
 	$PWD/file
@@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha
 	sub/sub
 	$PWD/sub/sub
 	EOF
-	git difftool --dir-diff --symlink \
+	git difftool --dir-diff --symlinks \
 		--extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
 	test_cmp expect actual
 '
-- 
2.20.0.482.g66447595a7
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 4 of 18 in “Convert diff opt parser to parse_options()”
  1. 00/75 Convert diff opt parser to parse_options()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  2. 01/75 parse-options.h: remove extern on function prototypesNguyễn Thái Ngọc Duy, Dec 27, 2018
  3. 02/75 parse-options: add one-shot modeNguyễn Thái Ngọc Duy, Dec 27, 2018
  4. 04/75 parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWNNguyễn Thái Ngọc Duy, Dec 27, 2018
  5. 03/75 parse-options: allow keep-unknown + stop-at-non-opt combinationNguyễn Thái Ngọc Duy, Dec 27, 2018
  6. 05/75 parse-options: add OPT_BITOP()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  7. 07/75 parse-options: avoid magic return codesNguyễn Thái Ngọc Duy, Dec 27, 2018
  8. 06/75 parse-options: stop abusing 'callback' for lowlevel callbacksNguyễn Thái Ngọc Duy, Dec 27, 2018
  9. 08/75 parse-options: allow ll_callback with OPTION_CALLBACKNguyễn Thái Ngọc Duy, Dec 27, 2018
  10. 11/75 diff.c: prepare to use parse_options() for parsingNguyễn Thái Ngọc Duy, Dec 27, 2018
  11. 74/75 diff --no-index: use parse_options() instead of diff_opt_parse()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  12. Eric SunshineDec 27, 2018
  13. 10/75 diff.h: avoid bit fields in struct diff_flagsNguyễn Thái Ngọc Duy, Dec 27, 2018
  14. Stefan BellerJan 9, 2019
  15. 75/75 am: avoid diff_opt_parse()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  16. 73/75 range-diff: use parse_options() instead of diff_opt_parse()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  17. 09/75 diff.h: keep forward struct declarations sortedNguyễn Thái Ngọc Duy, Dec 27, 2018
  18. 12/75 diff.c: convert -u|-p|--patchNguyễn Thái Ngọc Duy, Dec 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.