# [PATCH v3] mergetools: add winmerge as a builtin tool

2 messages from 2015-05-20 to 2015-05-20. Participants: David Aguilar, Sebastian Schuberth.
Thread: https://gitlist.dev/t/39378

## David Aguilar, 2015-05-20 04:20

Subject: [PATCH v3] mergetools: add winmerge as a builtin tool
Message-ID: <1432095635-96710-1-git-send-email-davvid@gmail.com>
URL: https://gitlist.dev/e/1432095635-96710-1-git-send-email-davvid%40gmail.com

```
Add a winmerge scriptlet with the commands described in [1] so
that users can use winmerge without needing to perform any
additional configuration.

[1] http://thread.gmane.org/gmane.comp.version-control.git/268631

Helped-by: Philip Oakley <philipoakley@iee.org>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Helped-by: Sebastian Schuberth <sschuberth@gmail.com>
Helped-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Changes since v2: We now use "$PROGRAMFILES" exclusively
and let the shell concatenate the " (x86)" part when testing
filesystem paths.  The C:/... hard-coded fallbacks have been
removed since $PROGRAMFILES should exist in practice.

 mergetools/winmerge | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 mergetools/winmerge

diff --git a/mergetools/winmerge b/mergetools/winmerge
new file mode 100644
index 0000000..435623c
--- /dev/null
+++ b/mergetools/winmerge
@@ -0,0 +1,35 @@
+diff_cmd () {
+	"$merge_tool_path" -u -e "$LOCAL" "$REMOTE"
+	return 0
+}
+
+merge_cmd () {
+	# mergetool.winmerge.trustExitCode is implicitly false.
+	# touch $BACKUP so that we can check_unchanged.
+	touch "$BACKUP"
+	"$merge_tool_path" -u -e -dl Local -dr Remote \
+		"$LOCAL" "$REMOTE" "$MERGED"
+	check_unchanged
+}
+
+translate_merge_tool_path() {
+	# Use WinMergeU.exe if it exists in $PATH
+	if type WinMergeU.exe >/dev/null 2>&1
+	then
+		echo WinMergeU.exe
+		return
+	fi
+
+	# Look for WinMergeU.exe in the typical locations
+	winmerge_exe="WinMerge/WinMergeU.exe"
+
+	if test -n "$PROGRAMFILES" && test -x "$PROGRAMFILES (x86)/$winmerge_exe"
+	then
+		printf '%s' "$PROGRAMFILES (x86)/$winmerge_exe"
+	elif test -n "$PROGRAMFILES" && test -x "$PROGRAMFILES/$winmerge_exe"
+	then
+		printf '%s' "$PROGRAMFILES/$winmerge_exe"
+	else
+		echo WinMergeU.exe
+	fi
+}
-- 
2.4.1.218.g416b006

```

## Sebastian Schuberth, 2015-05-20 07:11

Subject: Re: [PATCH v3] mergetools: add winmerge as a builtin tool
Message-ID: <CAHGBnuOwf2cBMZf1A6HuSoVTPxCem7fH3TOCHnYg3tW-QkoOEg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuOwf2cBMZf1A6HuSoVTPxCem7fH3TOCHnYg3tW-QkoOEg%40mail.gmail.com
In-Reply-To: <1432095635-96710-1-git-send-email-davvid@gmail.com>

```
On Wed, May 20, 2015 at 6:20 AM, David Aguilar <davvid@gmail.com> wrote:

> +translate_merge_tool_path() {
> +       # Use WinMergeU.exe if it exists in $PATH
> +       if type WinMergeU.exe >/dev/null 2>&1

Maybe "type -p" here?

> +       # Look for WinMergeU.exe in the typical locations
> +       winmerge_exe="WinMerge/WinMergeU.exe"
> +
> +       if test -n "$PROGRAMFILES" && test -x "$PROGRAMFILES (x86)/$winmerge_exe"
> +       then
> +               printf '%s' "$PROGRAMFILES (x86)/$winmerge_exe"
> +       elif test -n "$PROGRAMFILES" && test -x "$PROGRAMFILES/$winmerge_exe"
> +       then
> +               printf '%s' "$PROGRAMFILES/$winmerge_exe"
> +       else
> +               echo WinMergeU.exe
> +       fi
> +}

This does not solve the problem reported by Dscho that some versions
of Cygwin / MSYS 1 / MSYS 2 might export "$ProgramFiles" instead of
"$PROGRAMFILES" (or similar for related variables).

Also there is a bit too much string duplication for my taste. And why
use "echo" in some places and "printf" in others?

I still like a loop-based solution best:

IFS=$'\n'
for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
cut -d '=' -f 2- | sort -u)
do
    test -n "$directory" &&
    test -x "$directory/$winmerge_exe" &&
    echo "$directory/$winmerge_exe" &&
    break
done

-- 
Sebastian Schuberth

```
