Skip to contentSkip to conversation

mergetool--lib: set IFS for difftool and mergetool

PATCH In review David Aguilar 5 participants 11 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

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.

---
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(-)
git-mergetool--lib.sh +3 -0
index fe61e89..14b039d 100644
@@ -2,6 +2,9 @@
 
 : ${MERGE_TOOLS_DIR=$(git --exec-path)/mergetools}
 
+IFS='
+'
+
 mode_ok () {
 	if diff_mode
 	then
git-mergetool.sh +0 -2
index d20581c..9f77e3a 100755
@@ -451,8 +451,6 @@ fi
 printf "Merging:\n"
 printf "%s\n" "$files"
 
-IFS='
-'
 rc=0
 for i in $files
 do
Signature · 1 line
2.4.1.218.gc09a0e5
#1 lore raw

PATCH v6 2/2 mergetools: add winmerge as a builtin tool

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

---
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
mergetools/winmerge new file +36 -0
new file mode 100644
index 0000000..74a66d4
@@ -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
+}
Signature · 1 line
2.4.1.218.gc09a0e5
#2 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

Quoting David Aguilar <[email protected]>:

mergetools/winmerge line 24

Quoted 10 lines
mergetools/winmerge new file +10 -0
+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.

mergetools/winmerge line 35

Quoted 11 lines
mergetools/winmerge new file +11 -0
+	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

Quoted 3 lines

+}
--
2.4.1.218.gc09a0e5

#3 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

[just wrapping up the unaswered questions in this thread]

Quoted 16 lines · SZEDER Gábor

Quoting David Aguilar <[email protected]>:

mergetools/winmerge line 24

Quoted 10 lines
mergetools/winmerge new file +10 -0
+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.

Quoted 9 lines
Quoted 9 lines
mergetools/winmerge new file +9 -0
+	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
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	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.

Signature · 1 line
David
#4 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

Quoted 3 lines · David Aguilar

[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?

#5 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

Quoted 7 lines · Junio C Hamano
Quoted 3 lines · David Aguilar

[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,

Signature · 1 line
David
#6 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

In reply to David Aguilar

mergetools/winmerge line 26

Quoted 2 lines · David Aguilar
mergetools/winmerge new file +2 -0
+	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 ;-)

Quoted 10 lines
mergetools/winmerge new file +10 -0
+	do
+		if test -n "$directory" && test -x "$directory/$winmerge_exe"
+		then
+			printf '%s' "$directory/$winmerge_exe"
+			return
+		fi
+	done
+
+	printf WinMergeU.exe
+}
#7 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

Quoted 10 lines · Junio C Hamano

mergetools/winmerge line 26

Quoted 2 lines · David Aguilar
mergetools/winmerge new file +2 -0
+     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.

Signature · 1 line
Sebastian Schuberth
#8 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

Quoted 13 lines · Sebastian Schuberth
Quoted 10 lines · Junio C Hamano

mergetools/winmerge line 26

Quoted 2 lines · David Aguilar
mergetools/winmerge new file +2 -0
+     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.

Quoted 5 lines

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.

#9 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

Hi Junio,

Quoted 21 lines · Junio C Hamano
Quoted 13 lines · Sebastian Schuberth
Quoted 10 lines · Junio C Hamano

mergetools/winmerge line 26

Quoted 2 lines · David Aguilar
mergetools/winmerge new file +2 -0
+     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.

Quoted 5 lines

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.

Quoted 5 lines

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

#10 lore raw

Re: [PATCH v6 2/2] mergetools: add winmerge as a builtin tool

In reply to Junio C Hamano
Quoted 3 lines · Junio C Hamano

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.

Quoted 3 lines

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 :-)

Signature · 1 line
Sebastian Schuberth