Third-Party Merge Tools

Using third-party merge tools with Perforce

SUMMARY

This article describes how to use third-party merge tools with Perforce.


DETAILS

Using Third-Party Merge Tools with P4V

Perforce's cross-platform GUI contains not only its own powerful merging capabilities, but also the built-in ability to use an external merge program. You can configure this by choosing Tools->Preferences, then clicking the Merge tab, clicking the radio button Use external application, and entering the filename there. Note that this tool should be a graphical utility that opens its own windows even on platforms such as Linux. An xterm can be used to run shell script merges if desired.

Using Third-Party Merge Tools with the Command-Line P4

When resolving files and selecting the merge option, Perforce outputs four files. The four files, in order of presentation, are:

  1. the base file
  2. the source file (also known as "theirs")
  3. the target file (also known as "yours")
  4. the merge file.

These four files can then be used as input to a third-party diff/merge program during the resolve process.

For example, if you were integrating into a file named "foo.c", Perforce passes the following arguments to an external merge program.

txxxt(n).tmp	= base		read-only temp file

txxxt(n+1).tmp	= theirs 	read-only temp file

foo.c		= yours		local copy of target file open for integrate

txxxt(n+2).tmp	= merge		writable temp file

(Here, the "xxx" and (n) would be replaced by a unique file number sequence.)

To specify a third-party diff/merge, set the P4MERGE environment variable. For example:

set P4MERGE=merge.exe

If you need to specify command line options to the diff/merge program, then you can wrap these in a batch file and provide the batch file name to P4MERGE. For example:

set P4MERGE=merge.bat

The general form of a Windows-style batch file is:

::merge.bat
::
merge.exe %1 %2 %3 %4

More examples

AraxisMerge serves as a good case study of the generic process of integrating third-party merge tools. AraxisMerge is a popular merge tool for Windows and Mac OS X platforms available from Araxis Ltd.

Important Note: Araxis Merge Professional is needed if you require three-way merging. If you are only able to bring up a two-window merge, you most likely have the "Standard" version and you will need to upgrade in order to have a three-way merge.

http://www.araxis.com/merge/scm_integration.html (Perforce section)

P4Merge

As of release 2005.1, the Perforce Windows Installer includes P4V's built-in graphical merge utility, P4Merge.

External Merge Programs and the SCC Plug-In

Programs that use the Perforce SCC plug-in interface (Microsoft Visual C++, for example) do not recognize the P4MERGE environment variable. The Microsoft SCC API provides no methods for merging files and therefore the P4SCC plug-in cannot do so. If you need to resolve file conflicts, use P4, P4Win, P4Web, or P4V.