Custom merging with Mercurial, on Windows
February 7th, 2008 by hattonToday I had one of those 1/2 hour projects that turn into most of the day. I set out to try out mercurial and see how difficult it would be to get it to use a custom program to do a merge, based on the file extension. When the file type is a .lift (which is xml), I want it to run my program that knows about lift files. Simple enough. The web was littered with pages claiming ways to accomlish this… but like so often in open source stuff, a given page is for some past version on some other platform, though you as a newbie have no idea of this, so you spend all day trying things.
I’ll spare you the rest of sob story. Here’s what finally worked:
1) I installed a recent tortoisehg distribution.
2) I installed python 2.5, made sure python was part of my PATH
3) I grabbed the hgmerge.py python script
4) I learned enough python to make the script actually work (must have worked in some previous version of python… surely!)
The part of the script that inserts the values for the file paths had lines like this:
cmd.replace(’$base’, base)
Which I had to change to:
self.cmd = string.replace(self.cmd,’$base’, base)
Also the part that recognizes the “external” word didn’t work, so I rewrote it as:
elif string.find(inter, ‘external’) > -1:
start = string.find(inter, ‘external’)
tool = External()
tool.set_command(inter[9+start:])
return (noninteractive, tool, ext_filter)
5) in the .hg folder which is the mercurial repository, I edited the hgrc file:
[ui] merge = python E:\Users\John\Documents\WeSay\hgTest1\hgmerge.py
6) I edited the E:\Program Files\TortoiseHg\mercurial.ini file:
[hgmerge] ext.lift = external C:\WeSay\lib\LIFT\LIFTDotNet\output\debug\LiftMerge.exe $base $local $other $output