Skip to contentSkip to conversation

difftool/mergetool: refactor commands to use git-mergetool--lib

PATCH In review David Aguilar 4 participants 6 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 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.

---

Includes latest suggestions from Markus:

* Modify check_unchanged so that it doesn't check merge_mode

* Modify the way $tools is setup so that we fixup duplicated spaces later

* Fix the status capturing for the custom tool in run_merge_tool

 .gitignore                           |    1 +
 Documentation/git-mergetool--lib.txt |   56 +++++
 Makefile                             |    1 +
 git-difftool--helper.sh              |  186 +----------------
 git-mergetool--lib.sh                |  381 ++++++++++++++++++++++++++++++++++
 git-mergetool.sh                     |  224 ++-------------------
 6 files changed, 461 insertions(+), 388 deletions(-)
 create mode 100644 Documentation/git-mergetool--lib.txt
 create mode 100644 git-mergetool--lib.sh
.gitignore +1 -0
index a36da9d..757c7f0 100644
@@ -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
index a80055f..3e56274 100644
@@ -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 +381 -0

381 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.1.3
#1 lore raw

David Aguilar, 08.04.2009:

git-mergetool--lib.sh line 291

Quoted 6 lines
git-mergetool--lib.sh +4 -0
 
+guess_merge_tool () {
+	tools="ecmerge"
+	if merge_mode; then
+		tools="$tools tortoisemerge"

ecmerge can now go to the block after "test -n $DISPLAY", so that in this if-then-else really only merge-only and diff-only tools are handled.
Then here it is
+ tools="tortoisemerge"

git-mergetool--lib.sh

Quoted 2 lines
git-mergetool--lib.sh +2 -0
+	else
+		kompare="kompare"

and here
+ tools="kompare"

git-mergetool--lib.sh line 302

Quoted 9 lines
git-mergetool--lib.sh +9 -0
+	fi
+	if test -n "$DISPLAY"; then
+		if test -n "$GNOME_DESKTOP_SESSION_ID" ; then
+			tools="meld opendiff kdiff3 $kompare tkdiff $tools"
+			tools="$tools xxdiff gvimdiff diffuse"
+		else
+			tools="opendiff kdiff3 $kompare tkdiff xxdiff $tools"
+			tools="$tools meld gvimdiff diffuse"
+		fi

And above ecmerge
And now that we remove the duplicated spaces afterwards anyway, we can get rid of the double tools= and continue the line with \
if we adjust the sed command below...

git-mergetool--lib.sh line 313

Quoted 11 lines
git-mergetool--lib.sh +11 -0
+	fi
+	if echo "${VISUAL:-$EDITOR}" | grep emacs > /dev/null 2>&1; then
+		# $EDITOR is emacs so add emerge as a candidate
+		tools="$tools emerge vimdiff"
+	elif echo "${VISUAL:-$EDITOR}" | grep vim > /dev/null 2>&1; then
+		# $EDITOR is vim so add vimdiff as a candidate
+		tools="$tools vimdiff emerge"
+	else
+		tools="$tools emerge vimdiff"
+	fi
+	tools="$(echo "$tools" | sed -e 's/ +/ /g')"

Doesn't work for me. For me 's/ \+/ /g' works.

...like this: 's/[ ]\+/ /g' (space and tab)

OK, for clarification now:
if merge_mode; then
tools="tortoisemerge"
else
tools="kompare"
fi
if test -n "$DISPLAY"; then
if test -n "$GNOME_DESKTOP_SESSION_ID" ; then
tools="meld opendiff kdiff3 tkdiff xxdiff $tools \
gvimdiff diffuse ecmerge"
else
tools="opendiff kdiff3 tkdiff xxdiff meld $tools \
gvimdiff diffuse ecmerge"
fi
fi
[...]
tools="$(echo "$tools" | sed -e 's/[ ]\+/ /g')"

Quoted 8 lines
git-mergetool--lib.sh +8 -0
+	echo >&2 "merge tool candidates: $tools"
+
+	# Loop over each candidate and stop when a valid merge tool is found.
+	for i in $tools
+	do
+		merge_tool_path="$(translate_merge_tool_path "$i")"
+		if type "$merge_tool_path" > /dev/null 2>&1; then
+			merge_tool="$i"

git-mergetool--lib.sh line 331

Quoted 10 lines
git-mergetool--lib.sh +10 -0
+			break
+		fi
+	done
+
+	if test -z "$merge_tool" ; then
+		echo >&2 "No known merge resolution program available."
+		return 1
+	fi
+	echo "$merge_tool"
+}

Looks good to me, after these last 2 issues are adjusted. Maybe resend the whole series then, so that Junio can apply them easily?

Markus

