# [PATCH v6 1/2] mergetool--lib: set IFS for difftool and mergetool

11 messages from 2015-05-20 to 2015-05-22. Participants: David Aguilar, SZEDER Gábor, Junio C Hamano, Sebastian Schuberth, Johannes Schindelin.
Thread: https://gitlist.dev/t/39381

## David Aguilar, 2015-05-20 09:07

Subject: [PATCH v6 1/2] mergetool--lib: set IFS for difftool and mergetool
Message-ID: <1432112843-973-1-git-send-email-davvid@gmail.com>
URL: https://gitlist.dev/e/1432112843-973-1-git-send-email-davvid%40gmail.com

```
git-sh-setup sets IFS but it is not used by git-difftool--helper.
Set IFS in git-mergetool--lib so that the mergetool scriptlets,
difftool, and mergetool do not need to do so.

Signed-off-by: David Aguilar <davvid@gmail.com>
---
Changes since v5: fixed "diftool" typo in commit message

 git-mergetool--lib.sh | 3 +++
 git-mergetool.sh      | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index fe61e89..14b039d 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -2,6 +2,9 @@
 
 : ${MERGE_TOOLS_DIR=$(git --exec-path)/mergetools}
 
+IFS='
+'
+
 mode_ok () {
 	if diff_mode
 	then
diff --git a/git-mergetool.sh b/git-mergetool.sh
index d20581c..9f77e3a 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -451,8 +451,6 @@ fi
 printf "Merging:\n"
 printf "%s\n" "$files"
 
-IFS='
-'
 rc=0
 for i in $files
 do
-- 
2.4.1.218.gc09a0e5

```

## David Aguilar, 2015-05-20 09:07

Subject: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <1432112843-973-2-git-send-email-davvid@gmail.com>
URL: https://gitlist.dev/e/1432112843-973-2-git-send-email-davvid%40gmail.com
In-Reply-To: <1432112843-973-1-git-send-email-davvid@gmail.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>
---
Unchanged since v5.
Changes since v4: IFS is left as-is since it's done in 1/2

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

diff --git a/mergetools/winmerge b/mergetools/winmerge
new file mode 100644
index 0000000..74a66d4
--- /dev/null
+++ b/mergetools/winmerge
@@ -0,0 +1,36 @@
+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 -p WinMergeU.exe >/dev/null 2>&1
+	then
+		printf WinMergeU.exe
+		return
+	fi
+
+	# Look for WinMergeU.exe in the typical locations
+	winmerge_exe="WinMerge/WinMergeU.exe"
+	for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
+		cut -d '=' -f 2- | sort -u)
+	do
+		if test -n "$directory" && test -x "$directory/$winmerge_exe"
+		then
+			printf '%s' "$directory/$winmerge_exe"
+			return
+		fi
+	done
+
+	printf WinMergeU.exe
+}
-- 
2.4.1.218.gc09a0e5

```

## SZEDER Gábor, 2015-05-20 11:09

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <20150520130929.Horde.vYwOuIDRpi6hr15rOUbW1w7@webmail.informatik.kit.edu>
URL: https://gitlist.dev/e/20150520130929.Horde.vYwOuIDRpi6hr15rOUbW1w7%40webmail.informatik.kit.edu
In-Reply-To: <1432112843-973-2-git-send-email-davvid@gmail.com>

```

Quoting David Aguilar <davvid@gmail.com>:

> +translate_merge_tool_path() {
> +	# Use WinMergeU.exe if it exists in $PATH
> +	if type -p WinMergeU.exe >/dev/null 2>&1
> +	then
> +		printf WinMergeU.exe
> +		return
> +	fi
> +
> +	# Look for WinMergeU.exe in the typical locations
> +	winmerge_exe="WinMerge/WinMergeU.exe"

This variable is not used elsewhere, right?  Then you might want to  
mark it as local to make this clear.

> +	for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
> +		cut -d '=' -f 2- | sort -u)
> +	do
> +		if test -n "$directory" && test -x "$directory/$winmerge_exe"
> +		then
> +			printf '%s' "$directory/$winmerge_exe"
> +			return
> +		fi
> +	done
> +
> +	printf WinMergeU.exe

