Web lists-archives.com

Re: [PATCH v4 3/6] mergetool: use get_merge_tool function




On Thu, Apr 25, 2019 at 02:54:39AM -0700, Denton Liu wrote:
> In git-mergetool, the logic for getting which merge tool to use is
> duplicated in git-mergetool--lib, except for the fact that it needs to
> know whether the tool was guessed or not.
> 
> Rewrite `get_merge_tool` to return whether or not the tool was guessed
> through the return code and make git-mergetool call this function
> instead of duplicating the logic. Note that 1 was chosen to be the
> return code of when a tool is guessed because it seems like a slightly
> more abnormal condition than getting a tool that's explicitly specified
> but this is completely arbitrary.
> 
> Also, let `$GIT_MERGETOOL_GUI` be set to determine whether or not the
> guitool will be selected.
> 
> This change is not completely backwards compatible as there may be
> external users of git-mergetool--lib. However, only one user,
> git-diffall[1], was found from searching GitHub and Google. It seems
> very unlikely that there exists an external caller that would take into
> account the return code of `get_merge_tool` as it would always return 0
> before this change so this change probably does not affect any external
> users.
> 
> [1]: https://github.com/thenigan/git-diffall
> 
> Signed-off-by: Denton Liu <liu.denton@xxxxxxxxx>


The author of git-diffall approached the list some time ago and his
contribution resulted in "git difftool --dir-diff".

These days we would probably encourage users to use the difftool
built-in feature rather than "diffall", but thank you for your
careful consideration against breaking external scripts.

Maybe we can submit a PR against the diffall repo mentioning
the backstory so that new users are pointed to the main tool.


> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> index 83bf52494c..68ff26a0f7 100644
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -403,14 +403,17 @@ get_merge_tool_path () {
>  }
>  
>  get_merge_tool () {
> +	not_guessed=true

Tiny nit; I find double-negatives hard to understand.  Maybe rename this
to "is_guessed" and flip the logic below so that we can keep the
variable named as a positive flag?


>  	# Check if a merge tool has been configured
> -	merge_tool=$(get_configured_merge_tool)
> +	merge_tool=$(get_configured_merge_tool $GIT_MERGETOOL_GUI)
>  	# Try to guess an appropriate merge tool if no tool has been set.
>  	if test -z "$merge_tool"
>  	then
>  		merge_tool=$(guess_merge_tool) || exit
> +		not_guessed=false
>  	fi
>  	echo "$merge_tool"
> +	test "$not_guessed" = true
>  }

-- 
David