How to use p4merge as the merge/diff tool for Mercurial?
Asked Answered
O

6

37

Does anyone know how to setup Mercurial to use p4merge as the merge/diff tool on OS X 10.5?

Obstacle answered 4/9, 2008 at 1:14 Comment(0)
L
40

This will work for merging:

Place this into your ~/.hgrc (or, optionally, your Mercurial.ini on Windows):

[merge-tools]
p4.priority = 100
p4.premerge = True  # change this to False if you're don't trust hg's internal merge
p4.executable = /Applications/p4merge.app/Contents/MacOS/p4merge
p4.gui = True
p4.args = $base $local $other $output

Requires Mercurial 1.0 or newer. Clearly you'll need to update the path to that executable to reflect where you'd got p4merge installed.


You can't change what hg diff uses; but you can use the extdiff extension to create new diff commands that use the display you want.

So hg pdiff could run p4 merge, etc.

Lin answered 4/10, 2008 at 16:48 Comment(4)
You should use the executable 'launchp4merge' instead of 'p4merge'. This way, if you diff multiple pairs of files simultaneously, they all appear within one p4merge process instead of in separate processes.Governorship
If you wish to use Adam's suggestion, which works for me, use this line in place of the p4.executable line above: p4.executable = /Applications/p4merge.app/Contents/Resources/launchp4mergeContrail
This does not work with hg diff. Any suggestions on how to make p4merge the default diff editor?Heilner
You can't change what diff uses, but you can use the extdiff extension to create new diff commands that use the display you want. So hg pdiff could run p4 merge, etc.Lin
C
15

I found Ry4an's answer to be a good solution, except for a minor problem, which left p4merge (under mac os) mixing up the command inputs. Do everything described in his answer and add the following line in the [merge-tools] section:

p4.args=$base $local $other $output

This line tells mercurial in which order p4merge takes its arguments.

Chthonian answered 29/12, 2008 at 23:39 Comment(0)
C
15

I am using version 1.0.1 of TortoiseHg and p4merge works out of the box.

Just go to Global Settings -> TortoiseHg and select the following options:

  • Three-way Merge Tool: p4merge
  • Visual Diff Tool: p4merge

Screenshot

Caton answered 23/9, 2010 at 14:38 Comment(0)
C
3

Maybe because I'm working on Windows, but the proposed solution didn't work for me. Instead, the following does work.

In your ~/.hgrc/ / Mercurial.ini, I applied the following changes:

Enabled "ExtDiff" extension:

[extensions]
hgext.extdiff =

Added P4 extdiff command:

[extdiff]
cmd.p4diff = p4merge

Configured it as the default visual diff tool:

[tortoisehg]
vdiff = p4diff
Caruthers answered 22/2, 2010 at 13:57 Comment(1)
If you go this route, you just need to type "hg p4" to do a visual diff because Mercurial only requires you to type the minimum number of characters to disambiguate a command.Sojourn
T
0

I'm guessing there's a CLI tool for p4merge (which I know nothing about).

I wrote a blog post about using Changes.app, and some other GUI tools with Mercurial: Using Mercurial with GUI Tools.

Basically, you need to know the calling expectations of the CLI tool that loads up the diff tool. IE, how to make it load data from a particular file, and how to make it wait for exit. There should be enough info on the post to give you some ideas.

Toxicogenic answered 4/9, 2008 at 6:11 Comment(0)
W
0

I use the following bit of Python to launch p4merge and use it with git :

#!/usr/bin/python
import sys
import os

os.system('/Applications/p4merge.app/Contents/MacOS/p4merge "%s" "%s"' % (sys.argv[2], sys.argv[5]))

I'm not sure how mercurial looks to launch an external diff tool though ? Hopefully it's as simple as adjusting 2 & 5 in the above line to being the index of the arguments for 'checked in' and 'current working copy'.

Whiteness answered 10/9, 2008 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.