Please pardon my ignorance and curiosity, but what is the purpose of  
this last printf?
It outputs the same as in the case when winmerge is in $PATH at the  
beginning of the function.  However, if we reach this printf, then  
winmerge is not in $PATH, so what will be executed?


Gábor

> +}
> --
> 2.4.1.218.gc09a0e5

```

## Junio C Hamano, 2015-05-20 20:13

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <xmqqtwv7m2hw.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqtwv7m2hw.fsf%40gitster.dls.corp.google.com
In-Reply-To: <1432112843-973-2-git-send-email-davvid@gmail.com>

```
David Aguilar <davvid@gmail.com> writes:

> +	for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
> +		cut -d '=' -f 2- | sort -u)

Is the final "sort" really desired?  I am wondering if there are
fixed precedence/preference order among variants of %PROGRAMFILES% 
environment variables that the users on the platform are expected
to stick to, but the "sort" is sorting by the absolute pathnames of
where these things are, which may not reflect that order.

Not that I personally care too deeply, as I would expect that it is
likely any one of them found would just work fine ;-)

> +	do
> +		if test -n "$directory" && test -x "$directory/$winmerge_exe"
> +		then
> +			printf '%s' "$directory/$winmerge_exe"
> +			return
> +		fi
> +	done
> +
> +	printf WinMergeU.exe
> +}

```

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

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <CAHGBnuPyhG4y5ooR7KH0KrEhRYFu9BB+HKnnn+XhU5xL2TnL=w@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuPyhG4y5ooR7KH0KrEhRYFu9BB%2BHKnnn%2BXhU5xL2TnL%3Dw%40mail.gmail.com
In-Reply-To: <xmqqtwv7m2hw.fsf@gitster.dls.corp.google.com>

```
On Wed, May 20, 2015 at 10:13 PM, Junio C Hamano <gitster@pobox.com> wrote:

> David Aguilar <davvid@gmail.com> writes:
>
>> +     for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
>> +             cut -d '=' -f 2- | sort -u)
>
> Is the final "sort" really desired?  I am wondering if there are
> fixed precedence/preference order among variants of %PROGRAMFILES%
> environment variables that the users on the platform are expected
> to stick to, but the "sort" is sorting by the absolute pathnames of
> where these things are, which may not reflect that order.

I did add the sort (and -u) by intention, to ensure that "C:\Program
Files" (which is what %PROGRAMFILES% expands to by default) comes
before "C:\Program Files (x86)" (which is what %PROGRAMFILES(X86)%
expands to by default), so that programs of the OS-native bitness are
preferred.

-- 
Sebastian Schuberth

```

## Junio C Hamano, 2015-05-20 21:00

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <xmqq8ucjm0bo.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqq8ucjm0bo.fsf%40gitster.dls.corp.google.com
In-Reply-To: <CAHGBnuPyhG4y5ooR7KH0KrEhRYFu9BB+HKnnn+XhU5xL2TnL=w@mail.gmail.com>

```
Sebastian Schuberth <sschuberth@gmail.com> writes:

> On Wed, May 20, 2015 at 10:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
>
>> David Aguilar <davvid@gmail.com> writes:
>>
>>> +     for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
>>> +             cut -d '=' -f 2- | sort -u)
>>
>> Is the final "sort" really desired?  I am wondering if there are
>> fixed precedence/preference order among variants of %PROGRAMFILES%
>> environment variables that the users on the platform are expected
>> to stick to, but the "sort" is sorting by the absolute pathnames of
>> where these things are, which may not reflect that order.
>
> I did add the sort (and -u) by intention, to ensure that "C:\Program
> Files" (which is what %PROGRAMFILES% expands to by default) comes
> before "C:\Program Files (x86)" (which is what %PROGRAMFILES(X86)%
> expands to by default), so that programs of the OS-native bitness are
> preferred.