#2 lore raw
Quoted 6 lines · Markus Heidelberg
Quoted 6 lines
(quoted diff) +6 -0
+	fi
+	if echo "${VISUAL:-$EDITOR}" | grep emacs > /dev/null 2>&1; then
+		# $EDITOR is emacs so add emerge as a candidate
+		tools="$tools emerge vimdiff"
+	elif echo "${VISUAL:-$EDITOR}" | grep vim > /dev/null 2>&1; then
+		# $EDITOR is vim so add vimdiff as a candidate
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		tools="$tools vimdiff emerge"
+	else
+		tools="$tools emerge vimdiff"
+	fi
+	tools="$(echo "$tools" | sed -e 's/ +/ /g')"

Doesn't work for me. For me 's/ \+/ /g' works.
...like this: 's/[ ]\+/ /g' (space and tab)

Pleae don't. "s/ */ /g' should be the most portable (the point being "do not use one-or-more +").

Quoted 2 lines

Looks good to me, after these last 2 issues are adjusted. Maybe resend the whole series then, so that Junio can apply them easily?

Thanks. I've replaced the series with the following applied on top of the 'master', but I won't be merging them to 'next' for tonight, I guess.

[PATCH 01/14] doc/merge-config: list ecmerge as a built-in merge [PATCH 02/14] git-mergetool/difftool: make (g)vimdiff workable under [PATCH 03/14] git-mergetool: add new merge tool TortoiseMerge [PATCH 04/14] difftool: remove merge options for opendiff, tkdiff, [PATCH 05/14] difftool: remove the backup file feature
[PATCH 06/14] difftool: use perl built-ins when testing for msys [PATCH v2 07/14] difftool: add a -y shortcut for --no-prompt
[PATCH 08/14] difftool/mergetool: add diffuse as merge and diff tool [PATCH v2 09/14] difftool: move 'git-difftool' out of contrib [PATCH v3 10/14] difftool: add various git-difftool tests
[PATCH v2 11/14] difftool: add support for a difftool.prompt config variable [PATCH 12/14] bash completion: add git-difftool
[PATCH 13/14] mergetool: use $( ... ) instead of backticks
[PATCH v4 14/14] difftool/mergetool: refactor commands to use git-mergetool--lib

It appears that, assuming that up to 13/14 above is what you two expected me to pick up, we would perhaps need to only replace 14/14?

As the final sanity check, please eyeball the attached interdiff, created this way:

 $ git checkout master^0
 $ git am -s ./+da-fourteen-patches
 $ A=$(git rev-parse HEAD)
 $ git reset --hard master
 $ git merge da/difftool ;# old series
 $ git diff --stat -p HEAD $A ;# what's new in the new series?
 Documentation/config.txt               |    3 +-
 Documentation/git-mergetool.txt        |    2 +-
 Documentation/merge-config.txt         |    6 +-
 command-list.txt                       |    1 -
 contrib/completion/git-completion.bash |    2 +-
 git-mergetool--lib.sh                  |  237 ++++++++++++++++++--------------
 t/t7800-difftool.sh                    |    4 +-
 7 files changed, 144 insertions(+), 111 deletions(-)
Documentation/config.txt +2 -1
index 6e29623..d427daf 100644
@@ -670,7 +670,8 @@ diff.suppressBlankEmpty::
 diff.tool::
 	Controls which diff tool is used.  `diff.tool` overrides
 	`merge.tool` when used by linkgit:git-difftool[1] and has
-	the same valid values as `merge.tool`.
+	the same valid values as `merge.tool` minus "tortoisemerge"
+	and plus "kompare".
 
 difftool.<tool>.path::
 	Override the path for the given tool.  This is useful in case
Documentation/git-mergetool.txt +1 -1
index c3a8092..ff9700d 100644
@@ -27,7 +27,7 @@ OPTIONS
 	Use the merge resolution program specified by <tool>.
 	Valid merge tools are:
 	kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge,
-	diffuse and opendiff
+	diffuse, tortoisemerge and opendiff
 +
 If a merge resolution program is not specified, 'git-mergetool'
 will use the configuration variable `merge.tool`.  If the
Documentation/merge-config.txt +3 -3
index c4fc3eb..4832bc7 100644
@@ -23,9 +23,9 @@ merge.tool::
 	Controls which merge resolution program is used by
 	linkgit:git-mergetool[1].  Valid built-in values are: "kdiff3",
 	"tkdiff", "meld", "xxdiff", "emerge", "vimdiff", "gvimdiff",
-	"diffuse" and "opendiff".  Any other value is treated as a custom
-	merge tool and there must be a corresponding mergetool.<tool>.cmd
-	option.
+	"diffuse", "ecmerge", "tortoisemerge", and
+	"opendiff".  Any other value is treated is custom merge tool
+	and there must be a corresponding mergetool.<tool>.cmd option.
 
 merge.verbosity::
 	Controls the amount of output shown by the recursive merge
command-list.txt +0 -1
index fd66395..fb03a2e 100644
@@ -69,7 +69,6 @@ git-merge-file                          plumbingmanipulators
 git-merge-index                         plumbingmanipulators
 git-merge-one-file                      purehelpers
 git-mergetool                           ancillarymanipulators
