Re: [PATCH] mergetool: support absolute paths to tools by git config merge.<tool>path

Previous thread: none

Next thread: confused about a conflict during octopus merging by martin f krafft on Monday, October 8, 2007 - 5:31 pm. (3 messages)
From: Steffen Prohaska
Date: Monday, October 8, 2007 - 2:22 pm

This commit adds a mechanism to provide absolute paths to the
commands called by 'git mergetool'. A path can be specified
in the configuation variable merge.&lt;toolname&gt;path.

This mechanism is especially useful on Windows, where external
programs are unlikely to be in the path.

Signed-off-by: Steffen Prohaska &lt;prohaska@zib.de&gt;
---
 Documentation/git-mergetool.txt |    5 ++
 git-mergetool.sh                |   81 ++++++++++++++++++++++-----------------
 2 files changed, 51 insertions(+), 35 deletions(-)

diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index 6c32c6d..6b97aaa 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -31,6 +31,11 @@ If a merge resolution program is not specified, 'git mergetool'
 will use the configuration variable merge.tool.  If the
 configuration variable merge.tool is not set, 'git mergetool'
 will pick a suitable default.
++
+You can explicitly provide a full path to the tool by setting the
+configuration variable merge.&lt;tool&gt;path. For example, you
+can configure the absolute path to kdiff3 by setting merge.kdiff3path.
+Otherise, 'git mergetool' assumes the tool is available in PATH.
 
 Author
 ------
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 9f4f313..7f6c16f 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -192,10 +192,10 @@ merge_file () {
     case &quot;$merge_tool&quot; in
 	kdiff3)
 	    if base_present ; then
-		(kdiff3 --auto --L1 &quot;$path (Base)&quot; --L2 &quot;$path (Local)&quot; --L3 &quot;$path (Remote)&quot; \
+		(&quot;$merge_tool_path&quot; --auto --L1 &quot;$path (Base)&quot; --L2 &quot;$path (Local)&quot; --L3 &quot;$path (Remote)&quot; \
 		    -o &quot;$path&quot; -- &quot;$BASE&quot; &quot;$LOCAL&quot; &quot;$REMOTE&quot; &gt; /dev/null 2&gt;&amp;1)
 	    else
-		(kdiff3 --auto --L1 &quot;$path (Local)&quot; --L2 &quot;$path (Remote)&quot; \
+		(&quot;$merge_tool_path&quot; --auto --L1 &quot;$path (Local)&quot; --L2 &quot;$path (Remote)&quot; \
 		    -o &quot;$path&quot; -- &quot;$LOCAL&quot; &quot;$REMOTE&quot; &gt; /dev/null 2&gt;&amp;1)
 	    fi
 	    status=$?
@@ -203,35 +203,35 @@ merge_file () {
 	    ;;
 	tkdiff)
 	    if ...
From: Steffen Prohaska
Date: Monday, October 8, 2007 - 2:22 pm

Add support for ECMerge available from
http://www.elliecomputing.com/Products/merge_overview.asp

Signed-off-by: Steffen Prohaska &lt;prohaska@zib.de&gt;
---
 Documentation/git-mergetool.txt |    2 +-
 git-mergetool.sh                |   12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index 6b97aaa..ece7718 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -25,7 +25,7 @@ OPTIONS
 -t or --tool=&lt;tool&gt;::
 	Use the merge resolution program specified by &lt;tool&gt;.
 	Valid merge tools are:
-	kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, and opendiff
+	kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff
 +
 If a merge resolution program is not specified, 'git mergetool'
 will use the configuration variable merge.tool.  If the
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 7f6c16f..39f6595 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -250,6 +250,16 @@ merge_file () {
 	    check_unchanged
 	    save_backup
 	    ;;
+	ecmerge)
+	    touch &quot;$BACKUP&quot;
+	    if base_present; then
+		&quot;$merge_tool_path&quot; &quot;$BASE&quot; &quot;$LOCAL&quot; &quot;$REMOTE&quot; --mode=merge3 --to=&quot;$path&quot;
+	    else
+		&quot;$merge_tool_path&quot; &quot;$LOCAL&quot; &quot;$REMOTE&quot; --mode=merge2 --to=&quot;$path&quot;
+	    fi
+	    check_unchanged
+	    save_backup
+	    ;;
 	emerge)
 	    if base_present ; then
 		&quot;$merge_tool_path&quot; -f emerge-files-with-ancestor-command &quot;$LOCAL&quot; &quot;$REMOTE&quot; &quot;$BASE&quot; &quot;$(basename &quot;$path&quot;)&quot;
@@ -299,7 +309,7 @@ done
 
 valid_tool() {
 	case &quot;$1&quot; in
-		kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff)
+		kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)
 			;; # happy
 		*)
 			return 1
