mergetool-lib improvements for --tool-help
cover mergetool-lib improvements for --tool-help
I ran with John's idea and simplified a few more things so that the --tool-help output shows the correct results.
My final commit is dependent on John's commits but the other two could be picked up independently since they are general improvements.
This does add a few symlinks to the repo for the sake of simplicity; I'm not sure if this presents a problem for folks on other platforms.
The replacement of vim with vimdiff and symlinks simplifies things so that we can later auto-generate the list-of-all-tools for use by Documentation/. This was not previously possible due to the special-case for the vim tools which this series eliminates.
David Aguilar (3):
mergetools/vim: Remove redundant diff command
mergetools: Fix difftool/mergetool --tool-help listing for vim
mergetool--lib: Improve show_tool_help() output
John Keeping (4):
git-mergetool: move show_tool_help to mergetool--lib
git-mergetool: remove redundant assignment
git-mergetool: don't hardcode 'mergetool' in show_tool_help
git-difftool: use git-mergetool--lib for "--tool-help"
git-difftool.perl | 55 +++++----------------------------------
git-mergetool--lib.sh | 63 +++++++++++++++++++++++++++++++++++++++------
git-mergetool.sh | 37 --------------------------
mergetools/gvimdiff | 1 +
mergetools/gvimdiff2 | 1 +
mergetools/{vim => vimdiff} | 12 ++-------
mergetools/vimdiff2 | 1 +
7 files changed, 67 insertions(+), 103 deletions(-)
create mode 120000 mergetools/gvimdiff
create mode 120000 mergetools/gvimdiff2
rename mergetools/{vim => vimdiff} (68%)
create mode 120000 mergetools/vimdiff2Signature · 1 line
1.8.1.1.367.g22b1720.dirty
PATCH 1/7 git-mergetool: move show_tool_help to mergetool--lib
From: John Keeping <[email protected]>
This is the first step in unifying "git difftool --tool-help" and "git mergetool --tool-help".
--- git-mergetool--lib.sh | 37 +++++++++++++++++++++++++++++++++++++ git-mergetool.sh | 37 ------------------------------------- 2 files changed, 37 insertions(+), 37 deletions(-)
git-mergetool--lib.sh +37 -0
@@ -174,6 +174,43 @@ list_merge_tool_candidates () { esac } +show_tool_help () { + TOOL_MODE=merge + list_merge_tool_candidates + unavailable= available= LF=' +' + for i in $tools + do + merge_tool_path=$(translate_merge_tool_path "$i") + if type "$merge_tool_path" >/dev/null 2>&1 + then + available="$available$i$LF" + else + unavailable="$unavailable$i$LF" + fi + done + if test -n "$available" + then + echo "'git mergetool --tool=<tool>' may be set to one of the following:" + echo "$available" | sort | sed -e 's/^/ /' + else + echo "No suitable tool for 'git mergetool --tool=<tool>' found." + fi + if test -n "$unavailable" + then + echo + echo 'The following tools are valid, but not currently available:' + echo "$unavailable" | sort | sed -e 's/^/ /' + fi + if test -n "$unavailable$available" + then + echo + echo "Some of the tools listed above only work in a windowed" + echo "environment. If run in a terminal-only session, they will fail." + fi + exit 0 +} + guess_merge_tool () { list_merge_tool_candidates echo >&2 "merge tool candidates: $tools"
git-mergetool.sh +0 -37
@@ -315,43 +315,6 @@ merge_file () { return 0 } -show_tool_help () { - TOOL_MODE=merge - list_merge_tool_candidates - unavailable= available= LF=' -' - for i in $tools - do - merge_tool_path=$(translate_merge_tool_path "$i") - if type "$merge_tool_path" >/dev/null 2>&1 - then - available="$available$i$LF" - else - unavailable="$unavailable$i$LF" - fi - done - if test -n "$available" - then - echo "'git mergetool --tool=<tool>' may be set to one of the following:" - echo "$available" | sort | sed -e 's/^/ /' - else - echo "No suitable tool for 'git mergetool --tool=<tool>' found." - fi - if test -n "$unavailable" - then - echo - echo 'The following tools are valid, but not currently available:' - echo "$unavailable" | sort | sed -e 's/^/ /' - fi - if test -n "$unavailable$available" - then - echo - echo "Some of the tools listed above only work in a windowed" - echo "environment. If run in a terminal-only session, they will fail." - fi - exit 0 -} - prompt=$(git config --bool mergetool.prompt || echo true) while test $# != 0
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
PATCH 2/7 git-mergetool: remove redundant assignment
In reply to David AguilarFrom: John Keeping <[email protected]>
TOOL_MODE is set at the top of git-mergetool.sh so there is no need to set it again in show_tool_help. Removing this lets us re-use show_tool_help in git-difftool.
--- git-mergetool--lib.sh | 1 - 1 file changed, 1 deletion(-)
git-mergetool--lib.sh +0 -1
@@ -175,7 +175,6 @@ list_merge_tool_candidates () { } show_tool_help () { - TOOL_MODE=merge list_merge_tool_candidates unavailable= available= LF=' '
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
PATCH 3/7 git-mergetool: don't hardcode 'mergetool' in show_tool_help
In reply to David AguilarFrom: John Keeping <[email protected]>
When using show_tool_help from git-difftool we will want it to print "git difftool" not "git mergetool" so use "git ${TOOL_MODE}tool".
--- git-mergetool--lib.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
git-mergetool--lib.sh +4 -2
@@ -188,12 +188,14 @@ show_tool_help () { unavailable="$unavailable$i$LF" fi done + + cmd_name=${TOOL_MODE}tool if test -n "$available" then - echo "'git mergetool --tool=<tool>' may be set to one of the following:" + echo "'git $cmd_name --tool=<tool>' may be set to one of the following:" echo "$available" | sort | sed -e 's/^/ /' else - echo "No suitable tool for 'git mergetool --tool=<tool>' found." + echo "No suitable tool for 'git $cmd_name --tool=<tool>' found." fi if test -n "$unavailable" then
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
PATCH 4/7 git-difftool: use git-mergetool--lib for "--tool-help"
In reply to David AguilarFrom: John Keeping <[email protected]>
The "--tool-help" option to git-difftool currently displays incorrect output since it uses the names of the files in "$GIT_EXEC_PATH/mergetools/" rather than the list of command names in git-mergetool--lib.
Fix this by simply delegating the "--tool-help" argument to the show_tool_help function in git-mergetool--lib.
--- git-difftool.perl | 55 +++++++------------------------------------------------ 1 file changed, 7 insertions(+), 48 deletions(-)
git-difftool.perl +7 -48
@@ -59,57 +59,16 @@ sub find_worktree return $worktree; } -sub filter_tool_scripts -{ - my ($tools) = @_; - if (-d $_) { - if ($_ ne ".") { - # Ignore files in subdirectories - $File::Find::prune = 1; - } - } else { - if ((-f $_) && ($_ ne "defaults")) { - push(@$tools, $_); - } - } -} - sub print_tool_help { - my ($cmd, @found, @notfound, @tools); - my $gitpath = Git::exec_path(); - - find(sub { filter_tool_scripts(\@tools) }, "$gitpath/mergetools"); - - foreach my $tool (@tools) { - $cmd = "TOOL_MODE=diff"; - $cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"'; - $cmd .= " && get_merge_tool_path $tool >/dev/null 2>&1"; - $cmd .= " && can_diff >/dev/null 2>&1"; - if (system('sh', '-c', $cmd) == 0) { - push(@found, $tool); - } else { - push(@notfound, $tool); - } - } - - print << 'EOF'; -'git difftool --tool=<tool>' may be set to one of the following: -EOF - print "\t$_\n" for (sort(@found)); + my $cmd = 'TOOL_MODE=diff'; + $cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"'; + $cmd .= ' && show_tool_help'; - print << 'EOF'; - -The following tools are valid, but not currently available: -EOF - print "\t$_\n" for (sort(@notfound)); - - print << 'EOF'; - -NOTE: Some of the tools listed above only work in a windowed -environment. If run in a terminal-only session, they will fail. -EOF - exit(0); + # See the comment at the bottom of file_diff() for the reason behind + # using system() followed by exit() instead of exec(). + my $rc = system('sh', '-c', $cmd); + exit($rc | ($rc >> 8)); } sub exit_cleanup
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
PATCH 5/7 mergetools/vim: Remove redundant diff command
In reply to David Aguilarvimdiff and vimdiff2 differ only by their merge command so remove the logic in the diff command since it's not actually needed.
--- mergetools/vim | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
mergetools/vim +2 -10
@@ -1,14 +1,6 @@ diff_cmd () { - case "$1" in - gvimdiff|vimdiff) - "$merge_tool_path" -R -f -d \ - -c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE" - ;; - gvimdiff2|vimdiff2) - "$merge_tool_path" -R -f -d \ - -c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE" - ;; - esac + "$merge_tool_path" -R -f -d \ + -c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE" } merge_cmd () {
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
PATCH 6/7 mergetools: Fix difftool/mergetool --tool-help listing for vim
In reply to David Aguilar"git difftool --tool-help" and "git mergetool --tool-help" incorreclty list "vim" as being an unavailable tool. This is because they attempt to find a tool named according to the mergetool scriptlet instead of the Git- recognized tool name.
vimdiff, vimdiff2, gvimdiff, and gvimdiff2 are all provided by the "vim" scriptlet. This required git-mergetool--lib to special-case it when setting up the tool.
Remove the exception for "vim" and allow the scriptlets to be found naturally by using symlinks to a single "vimdiff" scriptlet. This causes the --tool-help option to correctly list vimdiff, vimdiff2, gvimdiff, and gvimdiff2 in its output.
---
git-mergetool--lib.sh | 9 +--------
mergetools/gvimdiff | 1 +
mergetools/gvimdiff2 | 1 +
mergetools/{vim => vimdiff} | 0
mergetools/vimdiff2 | 1 +
5 files changed, 4 insertions(+), 8 deletions(-)
create mode 120000 mergetools/gvimdiff
create mode 120000 mergetools/gvimdiff2
rename mergetools/{vim => vimdiff} (100%)
create mode 120000 mergetools/vimdiff2git-mergetool--lib.sh +1 -8
@@ -44,14 +44,7 @@ valid_tool () { } setup_tool () { - case "$1" in - vim*|gvim*) - tool=vim - ;; - *) - tool="$1" - ;; - esac + tool="$1" mergetools="$(git --exec-path)/mergetools" # Load the default definitions
mergetools/gvimdiff new file +1 -0
@@ -0,0 +1 @@ +vimdiff
mergetools/gvimdiff2 new file +1 -0
@@ -0,0 +1 @@ +vimdiff
mergetools/vimdiff renamed from mergetools/vim +0 -0
mergetools/vimdiff2 new file +1 -0
@@ -0,0 +1 @@ +vimdiff
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
Quoted 4 lines · David Aguilar
"git difftool --tool-help" and "git mergetool --tool-help" incorreclty list "vim" as being an unavailable tool. This is because they attempt to find a tool named according to the mergetool scriptlet instead of the Git- recognized tool name.
Actually, after my patches both git-difftool and git-mergetool get this right since list_merge_tool_candidates lists vimdiff and gvimdiff.
Quoted 6 lines
vimdiff, vimdiff2, gvimdiff, and gvimdiff2 are all provided by the "vim" scriptlet. This required git-mergetool--lib to special-case it when setting up the tool.
Remove the exception for "vim" and allow the scriptlets to be found naturally by using symlinks to a single "vimdiff" scriptlet.
I wonder if it would be better to make these single-line scripts instead of symlinks:
. "$MERGE_TOOLS_DIR"/vimdiff
where we make git-mergetool--lib.sh export:
MERGE_TOOLS_DIR=$(git --exec-path)/mergetools
John
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
Quoted 16 lines · John Keeping
Quoted 4 lines · David Aguilar
"git difftool --tool-help" and "git mergetool --tool-help" incorreclty list "vim" as being an unavailable tool. This is because they attempt to find a tool named according to the mergetool scriptlet instead of the Git- recognized tool name.
Actually, after my patches both git-difftool and git-mergetool get this right since
list_merge_tool_candidateslists vimdiff and gvimdiff.Quoted 6 lines
vimdiff, vimdiff2, gvimdiff, and gvimdiff2 are all provided by the "vim" scriptlet. This required git-mergetool--lib to special-case it when setting up the tool.
Remove the exception for "vim" and allow the scriptlets to be found naturally by using symlinks to a single "vimdiff" scriptlet.
Quoted 8 lines
I wonder if it would be better to make these single-line scripts instead of symlinks:
. "$MERGE_TOOLS_DIR"/vimdiff
where we make
git-mergetool--lib.shexport:MERGE_TOOLS_DIR=$(git --exec-path)/mergetools
That sounds like the way to go.
Signature · 1 line
David
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
In reply to David AguilarQuoted 2 lines · David Aguilar
Remove the exception for "vim" and allow the scriptlets to be found naturally by using symlinks to a single "vimdiff" scriptlet. This
I guess that won't work on platforms where Git does not support symlinks, then, like Windows. But Windows has (g)vimdiff, so loosing these on that platform would not be so nice.
Signature · 1 line
Sebastian Schuberth
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
Quoted 9 lines · Sebastian Schuberth
Quoted 2 lines · David Aguilar
Remove the exception for "vim" and allow the scriptlets to be found naturally by using symlinks to a single "vimdiff" scriptlet. This
I guess that won't work on platforms where Git does not support symlinks, then, like Windows. But Windows has (g)vimdiff, so loosing these on that platform would not be so nice.
I thought Git did something sensible there like create a normal file?
If not then I was thinking we could add a provides_tools() function that each scriptlet could supply.
Signature · 1 line
David
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
Quoted 1 line · David Aguilar
I thought Git did something sensible there like create a normal file?
It does not. Also see my answer over here:
http://stackoverflow.com/questions/11412028/git-not-storing-symlink-as-a-symlink-on-windows/11412341#11412341
Quoted 2 lines
If not then I was thinking we could add a
provides_tools()function that each scriptlet could supply.
Or maybe simply introduce scriptlets that do nothing but include / inline another scriptlet?
Signature · 1 line
Sebastian Schuberth
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
Quoted 4 lines · Sebastian Schuberth
Quoted 1 line
I thought Git did something sensible there like create a normal file?
It does not. Also see my answer over here:
http://stackoverflow.com/questions/11412028/git-not-storing-symlink-as-a-symlink-on-windows/11412341#11412341
This one might be the even more appropriate answer:
http://stackoverflow.com/questions/11662868/what-happens-when-i-clone-a-repository-with-symlinks-on-windows/11664406#11664406
Signature · 1 line
Sebastian Schuberth
PATCH 7/7 mergetool--lib: Improve show_tool_help() output
In reply to David AguilarCheck the can_diff and can_merge functions before deciding whether to add the tool to the available/unavailable lists. This makes --tool-help context- sensitive so that "git mergetool --tool-help" displays merge tools only and "git difftool --tool-help" displays diff tools only.
--- git-mergetool--lib.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
git-mergetool--lib.sh +21 -5
@@ -168,17 +168,33 @@ list_merge_tool_candidates () { } show_tool_help () { - list_merge_tool_candidates unavailable= available= LF=' ' - for i in $tools + + scriptlets="$(git --exec-path)"/mergetools + for i in "$scriptlets"/* do - merge_tool_path=$(translate_merge_tool_path "$i") + . "$scriptlets"/defaults + . "$i" + + tool="$(basename "$i")" + if test "$tool" = "defaults" + then + continue + elif merge_mode && ! can_merge + then + continue + elif diff_mode && ! can_diff + then + continue + fi + + merge_tool_path=$(translate_merge_tool_path "$tool") if type "$merge_tool_path" >/dev/null 2>&1 then - available="$available$i$LF" + available="$available$tool$LF" else - unavailable="$unavailable$i$LF" + unavailable="$unavailable$tool$LF" fi done
Signature · 1 line
1.8.1.1.367.g22b1720.dirty
Re: [PATCH 6/7] mergetools: Fix difftool/mergetool --tool-help listing for vim
In reply to David AguilarQuoted 20 lines · David Aguilar
Quoted 19 lines · John Keeping
Quoted 4 lines · David Aguilar
"git difftool --tool-help" and "git mergetool --tool-help" incorreclty list "vim" as being an unavailable tool. This is because they attempt to find a tool named according to the mergetool scriptlet instead of the Git- recognized tool name.
Actually, after my patches both git-difftool and git-mergetool get this right since
list_merge_tool_candidateslists vimdiff and gvimdiff.Quoted 6 lines
vimdiff, vimdiff2, gvimdiff, and gvimdiff2 are all provided by the "vim" scriptlet. This required git-mergetool--lib to special-case it when setting up the tool.
Remove the exception for "vim" and allow the scriptlets to be found naturally by using symlinks to a single "vimdiff" scriptlet.
I wonder if it would be better to make these single-line scripts instead of symlinks:
Quoted 7 lines
Quoted 5 lines
. "$MERGE_TOOLS_DIR"/vimdiff
where we make
git-mergetool--lib.shexport:MERGE_TOOLS_DIR=$(git --exec-path)/mergetoolsThat sounds like the way to go.
Yup, I'll expect a reroll of this one and possibly the next one (I haven't read yet).
1-5/7 looked all very sensible.
Thanks.
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
In reply to David AguilarQuoted 4 lines · David Aguilar
Check the
can_diffandcan_mergefunctions before deciding whether to add the tool to the available/unavailable lists. This makes --tool-help context- sensitive so that "git mergetool --tool-help" displays merge tools only and "git difftool --tool-help" displays diff tools only.
This log message is misleading - the existing code in list_merge_tool_candidates already filters the tools like this, so the change is more:
mergetool--lib: don't use a hardcoded list for "--tool-help"
Instead of using a list of tools in list_merge_tool_candidates, list the available scriptlets and query each of those to know whether it applies to diff mode and/or merge mode.
guess_merge_tool still relies on list_merge_tool_candidates so we can't remove that function now.
The patch seems to do the right thing, although I have a couple of minor nits...
Quoted 16 lines
Signed-off-by David Aguilar <[email protected]>--- git-mergetool--lib.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)git-mergetool--lib.sh +0
-1@@ -168,17 +168,33 @@ list_merge_tool_candidates () { } show_tool_help () { - list_merge_tool_candidates unavailable= available= LF=' '
git-mergetool--lib.sh list_merge_tool_candidates () { · line 180
Quoted 10 lines
git-mergetool--lib.sh +7
-2- for i in $tools + + scriptlets="$(git --exec-path)"/mergetools + for i in "$scriptlets"/* do - merge_tool_path=$(translate_merge_tool_path "$i") + . "$scriptlets"/defaults + . "$i" + + tool="$(basename "$i")"
Quotes are unnecessary here.
git-mergetool--lib.sh list_merge_tool_candidates () { · line 190
Quoted 10 lines
git-mergetool--lib.sh +10
-0+ if test "$tool" = "defaults" + then + continue + elif merge_mode && ! can_merge + then + continue + elif diff_mode && ! can_diff + then + continue + fi
Would this be better as:
test "$tool" = "defaults" && continue
can_merge || ! merge_mode || continue
can_diff || ! diff_mode || continueor is that a bit too concise?
I'd prefer to see two separate if statements either way since the "test $tool = defaults" case is different from the "does it apply to the current mode?" case. The "$tool = defaults" case could even move to the top of the loop.
Quoted 10 lines
git-mergetool--lib.sh +3
-2+ merge_tool_path=$(translate_merge_tool_path "$tool") if type "$merge_tool_path" >/dev/null 2>&1 then - available="$available$i$LF" + available="$available$tool$LF" else - unavailable="$unavailable$i$LF" + unavailable="$unavailable$tool$LF" fi done
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 70 lines · John Keeping
Quoted 4 lines · David Aguilar
Check the
can_diffandcan_mergefunctions before deciding whether to add the tool to the available/unavailable lists. This makes --tool-help context- sensitive so that "git mergetool --tool-help" displays merge tools only and "git difftool --tool-help" displays diff tools only.This log message is misleading - the existing code in
list_merge_tool_candidatesalready filters the tools like this, so the change is more:mergetool--lib: don't use a hardcoded list for "--tool-help"
Instead of using a list of tools in
list_merge_tool_candidates, list the available scriptlets and query each of those to know whether it applies to diff mode and/or merge mode.
guess_merge_toolstill relies onlist_merge_tool_candidatesso we can't remove that function now.The patch seems to do the right thing, although I have a couple of minor nits...
Quoted 16 lines
Signed-off-by David Aguilar <[email protected]>--- git-mergetool--lib.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)git-mergetool--lib.sh +0
-1@@ -168,17 +168,33 @@ list_merge_tool_candidates () { } show_tool_help () { - list_merge_tool_candidates unavailable= available= LF=' 'git-mergetool--lib.sh list_merge_tool_candidates () { · line 180
Quoted 10 lines
git-mergetool--lib.sh +7
-2- for i in $tools + + scriptlets="$(git --exec-path)"/mergetools + for i in "$scriptlets"/* do - merge_tool_path=$(translate_merge_tool_path "$i") + . "$scriptlets"/defaults + . "$i" + + tool="$(basename "$i")"Quotes are unnecessary here.
git-mergetool--lib.sh list_merge_tool_candidates () { · line 190
Quoted 10 lines
git-mergetool--lib.sh +10
-0+ if test "$tool" = "defaults" + then + continue + elif merge_mode && ! can_merge + then + continue + elif diff_mode && ! can_diff + then + continue + fiWould this be better as:
test "$tool" = "defaults" && continue can_merge || ! merge_mode || continue can_diff || ! diff_mode || continue
Quoted 8 lines
or is that a bit too concise?
I'd prefer to see two separate if statements either way since the "test $tool = defaults" case is different from the "does it apply to the current mode?" case. The "$tool = defaults" case could even move to the top of the loop.
git-mergetool--lib.sh list_merge_tool_candidates () { · line 192
Quoted 1 line
git-mergetool--lib.sh +1
-0+ merge_tool_path=$(translate_merge_tool_path "$tool")
Actually, can we just change all of the above part of the loop to:
test "$tool" = defaults && continue merge_tool_path=$( setup_tool "$tool" >/dev/null 2>&1 && translate_merge_tool_path "$tool" ) || continue
Quoted 13 lines
git-mergetool--lib.sh list_merge_tool_candidates () { · line 199
Quoted 9 lines
git-mergetool--lib.sh +2
-2if type "$merge_tool_path" >/dev/null 2>&1 then - available="$available$i$LF" + available="$available$tool$LF" else - unavailable="$unavailable$i$LF" + unavailable="$unavailable$tool$LF" fi done--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 8 lines · John Keeping
Actually, can we just change all of the above part of the loop to:
test "$tool" = defaults && continue merge_tool_path=$( setup_tool "$tool" >/dev/null 2>&1 && translate_merge_tool_path "$tool" ) || continue
Meaning "setup_tool ought to know which mode we are in and should fail if we are in merge mode and it does not support merging"? That line of reasoning makes tons of sense to me, compared to this script implementing that logic for these scriptlets.
How/when does translate_merge_tool_path fail?
Quoted 14 lines
Quoted 14 lines
git-mergetool--lib.sh list_merge_tool_candidates () { · line 199
Quoted 10 lines
git-mergetool--lib.sh +2
-2if type "$merge_tool_path" >/dev/null 2>&1 then - available="$available$i$LF" + available="$available$tool$LF" else - unavailable="$unavailable$i$LF" + unavailable="$unavailable$tool$LF" fi done--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · John Keeping
Actually, can we just change all of the above part of the loop to:
test "$tool" = defaults && continue merge_tool_path=$( setup_tool "$tool" >/dev/null 2>&1 && translate_merge_tool_path "$tool" ) || continue
Quoted 4 lines
Meaning "
setup_toolought to know which mode we are in and should fail if we are in merge mode and it does not support merging"? That line of reasoning makes tons of sense to me, compared to this script implementing that logic for these scriptlets.
Yes, that's part of what setup_tool does. It actually calls "exit" if the "mode? && can_mode" test fails, which is why we need to call it in the subshell.
I think this would get even better if we add a preparatory patch like this, so we can just call setup_tool and then set merge_tool_path:
-- >8 --
git-mergetool--lib.sh +3 -3
@@ -67,11 +67,11 @@ setup_tool () { if merge_mode && ! can_merge then echo "error: '$tool' can not be used to resolve merges" >&2 - exit 1 + return 1 elif diff_mode && ! can_diff then echo "error: '$tool' can only be used to resolve merges" >&2 - exit 1 + return 1 fi return 0 }
@@ -100,7 +100,7 @@ run_merge_tool () { status=0 # Bring tool-specific functions into scope - setup_tool "$1" + setup_tool "$1" || return if merge_mode then
-- 8< --
Quoted 1 line
How/when does
translate_merge_tool_pathfail?
It doesn't - the "|| continue" is to catch errors from setup_tool.
John
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 56 lines · John Keeping
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · John Keeping
Actually, can we just change all of the above part of the loop to:
test "$tool" = defaults && continue merge_tool_path=$( setup_tool "$tool" >/dev/null 2>&1 && translate_merge_tool_path "$tool" ) || continueQuoted 4 lines
Meaning "
setup_toolought to know which mode we are in and should fail if we are in merge mode and it does not support merging"? That line of reasoning makes tons of sense to me, compared to this script implementing that logic for these scriptlets.Yes, that's part of what
setup_tooldoes. It actually calls "exit" if the "mode? &&can_mode" test fails, which is why we need to call it in the subshell.I think this would get even better if we add a preparatory patch like this, so we can just call
setup_tooland then setmerge_tool_path:-- >8 --
git-mergetool--lib.sh +3
-4@@ -67,11 +67,11 @@ setup_tool () { if merge_mode && ! can_merge then echo "error: '$tool' can not be used to resolve merges" >&2 - exit 1 + return 1 elif diff_mode && ! can_diff then echo "error: '$tool' can only be used to resolve merges" >&2 - exit 1 + return 1 fi return 0 }@@ -100,7 +100,7 @@ run_merge_tool () { status=0 # Bring tool-specific functions into scope - setup_tool "$1" + setup_tool "$1" || return if merge_mode then -- 8< --
Quoted 3 lines
Quoted 1 line
How/when does
translate_merge_tool_pathfail?It doesn't - the "|| continue" is to catch errors from
setup_tool.
Ugh.
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 56 lines · Junio C Hamano
Quoted 54 lines · John Keeping
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · John Keeping
Actually, can we just change all of the above part of the loop to:
test "$tool" = defaults && continue merge_tool_path=$( setup_tool "$tool" >/dev/null 2>&1 && translate_merge_tool_path "$tool" ) || continueQuoted 4 lines
Meaning "
setup_toolought to know which mode we are in and should fail if we are in merge mode and it does not support merging"? That line of reasoning makes tons of sense to me, compared to this script implementing that logic for these scriptlets.Yes, that's part of what
setup_tooldoes. It actually calls "exit" if the "mode? &&can_mode" test fails, which is why we need to call it in the subshell.I think this would get even better if we add a preparatory patch like this, so we can just call
setup_tooland then setmerge_tool_path:-- >8 --
git-mergetool--lib.sh +3
-3@@ -67,11 +67,11 @@ setup_tool () { if merge_mode && ! can_merge then echo "error: '$tool' can not be used to resolve merges" >&2 - exit 1 + return 1 elif diff_mode && ! can_diff then echo "error: '$tool' can only be used to resolve merges" >&2 - exit 1 + return 1 fi return 0 }@@ -100,7 +100,7 @@ run_merge_tool () { status=0 # Bring tool-specific functions into scope - setup_tool "$1" + setup_tool "$1" || return if merge_mode then
Quoted 7 lines
Quoted 5 lines
-- 8< --
Quoted 1 line
How/when does
translate_merge_tool_pathfail?It doesn't - the "|| continue" is to catch errors from
setup_tool.Ugh.
Is that targeted at my suggestion at the top of this email or calling exit in setup_tool?
With the patch above, the block of code at the top becomes:
test "$tool" = defaults && continue
setup_tool "$tool" 2>/dev/null || continue merge_tool_path=$(translate_merge_tool_path "$tool")
which IMHO is pretty readable.
John
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 6 lines · John Keeping
Quoted 3 lines
Quoted 1 line
It doesn't - the "|| continue" is to catch errors from
setup_tool.Ugh.
Is that targeted at my suggestion at the top of this email or calling exit in
setup_tool?
At the fact that you had to go a convoluted route because you cannot just run setup_tool in subshell and do translate_merge_tool_path after that, because the latter needs to look at the shell variable the former sets.
Quoted 8 lines
With the patch above, the block of code at the top becomes:
(quoted diff) +0
-0test "$tool" = defaults && continue setup_tool "$tool" 2>/dev/null || continue merge_tool_path=$(translate_merge_tool_path "$tool")which IMHO is pretty readable.
Of course it is. The current callers of setup_tool may need some adjustments, but that should be fairly trivial, I hope.
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
Quoted 5 lines · Junio C Hamano
Quoted 4 lines · John Keeping
With the patch above, the block of code at the top becomes:
test "$tool" = defaults && continue
Quoted 7 lines
Quoted 4 lines
(quoted diff) +0
-0setup_tool "$tool" 2>/dev/null || continue merge_tool_path=$(translate_merge_tool_path "$tool")which IMHO is pretty readable.
Of course it is. The current callers of
setup_toolmay need some adjustments, but that should be fairly trivial, I hope.
There are only two and one of them already seems like it doesn't want the command to cause the script to exit.
David, can you incorporate the following two patches when you re-roll? Your original 7/7 with the change above will want to build on 8/7.
John
[PATCH 8/7] mergetool--lib: don't call "exit" in setup_tool
This will make it easier to use setup_tool in places where we expect that the selected tool will not support the current mode.
--- git-mergetool--lib.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
git-mergetool--lib.sh +3 -3
@@ -67,11 +67,11 @@ setup_tool () { if merge_mode && ! can_merge then echo "error: '$tool' can not be used to resolve merges" >&2 - exit 1 + return 1 elif diff_mode && ! can_diff then echo "error: '$tool' can only be used to resolve merges" >&2 - exit 1 + return 1 fi return 0 }
@@ -100,7 +100,7 @@ run_merge_tool () { status=0 # Bring tool-specific functions into scope - setup_tool "$1" + setup_tool "$1" || return if merge_mode then
Signature · 1 line
1.8.1
Re: [PATCH 8/7] mergetool--lib: don't call "exit" in setup_tool
Applying this one on top of 1/7 thru 5/7 and 7/7 seems to break t7610 rather badly.
--- >8 ------ >8 ------ >8 ------ >8 ------ >8 ------ >8 ---
...
ok 1 - setup
expecting success:
git checkout -b test1 branch1 &&
git submodule update -N &&
test_must_fail git merge master >/dev/null 2>&1 &&
( yes "" | git mergetool both >/dev/null 2>&1 ) &&
( yes "" | git mergetool file1 file1 ) &&
( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) &&
( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file11 >/dev/null 2>&1 ) &&
( yes "d" | git mergetool file12 >/dev/null 2>&1 ) &&
( yes "l" | git mergetool submod >/dev/null 2>&1 ) &&
test "$(cat file1)" = "master updated" &&
test "$(cat file2)" = "master new" &&
test "$(cat subdir/file3)" = "master new sub" &&
test "$(cat submod/bar)" = "branch1 submodule" &&
git commit -m "branch1 resolved with mergetool"M submod
Switched to a new branch 'test1'
Submodule path 'submod': checked out '39c7f044ed2e6a9cebd5266529badd181c8762b5' not ok - 2 custom mergetool
#
# git checkout -b test1 branch1 && # git submodule update -N && # test_must_fail git merge master >/dev/null 2>&1 && # ( yes "" | git mergetool both >/dev/null 2>&1 ) && # ( yes "" | git mergetool file1 file1 ) && # ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && # ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && # ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && # ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && # ( yes "l" | git mergetool submod >/dev/null 2>&1 ) && # test "$(cat file1)" = "master updated" && # test "$(cat file2)" = "master new" && # test "$(cat subdir/file3)" = "master new sub" && # test "$(cat submod/bar)" = "branch1 submodule" && # git commit -m "branch1 resolved with mergetool"
#
--- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---
Due to ">dev/null 2>&1", all of the error clues are hidden, and I didn't dig further to see which one was failing (this is why tests shouldn't do these in general).
PATCH v2 1/2 mergetool--lib: don't call "exit" in setup_tool
This will make it easier to use setup_tool in places where we expect that the selected tool will not support the current mode.
---
Quoted 2 lines · Junio C Hamano
Applying this one on top of 1/7 thru 5/7 and 7/7 seems to break t7610 rather badly.
Sorry about that. The 'setup_tool' function should really be called 'setup_builtin_tool' - it isn't necessary when a custom mergetool is configured and will return 1 when called with an argument that isn't a builtin tool from $GIT_EXEC_PATH/mergetools.
The change is the second hunk below which now wraps the call to setup_tool in an if block as well as adding the "|| return".
git-mergetool--lib.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
git-mergetool--lib.sh +6 -3
@@ -67,11 +67,11 @@ setup_tool () { if merge_mode && ! can_merge then echo "error: '$tool' can not be used to resolve merges" >&2 - exit 1 + return 1 elif diff_mode && ! can_diff then echo "error: '$tool' can only be used to resolve merges" >&2 - exit 1 + return 1 fi return 0 }
@@ -100,7 +100,10 @@ run_merge_tool () { status=0 # Bring tool-specific functions into scope - setup_tool "$1" + if test -z "$merge_tool_path" + then + setup_tool "$1" || return + fi if merge_mode then
Signature · 1 line
1.8.1.1.367.ga9c3dd4.dirty
PATCH v3 1/2 mergetool--lib: don't call "exit" in setup_tool
This will make it easier to use setup_tool in places where we expect that the selected tool will not support the current mode.
We need to introduce a new return code for setup_tool to differentiate between the case of "the selected tool is invalid" and "the selected tool is not a built-in" since we must call setup_tool when a custom 'merge.<tool>.path' is configured for a built-in tool but avoid failing when the configured tool is not a built-in.
---
Quoted 11 lines · Junio C Hamano
Quoted 2 lines
Applying this one on top of 1/7 thru 5/7 and 7/7 seems to break t7610 rather badly.
Sorry about that. The '
setup_tool' function should really be called 'setup_builtin_tool' - it isn't necessary when a custom mergetool is configured and will return 1 when called with an argument that isn't a builtin tool from $GIT_EXEC_PATH/mergetools.The change is the second hunk below which now wraps the call to
setup_toolin an if block as well as adding the "|| return".
Now that I've run the entire test suite, that still wasn't correct since it did not correctly handle the case where the user overrides the path for one of the built-in mergetools.
git-mergetool--lib.sh | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
git-mergetool--lib.sh +20 -3
@@ -58,7 +58,11 @@ setup_tool () { . "$mergetools/defaults" if ! test -f "$mergetools/$tool" then - return 1 + # Use a special return code for this case since we want to + # source "defaults" even when an explicit tool path is + # configured since the user can use that to override the + # default path in the scriptlet. + return 2 fi # Load the redefined functions
@@ -67,11 +71,11 @@ setup_tool () { if merge_mode && ! can_merge then echo "error: '$tool' can not be used to resolve merges" >&2 - exit 1 + return 1 elif diff_mode && ! can_diff then echo "error: '$tool' can only be used to resolve merges" >&2 - exit 1 + return 1 fi return 0 }
@@ -101,6 +105,19 @@ run_merge_tool () { # Bring tool-specific functions into scope setup_tool "$1" + exitcode=$? + case $exitcode in + 0) + : + ;; + 2) + # The configured tool is not a built-in tool. + test -n "$merge_tool_path" || return 1 + ;; + *) + return $exitcode + ;; + esac if merge_mode then
Signature · 1 line
1.8.1
Re: [PATCH 8/7] mergetool--lib: don't call "exit" in setup_tool
In reply to Junio C HamanoQuoted 2 lines · Junio C Hamano
Applying this one on top of 1/7 thru 5/7 and 7/7 seems to break t7610 rather badly.
I just sent a replacement for the vim/symlink issue stuff. I tried to keep the patch small. John, can you rebase this patch on top of it?
Quoted 47 lines
--- >8 ------ >8 ------ >8 ------ >8 ------ >8 ------ >8 ---
...
ok 1 - setupexpecting success:
git checkout -b test1 branch1 && git submodule update -N && test_must_fail git merge master >/dev/null 2>&1 && ( yes "" | git mergetool both >/dev/null 2>&1 ) && ( yes "" | git mergetool file1 file1 ) && ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod >/dev/null 2>&1 ) && test "$(cat file1)" = "master updated" && test "$(cat file2)" = "master new" && test "$(cat subdir/file3)" = "master new sub" && test "$(cat submod/bar)" = "branch1 submodule" && git commit -m "branch1 resolved with mergetool"M submod
Switched to a new branch 'test1'
Submodule path 'submod': checked out '39c7f044ed2e6a9cebd5266529badd181c8762b5' not ok - 2 custom mergetool
## git checkout -b test1 branch1 && # git submodule update -N && # test_must_fail git merge master >/dev/null 2>&1 && # ( yes "" | git mergetool both >/dev/null 2>&1 ) && # ( yes "" | git mergetool file1 file1 ) && # ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && # ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && # ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && # ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && # ( yes "l" | git mergetool submod >/dev/null 2>&1 ) && # test "$(cat file1)" = "master updated" && # test "$(cat file2)" = "master new" && # test "$(cat subdir/file3)" = "master new sub" && # test "$(cat submod/bar)" = "branch1 submodule" && # git commit -m "branch1 resolved with mergetool"#
--- 8< ------ 8< ------ 8< ------ 8< ------ 8< ------ 8< ---Due to ">dev/null 2>&1", all of the error clues are hidden, and I didn't dig further to see which one was failing (this is why tests shouldn't do these in general).
Signature · 1 line
David
[PATCH 9/7] mergetool--lib: fix path lookup in guess_merge_tool
In reply to John Keepingguess_merge_tool calls translate_merge_tool_path in order to get the correct name of the tool to check whether it can be found on the user's system. But this function is designed to be overridden by tool scriptlets so it does nothing if the relevant scriptlet has not been sourced.
Fix this by calling setup_tool before doing anything.
--- git-mergetool--lib.sh | 1 + 1 file changed, 1 insertion(+)
git-mergetool--lib.sh +1 -0
@@ -219,6 +219,7 @@ guess_merge_tool () { # Loop over each candidate and stop when a valid merge tool is found. for i in $tools do + setup_tool "$i" 2>&1 || continue merge_tool_path="$(translate_merge_tool_path "$i")" if type "$merge_tool_path" >/dev/null 2>&1 then
Signature · 1 line
1.8.1
Re: [PATCH 7/7] mergetool--lib: Improve show_tool_help() output
In reply to John KeepingQuoted 3 lines · John Keeping
git-mergetool--lib.sh list_merge_tool_candidates () { · line 180
Quoted 1 line
git-mergetool--lib.sh +1
-0+ tool="$(basename "$i")"Quotes are unnecessary here.
Yeah, the outer quotes aren't needed; the inner ones are.
Quoted 13 lines
git-mergetool--lib.sh list_merge_tool_candidates () { · line 190
Quoted 10 lines
git-mergetool--lib.sh +10
-0+ if test "$tool" = "defaults" + then + continue + elif merge_mode && ! can_merge + then + continue + elif diff_mode && ! can_diff + then + continue + fiWould this be better as:
Quoted 6 lines
test "$tool" = "defaults" && continue can_merge || ! merge_mode || continue can_diff || ! diff_mode || continueor is that a bit too concise?
It is beyond "too concise"; it is unreadable, and more importantly, the latter two lines are illogical (why do you even ask if it can be used for merging, before asking merge_mode to see if the answer to that question matters to you?)