Yuck.  So even though %PROGRAMFILES% and %PROGRAMFILES(X86)% look as
if they are variables that can point at arbitrary places, they in
reality don't?  Otherwise %PROGRAMFILES% may point at D:\Program
while %PROGRAMFILES(X86)% may piont at C:\X86 and the latter would
sort before the former, which would defeat that "logic".

But of course if I view this not as a "logic" but as a "heuristics"
that happens to do the right thing in common environments, it is
perfectly OK ;-).

I've queued the patches as-is.

Thanks.

```

## Sebastian Schuberth, 2015-05-20 21:20

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <CAHGBnuMt82oawQnoPGNiXefui6k5A3DW1ktGWvMy0m8iq78oPg@mail.gmail.com>
URL: https://gitlist.dev/e/CAHGBnuMt82oawQnoPGNiXefui6k5A3DW1ktGWvMy0m8iq78oPg%40mail.gmail.com
In-Reply-To: <xmqq8ucjm0bo.fsf@gitster.dls.corp.google.com>

```
On Wed, May 20, 2015 at 11:00 PM, Junio C Hamano <gitster@pobox.com> wrote:

> Yuck.  So even though %PROGRAMFILES% and %PROGRAMFILES(X86)% look as
> if they are variables that can point at arbitrary places, they in
> reality don't?  Otherwise %PROGRAMFILES% may point at D:\Program

Correct. In the vast majority of  WIndows installations these
variables contain the default values.

> But of course if I view this not as a "logic" but as a "heuristics"
> that happens to do the right thing in common environments, it is
> perfectly OK ;-).

Exactly a heuristic is what it's supposed to be :-)

-- 
Sebastian Schuberth

```

## Johannes Schindelin, 2015-05-21 10:06

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <86b89ca969ff967f600f955f1990cdca@www.dscho.org>
URL: https://gitlist.dev/e/86b89ca969ff967f600f955f1990cdca%40www.dscho.org
In-Reply-To: <xmqq8ucjm0bo.fsf@gitster.dls.corp.google.com>

```
Hi Junio,

On 2015-05-20 23:00, Junio C Hamano wrote:
> Sebastian Schuberth <sschuberth@gmail.com> writes:
> 
>> On Wed, May 20, 2015 at 10:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>
>>> David Aguilar <davvid@gmail.com> writes:
>>>
>>>> +     for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
>>>> +             cut -d '=' -f 2- | sort -u)
>>>
>>> Is the final "sort" really desired?  I am wondering if there are
>>> fixed precedence/preference order among variants of %PROGRAMFILES%
>>> environment variables that the users on the platform are expected
>>> to stick to, but the "sort" is sorting by the absolute pathnames of
>>> where these things are, which may not reflect that order.
>>
>> I did add the sort (and -u) by intention, to ensure that "C:\Program
>> Files" (which is what %PROGRAMFILES% expands to by default) comes
>> before "C:\Program Files (x86)" (which is what %PROGRAMFILES(X86)%
>> expands to by default), so that programs of the OS-native bitness are
>> preferred.
> 
> Yuck.  So even though %PROGRAMFILES% and %PROGRAMFILES(X86)% look as
> if they are variables that can point at arbitrary places, they in
> reality don't?  Otherwise %PROGRAMFILES% may point at D:\Program
> while %PROGRAMFILES(X86)% may piont at C:\X86 and the latter would
> sort before the former, which would defeat that "logic".

Well, you are correct, theoretically an administrator could set the registry values (which are the source of the environment variables in question) of the `ProgramFilesDir` key in both

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion

and

HKEY_LOCAL_MACHINE\Software\WOW64\Microsoft\Windows\CurrentVersion

