Friday, March 26, 2010

Emacs As 3Way Diff Tool, Use With Mercurial

So, I've switched recently to EMacs. Mostly doing okay with the switch, but today I wanted to do something I'd not seen mentioned elsewhere: I wanted to use it as a 3 way diff tool, and integrate this with Mercurial. Turns out it's not too hard to do at all.

First, you'll need to make the following into a script. I named it "ediff3":


#!/bin/bash
if [ $# -ne 3 ]; then
   echo Usage: $0 local base other
   exit 1
fi
emacs --eval '(ediff-merge-with-ancestor "'$1'" "'$2'" "'$3'")' 

Don't forget to set that script executable!

Next up, you'll need to tell Mercurial how to call your new ediff3 script. Edit $HOME/.hgrc, and add the following lines:

[ui]
merge = ediff3
[merge-tools]
ediff3.executable = ediff3
ediff3.args = $local $other $base

You're now done with configuration. This blog post over here told me how to actually use ediff3. All in all, I'm pretty pleased. It was quick, easy to learn, easy to use, and did what I needed. If only all the tools I ever needed were like that.

2 comments:

Arne Babenhauserheide said...

That’s great, thanks!

Besides: Nowadays it also works like this (all in .hgrc):

[merge-patterns]
** = ediff3

[merge-tools]
ediff3.executable = emacsclient
ediff3.args = --eval '(ediff-merge-with-ancestor "'$local'" "'$other'" "'$base'")'

Arne Babenhauserheide said...

correction: No, it does not work as it should… I had missed kicking out the selection line…

Sorry…