-- 
1.5.3.3.127.g40d17

-

From: Theodore Tso
Date: Monday, October 8, 2007 - 2:44 pm

Hmm.  A propietary merge tool.  It's not that much code, so I guess....

I note though that it claims on the web page that they are integrated
with &quot;most famous SCM's&quot;, but they don't include git.  If we add this
support, are they going to change their web page?  :-)

Also, ECmerge is supported on Linux, Solaris, MacOS X, and Windows.
Which platforms have you tested on?  My guess is that if it works on
Linux, it'll probably work on Solaris and MacOS, but is it a fair
guess you haven't tested under Windows?  Not that most Windows systems
are going to be able to use git-mergetool since it's a bash script,
unless they are using Cygwin or some such.

       	    	      	     	     - Ted
-

From: Steffen Prohaska
Date: Monday, October 8, 2007 - 11:14 pm

You may even apply for a free (as beer) license if you contribute
to open source projects:

http://www.elliecomputing.com/Community/opensource.asp



I work on the msysgit project and I'd like to have mergetool
available before I advertise git on Windows. It makes merging
so much easier ;)

	Steffen


-

From: Johannes Schindelin
Date: Tuesday, October 9, 2007 - 5:37 am

Hi,


I would _hate_ to rely on a closed source program (in addition to Windows 
itself) in msysGit.

And it seems that you cannot even get ECMerge for free in general.

What does TortoiseCVS use?

Ciao,
Dscho

-

From: Steffen Prohaska
Date: Tuesday, October 9, 2007 - 5:49 am

It's only an option. You can also choose kdiff3 if you like, or  
vimdiff or
emacs merge. But personally, I prefer ECMerge because is seems to  
support
a faster and safer workflow (at least for me).

Before submitted this patch I thought about a general mechanism to  
easily
specify any tool that supports command line argument. But just adding  
them
tool by tool as needed looks easier to me, and hopefully to the user. We
can include the correct command line in git-mergetool and only require

True. But does it matter? I can't get Windows for free and git runs  

Don't know.

	Steffen
-

From: Alan Hadsell
Date: Tuesday, October 9, 2007 - 6:03 am

They don't actually include it in the package, but they recommend
WinMerge http://winmerge.org/, which is free (GPL).

-- 
Alan Hadsell
-

From: Steffen Prohaska
Date: Tuesday, October 9, 2007 - 6:17 am

WinMerge doesn't support 3-way merges. At least I cannot find any
indication for 3-way in the manual [1] and the comparison at [2] also
tells that WinMerge doesn't support 3-way.

	Steffen

[1] http://winmerge.org/2.6/manual/CompareFiles.html
[2] http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools
-

From: Alan Hadsell
Date: Tuesday, October 9, 2007 - 7:21 am

From their FAQ:

Does WinMerge support merging three files? Sometimes it is called
3-way merge, where one file is ancestor. This would be useful for
version control!

Unfortunately not. We acknowledge it would be good feature but have no
plans to implement it in near future. This can be somewhat worked
around by using two WinMerge instances. (One developer has begun
preliminary work on this feature, but it is not yet available, even in
experimental releases.)
-

From: Theodore Tso
Date: Monday, October 8, 2007 - 2:57 pm

