git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] mergetool--lib: fix '--tool-help' to correctly show available tools
@ 2020-12-28 18:22 Philippe Blain via GitGitGadget
  2020-12-28 19:41 ` [PATCH v2] " Philippe Blain via GitGitGadget
  0 siblings, 1 reply; 10+ messages in thread
From: Philippe Blain via GitGitGadget @ 2020-12-28 18:22 UTC (permalink / raw)
  To: git
  Cc: Johannes Sixt, Felipe Contreras, pudinha, René Scharfe,
	Philippe Blain, Philippe Blain

From: Philippe Blain <philippe.blain@canada.ca>

Commit 83bbf9b92e (mergetool--lib: improve support for vimdiff-style tool
variants, 2020-07-29) introduced a regression in the output of `git mergetool
--tool-help` and `git difftool --tool-help` [1].

In function 'show_tool_names' in git-mergetool--lib.sh, we loop over the
supported mergetools and their variants and accumulate them in the variable
'variants', separating them with a literal '\n'.

The code then uses 'echo $variants' to turn these '\n' into newlines, but this
behaviour is not portable, it just happens to work in some shells, like
dash(1)'s 'echo' builtin.

For shells in which 'echo' does not turn '\n' into newlines, the end result is
that the only tools that are shown are those that are found and have variants,
since the variants are separated by actual newlines in '$variants' because of
the several 'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.

Fix this bug by embedding an actual line feed into `variants` in
show_tool_names(). While at it, replace `sort | uniq` by `sort -u`.

To prevent future regressions, add a simple test that counts the number
of tools shown by 'git mergetool --tool-help', irrespective of their
installed status, by making use of the fact that mergetools are listed
by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
`git config` commands used at the beginning of the test to remove the
fake tools used by the previous test with 'test_might_fail' so that the
test can be run independantly of the previous test without failing.

[1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/

Reported-by: Philippe Blain <levraiphilippeblain@gmail.com>
Based-on-patch-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
    Fix regression in 'git {diff,merge}tool --tool-help'
    
    I went with Johannes' suggestion finally because upon further
    inspection, René's patch for some reason (I did not debug further)
    caused to code to never reach 'any_shown=yes' in show_tool_help,
    therefore changing the output of the command.
    
    I guess it's too late for inclusion in 2.30...

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-825%2Fphil-blain%2Fmergetool-tool-help-fix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-825/phil-blain/mergetool-tool-help-fix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/825

 git-mergetool--lib.sh |  6 ++++--
 t/t7610-mergetool.sh  | 10 ++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 7225abd8112..78f3647ed97 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -46,9 +46,11 @@ show_tool_names () {
 		while read scriptname
 		do
 			setup_tool "$scriptname" 2>/dev/null
-			variants="$variants$(list_tool_variants)\n"
+			# We need an actual line feed here
+			variants="$variants
+$(list_tool_variants)"
 		done
-		variants="$(echo "$variants" | sort | uniq)"
+		variants="$(echo "$variants" | sort -u)"
 
 		for toolname in $variants
 		do
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 70afdd06fa7..ebd3af139e5 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
 	test_cmp expect actual
 '
 
+test_expect_success 'mergetool --tool-help shows all recognized tools' '
+	# Remove fake tools added in previous tests
+	test_might_fail git config --unset merge.tool &&
+	test_might_fail git config --remove-section mergetool.mytool &&
+	test_might_fail git config --remove-section mergetool.mybase &&
+	git mergetool --tool-help >output &&
+	grep "$(printf "\t")" output >mergetools &&
+	test_line_count = 30 mergetools
+'
+
 test_done

base-commit: 4a0de43f4923993377dbbc42cfc0a1054b6c5ccf
-- 
gitgitgadget

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

* [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2020-12-28 18:22 [PATCH] mergetool--lib: fix '--tool-help' to correctly show available tools Philippe Blain via GitGitGadget
@ 2020-12-28 19:41 ` Philippe Blain via GitGitGadget
  2021-01-06 13:16   ` SZEDER Gábor
  2021-01-07  1:09   ` [PATCH v3] " Philippe Blain via GitGitGadget
  0 siblings, 2 replies; 10+ messages in thread
