git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Johannes Sixt <j6t@kdbg.org>,
	Philippe Blain <levraiphilippeblain@gmail.com>,
	Git List <git@vger.kernel.org>,
	pudinha <rogi@skylittlesystem.org>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: Re: [BUG] Regression in 'git mergetool --tool-help'
Date: Sun, 20 Dec 2020 10:11:25 -0800	[thread overview]
Message-ID: <xmqqwnxcmjoy.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <a9e6f3aa-e88e-6cc2-fb16-c26bdd3bf4d3@web.de> ("René Scharfe"'s message of "Sun, 20 Dec 2020 17:23:26 +0100")

René Scharfe <l.s.r@web.de> writes:

> This still starts a subshell in the last line.  How about something
> like this?
>
> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> index 7225abd811..79d5ed1fa9 100644
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -46,11 +46,9 @@ show_tool_names () {
>  		while read scriptname
>  		do
>  			setup_tool "$scriptname" 2>/dev/null
> -			variants="$variants$(list_tool_variants)\n"
> -		done
> -		variants="$(echo "$variants" | sort | uniq)"
> -
> -		for toolname in $variants
> +			list_tool_variants
> +		done | sort | uniq |
> +		while read toolname
>  		do
>  			if setup_tool "$toolname" 2>/dev/null &&
>  				(eval "$condition" "$toolname")
>
> It requires setup_tool to be silent, though.

Another thing it depends on is that the side-effect of setup_tool in
the first loop does not matter in the end, as it now is done in the
upstream of a pipe.  It is a safe assumption to make (setup_tool is
called again in the later loop, so in the original it was called
twice), I think.

>> BTW, is `sort -u` not available everywhere?
>
> It's used by the function mergetool_find_win32_cmd in the same file
> and by several test scripts, so that shouldn't be a problem.

"sort -u" is safe; it is even in POSIX.

Having said that, when finding out how portable a construct we
already use is across the platforms we support, my recommendation is
to pretty much ignore what we do in a function or a file that we
know is only used by a single platform.  Stuff written for Windows,
for example, can assume that we use a particular implementation of
system-supplied tools and libraries.  The use of "sort -u" in
mergetool_find_win32_cmd can be legitimately justified with "We know
we use only GNU sed" and "we taught -u to our busybox sed already",
for example, if these statements are true.

Thanks.

  reply	other threads:[~2020-12-20 18:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19  4:23 [BUG] Regression in 'git mergetool --tool-help' Philippe Blain
2020-12-19  4:50 ` Felipe Contreras
2020-12-19  5:33   ` Junio C Hamano
2020-12-19 12:10     ` Felipe Contreras
2020-12-19 17:13       ` Junio C Hamano
2020-12-20  2:13         ` Philippe Blain
2020-12-20 10:28           ` Johannes Sixt
2020-12-20 16:23             ` René Scharfe
2020-12-20 18:11               ` Junio C Hamano [this message]
2020-12-20 23:47               ` Philippe Blain
2020-12-21  0:41                 ` Junio C Hamano
2020-12-20 15:34           ` Junio C Hamano
2020-12-19  5:16 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqwnxcmjoy.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=l.s.r@web.de \
    --cc=levraiphilippeblain@gmail.com \
    --cc=rogi@skylittlesystem.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).