to wildly different locations as you outlined. However, it is not supported by Microsoft to change those locations via the registry:

https://support.microsoft.com/en-us/kb/933700

Ciao,
Dscho

```

## David Aguilar, 2015-05-22 19:58

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <20150522195802.GA26066@gmail.com>
URL: https://gitlist.dev/e/20150522195802.GA26066%40gmail.com
In-Reply-To: <20150520130929.Horde.vYwOuIDRpi6hr15rOUbW1w7@webmail.informatik.kit.edu>

```

[just wrapping up the unaswered questions in this thread]

On Wed, May 20, 2015 at 01:09:29PM +0200, SZEDER Gábor wrote:
> 
> Quoting David Aguilar <davvid@gmail.com>:
> 
> >+translate_merge_tool_path() {
> >+	# Use WinMergeU.exe if it exists in $PATH
> >+	if type -p WinMergeU.exe >/dev/null 2>&1
> >+	then
> >+		printf WinMergeU.exe
> >+		return
> >+	fi
> >+
> >+	# Look for WinMergeU.exe in the typical locations
> >+	winmerge_exe="WinMerge/WinMergeU.exe"
> 
> This variable is not used elsewhere, right?  Then you might want to
> mark it as local to make this clear.


"local" is a bash-ism, otherwise that'd be a good idea.


> >+	for directory in $(env | grep -Ei '^PROGRAM(FILES(\(X86\))?|W6432)=' |
> >+		cut -d '=' -f 2- | sort -u)
> >+	do
> >+		if test -n "$directory" && test -x "$directory/$winmerge_exe"
> >+		then
> >+			printf '%s' "$directory/$winmerge_exe"
> >+			return
> >+		fi
> >+	done
> >+
> >+	printf WinMergeU.exe
> 
> Please pardon my ignorance and curiosity, but what is the purpose of
> this last printf?
> It outputs the same as in the case when winmerge is in $PATH at the
> beginning of the function.  However, if we reach this printf, then
> winmerge is not in $PATH, so what will be executed?


This function maps what we call the tool (winmerge) to the actual executable.
That last printf provides the following behavior:

	$ git difftool -t winmerge HEAD~
	
	Viewing (1/1): 'mergetools/winmerge'
	Launch 'winmerge' [Y/n]:
	The diff tool winmerge is not available as 'WinMergeU.exe'
	fatal: external diff died, stopping at mergetools/winmerge

It ensures that the user sees 'WinMergeU.exe' in the error message.
That way the user can resolve the problem by e.g. adjusting their $PATH,
or realizing that they don't have WinMergeU.exe installed.
-- 
David

```

## Junio C Hamano, 2015-05-22 20:05

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <xmqqr3q8e5tj.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqr3q8e5tj.fsf%40gitster.dls.corp.google.com
In-Reply-To: <20150522195802.GA26066@gmail.com>

```
David Aguilar <davvid@gmail.com> writes:

> [just wrapping up the unaswered questions in this thread]
> ...
> On Wed, May 20, 2015 at 01:09:29PM +0200, SZEDER Gábor wrote:

Thanks for clarifications.  I think all is good now?

```

## David Aguilar, 2015-05-22 20:16

Subject: Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool
Message-ID: <20150522201606.GB26066@gmail.com>
URL: https://gitlist.dev/e/20150522201606.GB26066%40gmail.com
In-Reply-To: <xmqqr3q8e5tj.fsf@gitster.dls.corp.google.com>

```
On Fri, May 22, 2015 at 01:05:28PM -0700, Junio C Hamano wrote:
> David Aguilar <davvid@gmail.com> writes:
> 
> > [just wrapping up the unaswered questions in this thread]
> > ...
> > On Wed, May 20, 2015 at 01:09:29PM +0200, SZEDER Gábor wrote:
> 
> Thanks for clarifications.  I think all is good now?

Yes, I think so.  I just looked at what you have queued in pu
and it looks good.

Thanks all,
-- 
David

```