From: Philippe Blain via GitGitGadget @ 2020-12-28 19:41 UTC (permalink / raw)
  To: git
  Cc: Johannes Sixt, Felipe Contreras, pudinha, René Scharfe,
	Philippe Blain, Philippe Blain

From: Philippe Blain <levraiphilippeblain@gmail.com>

Commit 83bbf9b92e (mergetool--lib: improve support for vimdiff-style tool
variants, 2020-07-29) introduced a regression in the output of `git mergetool
--tool-help` and `git difftool --tool-help` [1].

In function 'show_tool_names' in git-mergetool--lib.sh, we loop over the
supported mergetools and their variants and accumulate them in the variable
'variants', separating them with a literal '\n'.

The code then uses 'echo $variants' to turn these '\n' into newlines, but this
behaviour is not portable, it just happens to work in some shells, like
dash(1)'s 'echo' builtin.

For shells in which 'echo' does not turn '\n' into newlines, the end result is
that the only tools that are shown are those that are found and have variants,
since the variants are separated by actual newlines in '$variants' because of
the several 'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.

Fix this bug by embedding an actual line feed into `variants` in
show_tool_names(). While at it, replace `sort | uniq` by `sort -u`.

To prevent future regressions, add a simple test that counts the number
of tools shown by 'git mergetool --tool-help', irrespective of their
installed status, by making use of the fact that mergetools are listed
by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
`git config` commands used at the beginning of the test to remove the
fake tools used by the previous test with 'test_might_fail' so that the
test can be run independantly of the previous test without failing.

