difftool/mergetool: refactor commands to use git-mergetool--lib
Subsystems (2)
PATCH v6 14/14 difftool/mergetool: refactor commands to use git-mergetool--lib
This consolidates the common functionality from git-mergetool and git-difftool--helper into a single git-mergetool--lib scriptlet.
---
Simplified guess_merge_tool()'s tools= section.
.gitignore | 1 + Documentation/git-mergetool--lib.txt | 56 +++++ Makefile | 1 + git-difftool--helper.sh | 186 +---------------- git-mergetool--lib.sh | 378 ++++++++++++++++++++++++++++++++++ git-mergetool.sh | 224 ++------------------- 6 files changed, 458 insertions(+), 388 deletions(-) create mode 100644 Documentation/git-mergetool--lib.txt create mode 100644 git-mergetool--lib.sh
.gitignore +1 -0
@@ -80,6 +80,7 @@ git-merge-recursive git-merge-resolve git-merge-subtree git-mergetool +git-mergetool--lib git-mktag git-mktree git-name-rev
Documentation/git-mergetool--lib.txt new file +56 -0
56 lines not on this page · raw message
Makefile +1 -0
@@ -284,6 +284,7 @@ SCRIPT_SH += git-merge-octopus.sh SCRIPT_SH += git-merge-one-file.sh SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh +SCRIPT_SH += git-mergetool--lib.sh SCRIPT_SH += git-parse-remote.sh SCRIPT_SH += git-pull.sh SCRIPT_SH += git-quiltimport.sh
git-difftool--helper.sh +9 -177
210 lines not on this page · raw message
git-mergetool--lib.sh new file +378 -0
378 lines not on this page · raw message
git-mergetool.sh +13 -211
255 lines not on this page · raw message
Signature · 1 line
1.6.2.2.446.gfbdc
On Wed, Apr 08, 2009 at 12:17:20AM -0700, David Aguilar wrote:
Finally, I've got around to some git work...
Documentation/git-mergetool--lib.txt
Quoted 6 lines
Documentation/git-mergetool--lib.txt new file +0
-0
--- snip ---
Documentation/git-mergetool--lib.txt line 44
Quoted 8 lines
Documentation/git-mergetool--lib.txt new file +8
-0+ +run_merge_tool:: + launches a merge tool given the tool name and a true/false + flag to indicate whether a merge base is present. + '$merge_tool', '$merge_tool_path', and for custom commands, + '$merge_tool_cmd', must be defined prior to calling + run_merge_tool. Additionally, '$MERGED', '$LOCAL', '$REMOTE', + and '$BASE' must be defined for use by the merge tool.
Reading this function it doesn't look like the variable $merge_tool is actually used, only the first parameter which should be the same thing. Also, TOOL_MODE is used and is important so should probably be documented here instead.
git-mergetool--lib.sh
Quoted 5 lines
git-mergetool--lib.sh new file +0
-0
--- snip ---
Quoted 9 lines
git-mergetool--lib.sh new file +9
-0+get_merge_tool_path () { + # A merge tool has been set, so verify that it's valid. + if ! valid_tool "$merge_tool"; then + echo >&2 "Unknown merge tool $merge_tool" + exit 1 + fi + if diff_mode; then + merge_tool_path=$(git config difftool."$merge_tool".path) + fi
git-mergetool--lib.sh line 365
Quoted 10 lines
git-mergetool--lib.sh new file +10
-0+ if test -z "$merge_tool_path"; then + merge_tool_path=$(git config mergetool."$merge_tool".path) + fi + merge_tool_path="$(translate_merge_tool_path "$merge_tool" "$merge_tool_path")" + if test -z "$merge_tool_cmd" && ! type "$merge_tool_path" > /dev/null 2>&1; then + echo >&2 "The $TOOL_MODE tool $merge_tool is not available as '$merge_tool_path'" + exit 1 + fi + echo "$merge_tool_path" +}
I just wanted to double check that we supported finding tools in the path with merge.$tool.path unset (it should just work), so I had a quick play and got some really wierd results. Please tell me if just sourcing git-mergetool--lib isn't just going to work.
Quoted 1 line
From a non-X session:
$ git config -l | grep 'merge\.\?tool'; get_merge_tool; get_merge_tool_path
mergetool.p4merge.cmd=echo /"$BASE"/ /"$REMOTE"/ /"$LOCAL"/ /"$MERGED"/
merge tool candidates: kompare emerge vimdiff
vimdiff
vimQuoted 1 line
From an X session:
mergetool.p4merge.cmd=echo /"$BASE"/ /"$REMOTE"/ /"$LOCAL"/ /"$MERGED"/
merge tool candidates: meld opendiff kdiff3 tkdiff xxdiff kompare gvimdiff diffuse ecmerge emerge vimdiff kdiff3
vim
I'm not quite sure what's going on here.
git-mergetool.sh
Quoted 4 lines
git-mergetool.sh +0
-0
--- big snip to: @@ merge_file () {
git-mergetool.sh merge_file () { · line 179
Quoted 3 lines
git-mergetool.sh +3
-0+ present=false + base_present && + present=true
I'm not sure why, but from a style point of view, this seemed a bit inconsistent from the rest of mergetool and grated with me a bit.
I think I'd prefer
if base_present; then
present=false
else
present=true
fi
or even:
present=$(base_present && echo true || echo false)
Really, really minor stlye point, though.
Signature · 2 lines
Charles Bailey http://ccgi.hashpling.plus.com/blog/
Quoted 8 lines · Charles Bailey
git-mergetool.sh merge_file () { · line 179
Quoted 3 lines · David Aguilar
git-mergetool.sh +3
-0+ present=false + base_present && + present=trueI'm not sure why, but from a style point of view, this seemed a bit inconsistent from the rest of mergetool and grated with me a bit.
Quoted 7 lines
I think I'd prefer
if
base_present; then
present=false
else
present=true
fi
Although with 'true' and 'false' the corrent way around, obviously.
Quoted 5 lines
or even:
present=$(base_present && echo true || echo false)
Signature · 2 lines
Charles Bailey http://ccgi.hashpling.plus.com/blog/
Quoted 6 lines · Charles Bailey
On Wed, Apr 08, 2009 at 12:17:20AM -0700, David Aguilar wrote:
Finally, I've got around to some git work...
Review
Quoted 1 line
(quoted diff) +0
-0--- snip ---
Quoted 13 lines
Documentation/git-mergetool--lib.txt line 44
Quoted 8 lines
Documentation/git-mergetool--lib.txt new file +8
-0+ +run_merge_tool:: + launches a merge tool given the tool name and a true/false + flag to indicate whether a merge base is present. + '$merge_tool', '$merge_tool_path', and for custom commands, + '$merge_tool_cmd', must be defined prior to calling + run_merge_tool. Additionally, '$MERGED', '$LOCAL', '$REMOTE', + and '$BASE' must be defined for use by the merge tool.Reading this function it doesn't look like the variable $merge_tool is actually used, only the first parameter which should be the same thing. Also,
TOOL_MODEis used and is important so should probably be documented here instead.
Done.
My new patch further removes those pesky globals ;)
Quoted 22 lines
git-mergetool--lib.sh
Quoted 5 lines
git-mergetool--lib.sh new file +0
-0--- snip ---
Quoted 14 lines
git-mergetool--lib.sh new file +14
-0+get_merge_tool_path () { + # A merge tool has been set, so verify that it's valid. + if ! valid_tool "$merge_tool"; then + echo >&2 "Unknown merge tool $merge_tool" + exit 1 + fi + if diff_mode; then + merge_tool_path=$(git config difftool."$merge_tool".path) + fi + if test -z "$merge_tool_path"; then + merge_tool_path=$(git config mergetool."$merge_tool".path) + fi + merge_tool_path="$(translate_merge_tool_path "$merge_tool" "$merge_tool_path")" + if test -z "$merge_tool_cmd" && ! type "$merge_tool_path" > /dev/null 2>&1; then
Quoted 8 lines
git-mergetool--lib.sh line 365
Quoted 5 lines
git-mergetool--lib.sh new file +5
-0+ echo >&2 "The $TOOL_MODE tool $merge_tool is not available as '$merge_tool_path'" + exit 1 + fi + echo "$merge_tool_path" +}I just wanted to double check that we supported finding tools in the path with merge.$tool.path unset (it should just work), so I had a
mergetool.$tool.path
Quoted 11 lines
quick play and got some really wierd results. Please tell me if just sourcing git-mergetool--lib isn't just going to work.
From a non-X session:
$ git config -l | grep 'merge\.\?tool'; get_merge_tool; get_merge_tool_path mergetool.p4merge.cmd=echo /"$BASE"/ /"$REMOTE"/ /"$LOCAL"/ /"$MERGED"/ merge tool candidates: kompare emerge vimdiff vimdiff vim
Quoted 8 lines
From an X session:
mergetool.p4merge.cmd=echo /"$BASE"/ /"$REMOTE"/ /"$LOCAL"/ /"$MERGED"/
merge tool candidates: meld opendiff kdiff3 tkdiff xxdiff kompare gvimdiff diffuse ecmerge emerge vimdiff kdiff3
vimI'm not quite sure what's going on here.
mergetool.$tool.path does work (there's a test for that feature, though we only test difftool.$tool.path currently)
What you probably ran into was that get_merge_tool_path() had a side-effect of setting $merge_tool_path and thus would just return that value the 2nd time you ran it.
If you started from a fresh shell (instead of faking X11 by setting $DISPLAY) then it would behave correctly.
In any case, yes, it needs to be more robust, so I'm addressing that in:
"mergetool--lib: simplify API usage by removing more global variables" (patch on its way)
Quoted 9 lines
--- big snip to: @@
merge_file() {git-mergetool--lib.sh
Quoted 3 lines
git-mergetool--lib.sh new file +3
-0+ present=false + base_present && + present=trueI'm not sure why, but from a style point of view, this seemed a bit inconsistent from the rest of mergetool and grated with me a bit.
Quoted 7 lines
I think I'd prefer
if
base_present; then
present=false
else
present=true
fi
Definitely.
This was cleaned up as well.
In my patch get_merge_tool_path and get_merge_tool_cmd now take $1 as an optional argument since they can easily look up the $merge_tool themselves in lieu of a passed-in value.
I kept thinking of mergetool--lib from the POV of difftool and mergetool, but these changes are good since they make it more useful from a standalone POV.
Let me know what you think.
Signature · 1 line
David