threads / discuss / 32745

mergetool: include custom tools in '--tool-help'

Subject: mergetool: include custom tools in '--tool-help'

## tl;dr

5 messages between Jan 27, 2013 and Jan 27, 2013.

replies: 4people: 3as markdown or json

John Keeping· Jan 27, 2013, 16:34 UTC · lore

'git mergetool --tool-help' only lists builtin tools, not those that the user has configured via a 'mergetool.<tool>.cmd' config value. Fix this by inspecting the tools configured in this way and adding them to the available and unavailable lists before displaying them.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
After the recent changes to mergetool, do we want to do something like
this as well, so that 'git mergetool --tool-help' will display any tools
configured by the user/system administrator?
This is on top of jk/mergetool.
 git-mergetool--lib.sh | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 1d0fb12..f9a617c 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -206,6 +206,29 @@ list_merge_tool_candidates () {
 	esac
 }
 
+# Adds tools from git-config to the available and unavailable lists.
+# The tools are found in "$1.<tool>.cmd".
+add_config_tools() {
+	section=$1
+
+	eval $(git config --get-regexp $section'\..*\.cmd' |
+		while read -r key value
+		do
+			tool=${key#mergetool.}
+			tool=${tool%.cmd}
+
+			tool=$(echo "$tool" |sed -e 's/'\''/'\''\\'\'\''/g')
+
+			cmd=$(eval -- "set -- $value"; echo "$1")
+			if type "$cmd" >/dev/null 2>&1
+			then
+				echo "available=\"\${available}\"'$tool'\"\$LF\""
+			else
+				echo "unavailable=\"\${unavailable}\"'$tool'\"\$LF\""
+			fi
+		done)
+}
+
 show_tool_help () {
 	unavailable= available= LF='
 '
@@ -223,6 +246,12 @@ show_tool_help () {
 		fi
 	done
 
+	add_config_tools mergetool
+	if diff_mode
+	then
+		add_config_tools difftool
+	fi
+
 	cmd_name=${TOOL_MODE}tool
 	if test -n "$available"
 	then
-- 
1.8.1.1
Junio C Hamano· Jan 27, 2013, 18:03 UTC · re: John Keeping · lore

Re: mergetool: include custom tools in '--tool-help'

John Keeping <john@keeping.me.uk> writes:
> 'git mergetool --tool-help' only lists builtin tools, not those that the
> user has configured via a 'mergetool.<tool>.cmd' config value.  Fix this
> by inspecting the tools configured in this way and adding them to the
> available and unavailable lists before displaying them.

Although I am not a mergetool user, I would imagine that it would make sense to show it as available.

Just like "git help -a" lists subcommands in a way that can be easy to tell which ones are the standard ones and which ones are user customizations, this may want to give a similar distinction, though. I dunno.

Show 59 quoted lines
>
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---
> After the recent changes to mergetool, do we want to do something like
> this as well, so that 'git mergetool --tool-help' will display any tools
> configured by the user/system administrator?
>
> This is on top of jk/mergetool.
>
>  git-mergetool--lib.sh | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>
> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> index 1d0fb12..f9a617c 100644
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -206,6 +206,29 @@ list_merge_tool_candidates () {
>  	esac
>  }
>  
> +# Adds tools from git-config to the available and unavailable lists.
> +# The tools are found in "$1.<tool>.cmd".
> +add_config_tools() {
> +	section=$1
> +
> +	eval $(git config --get-regexp $section'\..*\.cmd' |
> +		while read -r key value
> +		do
> +			tool=${key#mergetool.}
> +			tool=${tool%.cmd}
> +
> +			tool=$(echo "$tool" |sed -e 's/'\''/'\''\\'\'\''/g')
> +
> +			cmd=$(eval -- "set -- $value"; echo "$1")
> +			if type "$cmd" >/dev/null 2>&1
> +			then
> +				echo "available=\"\${available}\"'$tool'\"\$LF\""
> +			else
> +				echo "unavailable=\"\${unavailable}\"'$tool'\"\$LF\""
> +			fi
> +		done)
> +}
> +
>  show_tool_help () {
>  	unavailable= available= LF='
>  '
> @@ -223,6 +246,12 @@ show_tool_help () {
>  		fi
>  	done
>  
> +	add_config_tools mergetool
> +	if diff_mode
> +	then
> +		add_config_tools difftool
> +	fi
> +
>  	cmd_name=${TOOL_MODE}tool
>  	if test -n "$available"
>  	then
John Keeping· Jan 27, 2013, 19:56 UTC · re: Junio C Hamano · lore

Re: mergetool: include custom tools in '--tool-help'

On Sun, Jan 27, 2013 at 10:03:19AM -0800, Junio C Hamano wrote:
Show 14 quoted lines
> John Keeping <john@keeping.me.uk> writes:
> 
> > 'git mergetool --tool-help' only lists builtin tools, not those that the
> > user has configured via a 'mergetool.<tool>.cmd' config value.  Fix this
> > by inspecting the tools configured in this way and adding them to the
> > available and unavailable lists before displaying them.
> 
> Although I am not a mergetool user, I would imagine that it would
> make sense to show it as available.
> 
> Just like "git help -a" lists subcommands in a way that can be easy
> to tell which ones are the standard ones and which ones are user
> customizations, this may want to give a similar distinction, though.
> I dunno.

I think I'd want to do this with a suffix if at all, so the output would be like this:

    'git mergetool --tool=<tool>' may be set to one of the following:
            araxis
            gvimdiff
            gvimdiff2
            mytool	(user-defined)
            vimdiff
            vimdiff2
    The following tools are valid, but not currently available:
            bc3
            codecompare
            deltawalker
            diffuse
            ecmerge
            emerge
            kdiff3
            meld
            opendiff
            p4merge
            tkdiff
            tortoisemerge
            xxdiff
    Some of the tools listed above only work in a windowed
    environment. If run in a terminal-only session, they will fail.

Adding more sections for the user-defined tools feels like the output would be too imposing and would make it hard to immediately identify the valid option.

John
Junio C Hamano· Jan 27, 2013, 20:13 UTC · re: John Keeping · lore

Re: mergetool: include custom tools in '--tool-help'

John Keeping <john@keeping.me.uk> writes:
Show 11 quoted lines
> I think I'd want to do this with a suffix if at all, so the output would
> be like this:
>
>     'git mergetool --tool=<tool>' may be set to one of the following:
>
>             araxis
>             gvimdiff
>             gvimdiff2
>             mytool	(user-defined)
>             vimdiff
>             vimdiff2

That is fine by me, but the real users of mergetool please feel free to raise objections.

David Aguilar· Jan 27, 2013, 21:10 UTC · re: Junio C Hamano · lore

Re: mergetool: include custom tools in '--tool-help'

On Sun, Jan 27, 2013 at 12:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
> John Keeping <john@keeping.me.uk> writes:
>
>> I think I'd want to do this with a suffix if at all, so the output would
>> be like this:
>>
>>     'git mergetool --tool=<tool>' may be set to one of the following:
>>
>>             araxis
>>             gvimdiff
>>             gvimdiff2
>>             mytool    (user-defined)
>>             vimdiff
>>             vimdiff2
>
> That is fine by me, but the real users of mergetool please feel free
> to raise objections.
This seems pretty useful.

I did a bit of refactoring last night that I'd like to post here, the end result being something that's plugged into Documentation/.

I think what I did may also help add this functionality, and could be useful to build upon.

I'll send my patches shortly so you can take a look. Basically, I added a simple way to loop over the tools and filter them. This is reused in show_tool_help() and Documentation/Makefile.

The refactoring changes how show_tool_help() works, so I'd like you to take a look before we add a new feature since it might make it easier to do.

-- 
David

← back to recent threads