This patch doesn't work the config file doesn't specify an explicit
mergetool via merge.tool.   The reason for that is this loop:

    for i in $merge_tool_candidates; do
        if test $i = emerge ; then
            cmd=emacs
        else
            cmd=$i
        fi
        if type $cmd &gt; /dev/null 2&gt;&amp;1; then
            merge_tool=$i
            break
        fi
    done

is only checking to see if $cmd is in the path; it's not looking up
the merge.&lt;toolname&gt;path variable in this loop.

I guess the other question is whether we would be better off simply
telling the user to specify an absolute pathname in merge.tool, and
then having git-mergetool strip off the directory path via basename,
and then on window systems, stripping off the .EXE or .COM suffix, and
then downcasing the name so that something like &quot;C:\Program
Files\ECMerge\ECMerge.exe&quot; gets translated to &quot;ecmerge&quot;.  Would I be
right in guessing that the reason why you used merge.&lt;toolname&gt;path
approach was to avoid this messy headache?

					- Ted
-

From: Theodore Tso
Date: Monday, October 8, 2007 - 3:01 pm

Err, let me try that again.  &quot;This patch doesn't work IF the config
file doesn't specify an explicit &gt; mergetool via merge.tool.&quot;

Sorry about the missing conjuction; the sentence doesn't make much
sense without it...

						- Ted
-

From: Steffen Prohaska
Date: Monday, October 8, 2007 - 11:30 pm

I didn't change the automatic detection. It should work as before.
That is it continues to assume that merge tools are in PATH.

Is you expectation that git-mergetool should also consider the
absolute paths provided in merge.&lt;toolname&gt;path?

When I wrote the patch I had in mind that people will set the
merge.tool explicitly if they provide an absolute path. Automatic
detection would only be used if nothing is configured. In this

Yes. The program to start ECMerge on Windows is called 'guimerge.exe'.
Hard to derive a sensible short name from this.

So I don't think that an automatic translation is an option. I prefer
to provide the absolute paths.

Absolute paths have another advantage. You can set several of them
and choose a tool on the command line. Maybe you have several tools
you want to try. Or you hacking with someone else who preferes a
different tool. Or you just want to give a demo. I see
merge.&lt;toolname&gt;path more as a database associating absolute paths
with the shortnames.

My mental model is as follows:
1) merge.tool selects the mechanism needed to call the tool, that is
command line arguments, how merge result is passed, ...
2) merge.&lt;toolname&gt;path provides additional information how to locate
the selected tool in the filesystem.

The two points are somewhat orthogonal. I'd not fuse them into one.

	Steffen


-

From: Frank Lichtenheld
Date: Monday, October 8, 2007 - 3:00 pm

Why not merge.&lt;toolname&gt;.path?
This would it make easy to introduce new variables of the form
merge.&lt;toolname&gt;.&lt;var&gt; later if needed. I also think it is more
consistent with names of existing configuration variables.
(think branch.&lt;name&gt;.&lt;var&gt; or remote.&lt;name&gt;.&lt;var&gt;)

Gruesse,
-- 
Frank Lichtenheld &lt;frank@lichtenheld.de&gt;
www: http://www.djpig.de/
-

From: Steffen Prohaska
Date: Monday, October 8, 2007 - 11:42 pm

Looks more beautiful on the command line but a bit more complex
in the config file. But I like the idea.

Maybe mergetool.&lt;tool&gt;.path is even a better choice? It clearly
indicate the relationship with mergetool. We could explain:

'The variable merge.tool = &lt;tool&gt; refers to a tool that can
be further specified in mergetool.&lt;tool&gt;.path.'

	Steffen




-

From: Johannes Schindelin
Date: Tuesday, October 9, 2007 - 5:35 am

Hi,


Would it not be more in line with all other config variables if it was 
written merge.&lt;toolname&gt;.path?  (Indeed, I thought your subject line 
contained a typo when I read it first.)

Ciao,
Dscho
-

Previous thread: none

Next thread: confused about a conflict during octopus merging by martin f krafft on Monday, October 8, 2007 - 5:31 pm. (3 messages)