git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mergetool--lib: add support for p4merge
@ 2009-10-28  9:11 Jay Soffian
  2009-10-28  9:21 ` Jay Soffian
  0 siblings, 1 reply; 6+ messages in thread
From: Jay Soffian @ 2009-10-28  9:11 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, David Aguilar, Shawn O . Pearce, Jeff King,
	Junio C Hamano

Add native support for p4merge as a diff / merge tool. There are two
oddities. First, launching p4merge on Mac OS X requires running a helper
shim (which in turn is looked for in a couple common locations, as it's
very unlikely to be in PATH). Second, p4merge seems to require its file
arguments be absolute paths.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
As requested by an Android developer at GitTogether09.

Only tested on Mac OS X 10.6.1. Feedback from anyone running p4merge on other
OS's would be appreciated.

 Documentation/git-difftool.txt  |    2 +-
 Documentation/git-mergetool.txt |    2 +-
 git-mergetool--lib.sh           |   44 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt
index 96a6c51..8e9aed6 100644
--- a/Documentation/git-difftool.txt
+++ b/Documentation/git-difftool.txt
@@ -31,7 +31,7 @@ OPTIONS
 	Use the diff tool specified by <tool>.
 	Valid merge tools are:
 	kdiff3, kompare, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff,
-	ecmerge, diffuse, opendiff and araxis.
+	ecmerge, diffuse, opendiff, p4merge and araxis.
 +
 If a diff tool is not specified, 'git-difftool'
 will use the configuration variable `diff.tool`.  If the
diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index 68ed6c0..4a6f7f3 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -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, tortoisemerge, opendiff and araxis.
+	diffuse, tortoisemerge, opendiff, p4merge and araxis.
 +
 If a merge resolution program is not specified, 'git-mergetool'
 will use the configuration variable `merge.tool`.  If the
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index bfb01f7..23b2816 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -7,6 +7,12 @@ merge_mode() {
 	test "$TOOL_MODE" = merge
 }
 
+abspath() {
+	d=$(dirname "$1")
+	d=$(cd "$d" && pwd -P)
+	echo "$d/$(basename "$1")"
+}
+
 translate_merge_tool_path () {
 	case "$1" in
 	vimdiff)
@@ -21,6 +27,19 @@ translate_merge_tool_path () {
 	araxis)
 		echo compare
 		;;
+	p4merge)
+		# Look for the Mac OS X P4Merge shim
+		for app_dir in "/Applications" "$HOME/Applications"
+		do
+				launchp4merge="$app_dir/p4merge.app/Contents/Resources/launchp4merge"
+				if type "$launchp4merge" > /dev/null 2>&1; then
+					echo "$launchp4merge"
+					return 0
+				fi
+		done
+		# Otherwise assume we're not on Mac OS X and just return p4merge
+		echo "$1"
+		;;
 	*)
 		echo "$1"
 		;;
@@ -45,7 +64,7 @@ check_unchanged () {
 
 valid_tool () {
 	case "$1" in
-	kdiff3 | tkdiff | xxdiff | meld | opendiff | \
+	kdiff3 | tkdiff | xxdiff | meld | opendiff | p4merge | \
 	emerge | vimdiff | gvimdiff | ecmerge | diffuse | araxis)
 		;; # happy
 	tortoisemerge)
@@ -284,6 +303,29 @@ run_merge_tool () {
 				>/dev/null 2>&1
 		fi
 		;;
+	p4merge)
+		# At least on Mac OS X p4merge wants absolute paths
+		ABS_LOCAL=$(abspath "$LOCAL")
+		ABS_REMOTE=$(abspath "$REMOTE")
+		if merge_mode; then
+			ABS_MERGED=$(abspath "$MERGED")
+			touch "$BACKUP"
+			if $base_present; then
+				ABS_BASE=$(abspath "$BASE")
+				"$merge_tool_path" \
+					"$ABS_BASE" "$ABS_LOCAL" "$ABS_REMOTE" "$ABS_MERGED" \
+					>/dev/null 2>&1
+			else
+				"$merge_tool_path" \
+					"/dev/null" "$ABS_LOCAL" "$ABS_REMOTE" "$ABS_MERGED" \
+					>/dev/null 2>&1
+			fi
+			check_unchanged
+		else
+			"$merge_tool_path" "$ABS_LOCAL" "$ABS_REMOTE" \
+				>/dev/null 2>&1
+		fi
+		;;
 	*)
 		merge_tool_cmd="$(get_merge_tool_cmd "$1")"
 		if test -z "$merge_tool_cmd"; then
-- 
1.6.5.2.74.g610f9.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-10-28 10:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-28  9:11 [PATCH] mergetool--lib: add support for p4merge Jay Soffian
2009-10-28  9:21 ` Jay Soffian
2009-10-28  9:27   ` David Aguilar
2009-10-28  9:36   ` David Aguilar
2009-10-28  9:52     ` Jay Soffian
2009-10-28 10:02       ` Jay Soffian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).