git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] mergetool--lib: add support for p4merge

From
Jay Soffian <jaysoffian@gmail.com>
Date
Oct 28, 2009, 09:11 UTC
Message-ID
<1256721087-72534-1-git-send-email-jaysoffian@gmail.com>

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
Next: Jay Soffian
Message 1 of 6 in “mergetool--lib: add support for p4merge”
  1. mergetool--lib: add support for p4mergeJay Soffian, Oct 28, 2009
  2. Jay SoffianOct 28, 2009
  3. David AguilarOct 28, 2009
  4. David AguilarOct 28, 2009
  5. Jay SoffianOct 28, 2009
  6. Jay SoffianOct 28, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.