[1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/

Reported-by: Philippe Blain <levraiphilippeblain@gmail.com>
Based-on-patch-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
    Fix regression in 'git {diff,merge}tool --tool-help'
    
    Changes since v1:
    
     * Changed commit authorship (v1 sent with wrong identity).
    
    v1: I went with Johannes' suggestion finally because upon further
    inspection, René's patch for some reason (I did not debug further)
    caused to code to never reach 'any_shown=yes' in show_tool_help,
    therefore changing the output of the command.
    
    I guess it's too late for inclusion in 2.30...

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-825%2Fphil-blain%2Fmergetool-tool-help-fix-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-825/phil-blain/mergetool-tool-help-fix-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/825

Range-diff vs v1:

 1:  a79d0a09daa ! 1:  2b9dce31fd0 mergetool--lib: fix '--tool-help' to correctly show available tools
     @@
       ## Metadata ##
     -Author: Philippe Blain <philippe.blain@canada.ca>
     +Author: Philippe Blain <levraiphilippeblain@gmail.com>
      
       ## Commit message ##
          mergetool--lib: fix '--tool-help' to correctly show available tools


 git-mergetool--lib.sh |  6 ++++--
 t/t7610-mergetool.sh  | 10 ++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 7225abd8112..78f3647ed97 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -46,9 +46,11 @@ show_tool_names () {
 		while read scriptname
 		do
 			setup_tool "$scriptname" 2>/dev/null
-			variants="$variants$(list_tool_variants)\n"
+			# We need an actual line feed here
+			variants="$variants
+$(list_tool_variants)"
 		done
-		variants="$(echo "$variants" | sort | uniq)"
+		variants="$(echo "$variants" | sort -u)"
 
 		for toolname in $variants
 		do
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 70afdd06fa7..ebd3af139e5 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
 	test_cmp expect actual
 '
 
+test_expect_success 'mergetool --tool-help shows all recognized tools' '
+	# Remove fake tools added in previous tests
+	test_might_fail git config --unset merge.tool &&
+	test_might_fail git config --remove-section mergetool.mytool &&
+	test_might_fail git config --remove-section mergetool.mybase &&
+	git mergetool --tool-help >output &&
+	grep "$(printf "\t")" output >mergetools &&
+	test_line_count = 30 mergetools
+'
+
 test_done

base-commit: 4a0de43f4923993377dbbc42cfc0a1054b6c5ccf
-- 
gitgitgadget

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

* Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2020-12-28 19:41 ` [PATCH v2] " Philippe Blain via GitGitGadget
@ 2021-01-06 13:16   ` SZEDER Gábor
  2021-01-06 13:34     ` Philippe Blain
  2021-01-06 21:15     ` Junio C Hamano
  2021-01-07  1:09   ` [PATCH v3] " Philippe Blain via GitGitGadget
  1 sibling, 2 replies; 10+ messages in thread
From: SZEDER Gábor @ 2021-01-06 13:16 UTC (permalink / raw)
  To: Junio C Hamano, Philippe Blain via GitGitGadget
  Cc: git, Johannes Sixt, Felipe Contreras, pudinha, René Scharfe,
	Philippe Blain

On Mon, Dec 28, 2020 at 07:41:44PM +0000, Philippe Blain via GitGitGadget wrote:
> To prevent future regressions, add a simple test that counts the number
> of tools shown by 'git mergetool --tool-help', irrespective of their
> installed status, by making use of the fact that mergetools are listed
> by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
> `git config` commands used at the beginning of the test to remove the
> fake tools used by the previous test with 'test_might_fail' so that the
> test can be run independantly of the previous test without failing.

> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
> index 70afdd06fa7..ebd3af139e5 100755
> --- a/t/t7610-mergetool.sh
> +++ b/t/t7610-mergetool.sh
> @@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'mergetool --tool-help shows all recognized tools' '
> +	# Remove fake tools added in previous tests
> +	test_might_fail git config --unset merge.tool &&
> +	test_might_fail git config --remove-section mergetool.mytool &&
> +	test_might_fail git config --remove-section mergetool.mybase &&
> +	git mergetool --tool-help >output &&
> +	grep "$(printf "\t")" output >mergetools &&
> +	test_line_count = 30 mergetools
> +'

This new test fails when the topic 'pb/mergetool-tool-help-fix' is
built and tested in isolation, because 'git mergetool --tool-help'
lists only 29 tools instead of the expected 30.  The reason is that
'pb/mergetool-tool-help-fix' doesn't include commit 6bc9082c0f
(mergetools/bc: add `bc4` to the alias list for Beyond Compare,
2020-11-11), which added that 30th tool (and is already part of
v2.30.0).

It also makes me wonder whether this is the right way to test this
fix, because we'll need to adjust this test case every time we add
support for a new merge tool (which arguably doesn't happen that
often, but since we are already at 30 it doesn't seem to be that rare
either).


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

* Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2021-01-06 13:16   ` SZEDER Gábor
@ 2021-01-06 13:34     ` Philippe Blain
  2021-01-06 21:15     ` Junio C Hamano
  1 sibling, 0 replies; 10+ messages in thread
From: Philippe Blain @ 2021-01-06 13:34 UTC (permalink / raw)
  To: SZEDER Gábor, Junio C Hamano,
	Philippe Blain via GitGitGadget
  Cc: git, Johannes Sixt, Felipe Contreras, pudinha, René Scharfe

Hi Gábor,

Le 2021-01-06 à 08:16, SZEDER Gábor a écrit :
> On Mon, Dec 28, 2020 at 07:41:44PM +0000, Philippe Blain via GitGitGadget wrote:
>> To prevent future regressions, add a simple test that counts the number
>> of tools shown by 'git mergetool --tool-help', irrespective of their
>> installed status, by making use of the fact that mergetools are listed
>> by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
>> `git config` commands used at the beginning of the test to remove the
>> fake tools used by the previous test with 'test_might_fail' so that the
>> test can be run independantly of the previous test without failing.
> 
>> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
>> index 70afdd06fa7..ebd3af139e5 100755
>> --- a/t/t7610-mergetool.sh
>> +++ b/t/t7610-mergetool.sh
>> @@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
>>   	test_cmp expect actual
>>   '
>>   
>> +test_expect_success 'mergetool --tool-help shows all recognized tools' '
>> +	# Remove fake tools added in previous tests
>> +	test_might_fail git config --unset merge.tool &&
>> +	test_might_fail git config --remove-section mergetool.mytool &&
>> +	test_might_fail git config --remove-section mergetool.mybase &&
>> +	git mergetool --tool-help >output &&
>> +	grep "$(printf "\t")" output >mergetools &&
>> +	test_line_count = 30 mergetools
>> +'
> 
> This new test fails when the topic 'pb/mergetool-tool-help-fix' is
> built and tested in isolation, because 'git mergetool --tool-help'
> lists only 29 tools instead of the expected 30.  The reason is that
> 'pb/mergetool-tool-help-fix' doesn't include commit 6bc9082c0f
> (mergetools/bc: add `bc4` to the alias list for Beyond Compare,
> 2020-11-11), which added that 30th tool (and is already part of
> v2.30.0).

Indeed. The branch I submitted is based on v2.30.0-rc2, but Junio based
pb/mergetool-tool-help-fix on v2.29.0-rc0~165^2, so the number of supported
tools is "wrong".

> 
> It also makes me wonder whether this is the right way to test this
> fix, because we'll need to adjust this test case every time we add
> support for a new merge tool (which arguably doesn't happen that
> often, but since we are already at 30 it doesn't seem to be that rare
> either).

Yes, it does. I thought about that, and I came to the conclusion that it
was the easiest way to prevent a regression like the one this patch is fixing.
I tought about doing it a different way, like having the test count the available
mergetools itself, and comparing the number of tools shown by '--tool-help' with
that number, but I chose not to do that because it seemed to be more complicated
(and would end up kind of re-implementing what '--tool-help' does, in a way...)

If you think of another of how we could test it, I can try it.

Cheers,

Philippe.

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

* Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2021-01-06 13:16   ` SZEDER Gábor
  2021-01-06 13:34     ` Philippe Blain
@ 2021-01-06 21:15     ` Junio C Hamano
  2021-01-06 22:59       ` Philippe Blain
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2021-01-06 21:15 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Philippe Blain via GitGitGadget, git, Johannes Sixt,
	Felipe Contreras, pudinha, René Scharfe, Philippe Blain

SZEDER Gábor <szeder.dev@gmail.com> writes:

> On Mon, Dec 28, 2020 at 07:41:44PM +0000, Philippe Blain via GitGitGadget wrote:
>> To prevent future regressions, add a simple test that counts the number
>> of tools shown by 'git mergetool --tool-help', irrespective of their
>> installed status, by making use of the fact that mergetools are listed
>> by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
>> `git config` commands used at the beginning of the test to remove the
>> fake tools used by the previous test with 'test_might_fail' so that the
>> test can be run independantly of the previous test without failing.
>
>> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
>> index 70afdd06fa7..ebd3af139e5 100755
>> --- a/t/t7610-mergetool.sh
>> +++ b/t/t7610-mergetool.sh
>> @@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
>>  	test_cmp expect actual
>>  '
>>  
>> +test_expect_success 'mergetool --tool-help shows all recognized tools' '
>> +	# Remove fake tools added in previous tests
>> +	test_might_fail git config --unset merge.tool &&
>> +	test_might_fail git config --remove-section mergetool.mytool &&
>> +	test_might_fail git config --remove-section mergetool.mybase &&
>> +	git mergetool --tool-help >output &&
>> +	grep "$(printf "\t")" output >mergetools &&
>> +	test_line_count = 30 mergetools
>> +'
>
> This new test fails when the topic 'pb/mergetool-tool-help-fix' is
> built and tested in isolation, because 'git mergetool --tool-help'
> lists only 29 tools instead of the expected 30.  The reason is that
> 'pb/mergetool-tool-help-fix' doesn't include commit 6bc9082c0f
> (mergetools/bc: add `bc4` to the alias list for Beyond Compare,
> 2020-11-11), which added that 30th tool (and is already part of
> v2.30.0).
>
> It also makes me wonder whether this is the right way to test this
> fix, because we'll need to adjust this test case every time we add
> support for a new merge tool (which arguably doesn't happen that
> often, but since we are already at 30 it doesn't seem to be that rare
> either).

Yes, that is a very good point.  Also I can imagine us allowing some
tools to be excluded depending on a build/installation option and/or
which platform you are on, so hardcoded 30 smells a bit too fragile
as an approach for a project like ours.

What was the symptom before the fix?  Is it just missing only some
tools among 30?  Was there some pattern in names of missing one and
the ones that still got output?  Or was it more like "we see nothing
shown"?

Thanks.

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

* Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2021-01-06 21:15     ` Junio C Hamano
@ 2021-01-06 22:59       ` Philippe Blain
  2021-01-06 23:06         ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Philippe Blain @ 2021-01-06 22:59 UTC (permalink / raw)
  To: Junio C Hamano, SZEDER Gábor
  Cc: Philippe Blain via GitGitGadget, git, Johannes Sixt,
	Felipe Contreras, pudinha, René Scharfe

Hi Junio,

Le 2021-01-06 à 16:15, Junio C Hamano a écrit :
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
>> On Mon, Dec 28, 2020 at 07:41:44PM +0000, Philippe Blain via GitGitGadget wrote:
>>> To prevent future regressions, add a simple test that counts the number
>>> of tools shown by 'git mergetool --tool-help', irrespective of their
>>> installed status, by making use of the fact that mergetools are listed
>>> by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
>>> `git config` commands used at the beginning of the test to remove the
>>> fake tools used by the previous test with 'test_might_fail' so that the
>>> test can be run independantly of the previous test without failing.
>>
>>> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
>>> index 70afdd06fa7..ebd3af139e5 100755
>>> --- a/t/t7610-mergetool.sh
>>> +++ b/t/t7610-mergetool.sh
>>> @@ -828,4 +828,14 @@ test_expect_success 'mergetool -Oorder-file is honored' '
>>>   	test_cmp expect actual
>>>   '
>>>   
>>> +test_expect_success 'mergetool --tool-help shows all recognized tools' '
>>> +	# Remove fake tools added in previous tests
>>> +	test_might_fail git config --unset merge.tool &&
>>> +	test_might_fail git config --remove-section mergetool.mytool &&
>>> +	test_might_fail git config --remove-section mergetool.mybase &&
>>> +	git mergetool --tool-help >output &&
>>> +	grep "$(printf "\t")" output >mergetools &&
>>> +	test_line_count = 30 mergetools
>>> +'
>>
>> This new test fails when the topic 'pb/mergetool-tool-help-fix' is
>> built and tested in isolation, because 'git mergetool --tool-help'
>> lists only 29 tools instead of the expected 30.  The reason is that
>> 'pb/mergetool-tool-help-fix' doesn't include commit 6bc9082c0f
>> (mergetools/bc: add `bc4` to the alias list for Beyond Compare,
>> 2020-11-11), which added that 30th tool (and is already part of
>> v2.30.0).
>>
>> It also makes me wonder whether this is the right way to test this
>> fix, because we'll need to adjust this test case every time we add
>> support for a new merge tool (which arguably doesn't happen that
>> often, but since we are already at 30 it doesn't seem to be that rare
>> either).
> 
> Yes, that is a very good point.  Also I can imagine us allowing some
> tools to be excluded depending on a build/installation option and/or
> which platform you are on, so hardcoded 30 smells a bit too fragile
> as an approach for a project like ours.

As I said in my response to Gabor [1], this was a simple attempt at
preventing a future breakage. I agree that it could be improved, but
I'm not sure how without actually re-implementing the code of
'git mergetool --tool-help' in the test itself, especially if more
logic is added as you say for eg. hiding some tools depending
on platform/installation options.

> 
> What was the symptom before the fix?  Is it just missing only some
> tools among 30?  Was there some pattern in names of missing one and
> the ones that still got output?  Or was it more like "we see nothing
> shown"?
> 

The only tools that are shown are the variants, except the alphabetically last variant,
because as I wrote in the commit message,

For shells in which 'echo' does not turn '\n' into newlines, the end result is
that the only tools that are shown are those that are found and have variants,
since the variants are separated by actual newlines in '$variants' because of
the several 'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.

[Note: I should re-roll and remove "that are found" since that bit is not true).

For example, I get this with Bash 4.4.19 as /bin/sh on Ubuntu 18.04:

---
$ git mergetool --tool-help
'git mergetool --tool=<tool>' may be set to one of the following:
                 gvimdiff
                 gvimdiff2
                 gvimdiff3
                 vimdiff2
                 vimdiff3

The following tools are valid, but not currently available:
                 bc3
                 nvimdiff
                 nvimdiff2

Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.
---

Note that 'vimdiff', 'nvimdiff3' (last variant for vimdiff),
'bc' and 'bc4' (last variant for bc) are absent, and
all other tools that have no variants are absent as well.

I was able to understand what was happening by running 'git mergetool'
with Bash tracing:

PATH=$(git --exec-path):$PATH \
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' \
bash -x $(git --exec-path)/git-mergetool --tool-help

P.S.
I noticed that all tools are shown correctly on my Mac,
which has Bash 3.2.57 as /bin/sh. So behaviour of 'echo' regarding
'\n' depends on both the shell and its version (!)


[1] https://lore.kernel.org/git/11b3c261-14e6-0293-02a6-92bd1ea680d2@gmail.com/

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

* Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2021-01-06 22:59       ` Philippe Blain
@ 2021-01-06 23:06         ` Junio C Hamano
  2021-01-07  0:32           ` Philippe Blain
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2021-01-06 23:06 UTC (permalink / raw)
  To: Philippe Blain
  Cc: SZEDER Gábor, Philippe Blain via GitGitGadget, git,
	Johannes Sixt, Felipe Contreras, pudinha, René Scharfe

Philippe Blain <levraiphilippeblain@gmail.com> writes:

>> What was the symptom before the fix?  Is it just missing only some
>> tools among 30?  Was there some pattern in names of missing one and
>> the ones that still got output?  Or was it more like "we see nothing
>> shown"?
> ...
> Note that 'vimdiff', 'nvimdiff3' (last variant for vimdiff),
> 'bc' and 'bc4' (last variant for bc) are absent, and
> all other tools that have no variants are absent as well.

Thanks, that is exactly the kind of "some pattern" I wanted to see
us looking for, because I wonder if it is a more robust and cheaper
(maintenance wise) approach to find one single tool that we support,
which does not have, and which is unlikely to gain, any numbered
variants.  If we can find such a tool, we can grep for its name in
the output.




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

* Re: [PATCH v2] mergetool--lib: fix '--tool-help' to correctly show available tools
  2021-01-06 23:06         ` Junio C Hamano
@ 2021-01-07  0:32           ` Philippe Blain
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Blain @ 2021-01-07  0:32 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: SZEDER Gábor, Philippe Blain via GitGitGadget, git,
	Johannes Sixt, Felipe Contreras, pudinha, René Scharfe



Le 2021-01-06 à 18:06, Junio C Hamano a écrit :
> Philippe Blain <levraiphilippeblain@gmail.com> writes:
> 
>>> What was the symptom before the fix?  Is it just missing only some
>>> tools among 30?  Was there some pattern in names of missing one and
>>> the ones that still got output?  Or was it more like "we see nothing
>>> shown"?
>> ...
>> Note that 'vimdiff', 'nvimdiff3' (last variant for vimdiff),
>> 'bc' and 'bc4' (last variant for bc) are absent, and
>> all other tools that have no variants are absent as well.
> 
> Thanks, that is exactly the kind of "some pattern" I wanted to see
> us looking for, because I wonder if it is a more robust and cheaper
> (maintenance wise) approach to find one single tool that we support,
> which does not have, and which is unlikely to gain, any numbered
> variants.  If we can find such a tool, we can grep for its name in
> the output.
> 

Or, just choose a few tools, including some variants, and grep for those?
This way we are not relying on a single tool being shown for the test
to pas...

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

* [PATCH v3] mergetool--lib: fix '--tool-help' to correctly show available tools
  2020-12-28 19:41 ` [PATCH v2] " Philippe Blain via GitGitGadget
  2021-01-06 13:16   ` SZEDER Gábor
@ 2021-01-07  1:09   ` Philippe Blain via GitGitGadget
  2021-01-07 13:37     ` Philippe Blain
  1 sibling, 1 reply; 10+ messages in thread
From: Philippe Blain via GitGitGadget @ 2021-01-07  1:09 UTC (permalink / raw)
  To: git
  Cc: Johannes Sixt, Felipe Contreras, pudinha, René Scharfe,
	SZEDER Gábor, Philippe Blain, Philippe Blain, Philippe Blain

From: Philippe Blain <levraiphilippeblain@gmail.com>

Commit 83bbf9b92e (mergetool--lib: improve support for vimdiff-style tool
variants, 2020-07-29) introduced a regression in the output of `git mergetool
--tool-help` and `git difftool --tool-help` [1].

In function 'show_tool_names' in git-mergetool--lib.sh, we loop over the
supported mergetools and their variants and accumulate them in the variable
'variants', separating them with a literal '\n'.

The code then uses 'echo $variants' to turn these '\n' into newlines, but this
behaviour is not portable, it just happens to work in some shells, like
dash(1)'s 'echo' builtin.

For shells in which 'echo' does not turn '\n' into newlines, the end
result is that the only tools that are shown are the existing variants
(except the last variant alphabetically), since the variants are
separated by actual newlines in '$variants' because of the several
'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.

Fix this bug by embedding an actual line feed into `variants` in
show_tool_names(). While at it, replace `sort | uniq` by `sort -u`.

To prevent future regressions, add a simple test that checks that a few
known tools are correctly shown (let's avoid counting the total number
of tools to lessen the maintenance burden when new tools are added or if
'--tool-help' learns additional logic, like hiding tools depending on
the current platform).

[1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/

Reported-by: Philippe Blain <levraiphilippeblain@gmail.com>
Based-on-patch-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
    Fix regression in 'git {diff,merge}tool --tool-help'
    
    Changes since v1:
    
     * Changed commit authorship (v1 sent with wrong identity).
    
    v1: I went with Johannes' suggestion finally because upon further
    inspection, René's patch for some reason (I did not debug further)
    caused to code to never reach 'any_shown=yes' in show_tool_help,
    therefore changing the output of the command.
    
    I guess it's too late for inclusion in 2.30...

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-825%2Fphil-blain%2Fmergetool-tool-help-fix-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-825/phil-blain/mergetool-tool-help-fix-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/825

Range-diff vs v2:

 1:  2b9dce31fd0 ! 1:  f66421939ec mergetool--lib: fix '--tool-help' to correctly show available tools
     @@ Commit message
          behaviour is not portable, it just happens to work in some shells, like
          dash(1)'s 'echo' builtin.
      
     -    For shells in which 'echo' does not turn '\n' into newlines, the end result is
     -    that the only tools that are shown are those that are found and have variants,
     -    since the variants are separated by actual newlines in '$variants' because of
     -    the several 'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.
     +    For shells in which 'echo' does not turn '\n' into newlines, the end
     +    result is that the only tools that are shown are the existing variants
     +    (except the last variant alphabetically), since the variants are
     +    separated by actual newlines in '$variants' because of the several
     +    'echo' calls in mergetools/{bc,vimdiff}::list_tool_variants.
      
          Fix this bug by embedding an actual line feed into `variants` in
          show_tool_names(). While at it, replace `sort | uniq` by `sort -u`.
      
     -    To prevent future regressions, add a simple test that counts the number
     -    of tools shown by 'git mergetool --tool-help', irrespective of their
     -    installed status, by making use of the fact that mergetools are listed
     -    by 'git mergetool --tool-help' on lines starting with tabs. Prefix the
     -    `git config` commands used at the beginning of the test to remove the
     -    fake tools used by the previous test with 'test_might_fail' so that the
     -    test can be run independantly of the previous test without failing.
     +    To prevent future regressions, add a simple test that checks that a few
     +    known tools are correctly shown (let's avoid counting the total number
     +    of tools to lessen the maintenance burden when new tools are added or if
     +    '--tool-help' learns additional logic, like hiding tools depending on
     +    the current platform).
      
          [1] https://lore.kernel.org/git/CADtb9DyozjgAsdFYL8fFBEWmq7iz4=prZYVUdH9W-J5CKVS4OA@mail.gmail.com/
      
     @@ t/t7610-mergetool.sh: test_expect_success 'mergetool -Oorder-file is honored' '
       	test_cmp expect actual
       '
       
     -+test_expect_success 'mergetool --tool-help shows all recognized tools' '
     -+	# Remove fake tools added in previous tests
     -+	test_might_fail git config --unset merge.tool &&
     -+	test_might_fail git config --remove-section mergetool.mytool &&
     -+	test_might_fail git config --remove-section mergetool.mybase &&
     -+	git mergetool --tool-help >output &&
     -+	grep "$(printf "\t")" output >mergetools &&
     -+	test_line_count = 30 mergetools
     ++test_expect_success 'mergetool --tool-help shows recognized tools' '
     ++	# Check a few known tools are correctly shown
     ++	git mergetool --tool-help >mergetools &&
     ++	grep vimdiff mergetools &&
     ++	grep vimdiff3 mergetools &&
     ++	grep gvimdiff2 mergetools &&
     ++	grep araxis mergetools &&
     ++	grep xxdiff mergetools &&
     ++	grep meld mergetools
      +'
      +
       test_done


 git-mergetool--lib.sh |  6 ++++--
 t/t7610-mergetool.sh  | 11 +++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 7225abd8112..78f3647ed97 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -46,9 +46,11 @@ show_tool_names () {
 		while read scriptname
 		do
 			setup_tool "$scriptname" 2>/dev/null
-			variants="$variants$(list_tool_variants)\n"
+			# We need an actual line feed here
+			variants="$variants
+$(list_tool_variants)"
 		done
-		variants="$(echo "$variants" | sort | uniq)"
+		variants="$(echo "$variants" | sort -u)"
 
 		for toolname in $variants
 		do
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 70afdd06fa7..6ac75b5d4c0 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -828,4 +828,15 @@ test_expect_success 'mergetool -Oorder-file is honored' '
 	test_cmp expect actual
 '
 
+test_expect_success 'mergetool --tool-help shows recognized tools' '
+	# Check a few known tools are correctly shown
+	git mergetool --tool-help >mergetools &&
+	grep vimdiff mergetools &&
+	grep vimdiff3 mergetools &&
+	grep gvimdiff2 mergetools &&
+	grep araxis mergetools &&
+	grep xxdiff mergetools &&
+	grep meld mergetools
+'
+
 test_done

base-commit: 4a0de43f4923993377dbbc42cfc0a1054b6c5ccf
-- 
gitgitgadget

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

* Re: [PATCH v3] mergetool--lib: fix '--tool-help' to correctly show available tools
  2021-01-07  1:09   ` [PATCH v3] " Philippe Blain via GitGitGadget
@ 2021-01-07 13:37     ` Philippe Blain
  0 siblings, 0 replies; 10+ messages in thread
From: Philippe Blain @ 2021-01-07 13:37 UTC (permalink / raw)
  To: Philippe Blain via GitGitGadget, git
  Cc: Johannes Sixt, Felipe Contreras, pudinha, René Scharfe,
	SZEDER Gábor



Le 2021-01-06 à 20:09, Philippe Blain via GitGitGadget a écrit :
> From: Philippe Blain <levraiphilippeblain@gmail.com>
> 
> ...
> ---
>      Fix regression in 'git {diff,merge}tool --tool-help'
>      
>      Changes since v1:
>      
>       * Changed commit authorship (v1 sent with wrong identity).
>      
>      v1: I went with Johannes' suggestion finally because upon further
>      inspection, René's patch for some reason (I did not debug further)
>      caused to code to never reach 'any_shown=yes' in show_tool_help,
>      therefore changing the output of the command.
>      
>      I guess it's too late for inclusion in 2.30...

Forgot to summarize changes since v2:

- rewrote the description of the symptom of the bug to reflect what
was really happening
- changed the test to not rely on hard-coding the number of tools,
and just checking a few known tools are shown instead

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

end of thread, other threads:[~2021-01-07 13:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 18:22 [PATCH] mergetool--lib: fix '--tool-help' to correctly show available tools Philippe Blain via GitGitGadget
2020-12-28 19:41 ` [PATCH v2] " Philippe Blain via GitGitGadget
2021-01-06 13:16   ` SZEDER Gábor
2021-01-06 13:34     ` Philippe Blain
2021-01-06 21:15     ` Junio C Hamano
2021-01-06 22:59       ` Philippe Blain
2021-01-06 23:06         ` Junio C Hamano
2021-01-07  0:32           ` Philippe Blain
2021-01-07  1:09   ` [PATCH v3] " Philippe Blain via GitGitGadget
2021-01-07 13:37     ` Philippe Blain

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).