parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWN

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 27, 2019 at 07:35 UTC baa4adc66aefe2c3cc15b573b8a19dec786a1641
2 files changed +4 -3
parse-options.c
+2 -1
@@ -266,7 +266,8 @@ again:
266 }
267 if (!rest) {
268 /* abbreviated? */
269 - if (!strncmp(long_name, arg, arg_end - arg)) {
269 + if (!(p->flags & PARSE_OPT_KEEP_UNKNOWN) &&
270 + !strncmp(long_name, arg, arg_end - arg)) {
271 is_abbreviated:
272 if (abbrev_option) {
273 /*
t/t7800-difftool.sh
+2 -2
@@ -546,7 +546,7 @@ do
546 done >actual
547 EOF
548
549 -test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' '
549 +test_expect_success SYMLINKS 'difftool --dir-diff --symlinks without unstaged changes' '
550 cat >expect <<-EOF &&
551 file
552 $PWD/file
@@ -555,7 +555,7 @@ test_expect_success SYMLINKS 'difftool --dir-diff --symlink without unstaged cha
555 sub/sub
556 $PWD/sub/sub
557 EOF
558 - git difftool --dir-diff --symlink \
558 + git difftool --dir-diff --symlinks \
559 --extcmd "./.git/CHECK_SYMLINKS" branch HEAD &&
560 test_cmp expect actual
561 '