-git-mergetool--lib                      purehelpers
 git-merge-tree                          ancillaryinterrogators
 git-mktag                               plumbingmanipulators
 git-mktree                              plumbingmanipulators
contrib/completion/git-completion.bash +1 -1
index 6f96d75..069e19e 100755
@@ -1192,7 +1192,7 @@ _git_mergetool ()
 	local cur="${COMP_WORDS[COMP_CWORD]}"
 	case "$cur" in
 	--tool=*)
-		__gitcomp "$__git_mergetools_common" "" "${cur##--tool=}"
+		__gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
 		return
 		;;
 	--*)
git-mergetool--lib.sh +135 -102

383 lines not on this page · raw message

t/t7800-difftool.sh +2 -2
index cbfbe87..2586f86 100755
@@ -202,10 +202,10 @@ test_expect_success 'difftool + mergetool config variables' '
 
 test_expect_success 'difftool.<tool>.path' '
 	git config difftool.tkdiff.path echo &&
-	diff=$(git difftool -y -t tkdiff branch) &&
+	diff=$(git difftool --tool=tkdiff --no-prompt branch) &&
 	git config --unset difftool.tkdiff.path &&
 	lines=$(echo "$diff" | grep file | wc -l) &&
-	test "$lines" = 1
+	test "$lines" -eq 1
 '
 
 test_done
#3 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Markus Heidelberg

git-mergetool--lib.sh run_merge_tool () { · line 313

Quoted 1 line
git-mergetool--lib.sh +1 -0
+	tools="$(echo "$tools" | sed -e 's/ +/ /g')"

Doesn't work for me. For me 's/ \+/ /g' works.
...like this: 's/[ ]\+/ /g' (space and tab)

Pleae don't. "s/ */ /g' should be the most portable (the point being "do not use one-or-more +").

v5 14/14. good stuff.

Quoted 13 lines
Quoted 2 lines

Looks good to me, after these last 2 issues are adjusted. Maybe resend the whole series then, so that Junio can apply them easily?

Thanks. I've replaced the series with the following applied on top of the 'master', but I won't be merging them to 'next' for tonight, I guess.

...
[PATCH v2 07/14] difftool: add a -y shortcut for --no-prompt
[PATCH v2 09/14] difftool: move 'git-difftool' out of contrib [PATCH v3 10/14] difftool: add various git-difftool tests
[PATCH v2 11/14] difftool: add support for a difftool.prompt config variable [PATCH v4 14/14] difftool/mergetool: refactor commands to use git-mergetool--lib

Quoted 2 lines

It appears that, assuming that up to 13/14 above is what you two expected me to pick up, we would perhaps need to only replace 14/14?

Yup

Quoted 3 lines

As the final sanity check, please eyeball the attached interdiff, created this way:

That looks right to me.

Quoted 19 lines
 $ git checkout master^0
 $ git am -s ./+da-fourteen-patches
 $ A=$(git rev-parse HEAD)
 $ git reset --hard master
 $ git merge da/difftool ;# old series
 $ git diff --stat -p HEAD $A ;# what's new in the new series?
 Documentation/config.txt               |    3 +-
 Documentation/git-mergetool.txt        |    2 +-
 Documentation/merge-config.txt         |    6 +-
 command-list.txt                       |    1 -
 contrib/completion/git-completion.bash |    2 +-
 git-mergetool--lib.sh                  |  237 ++++++++++++++++++--------------
 t/t7800-difftool.sh                    |    4 +-
 7 files changed, 144 insertions(+), 111 deletions(-)
Documentation/config.txt +0 -0
...
Signature · 1 line
	David
#4 lore raw
In reply to Junio C Hamano
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Markus Heidelberg

Looks good to me, after these last 2 issues are adjusted. Maybe resend the whole series then, so that Junio can apply them easily?

Thanks. I've replaced the series with the following applied on top of the 'master', but I won't be merging them to 'next' for tonight, I guess.

I feel I should be re-reviewing the mergetool patches, but while I have sufficient time, it is usually at the weekend so I can't always respond very rapidly.

I have been skimming this series, but most of the times that I thought I could apply the series and have a thorough review, another comment and re-roll has come through and I've decided to wait until it's stable.

My slight concern is that this series has been changing very rapidly, is everyone else happy that it is stable enough for merge into next? Would you like my further input?

Charles.

#5 lore raw
Quoted 8 lines · Charles Bailey

I have been skimming this series, but most of the times that I thought I could apply the series and have a thorough review, another comment and re-roll has come through and I've decided to wait until it's stable.

My slight concern is that this series has been changing very rapidly, is everyone else happy that it is stable enough for merge into next? Would you like my further input?

I'd feel safer to pick up v5 of 14/14 from David and park the result in 'pu' for a few days. I expect myself to be overloaded with the day job for the rest of the week and shouldn't be advancing topics without having enough concentration myself anyway.