mercurialmercurial-hookmercurial-extension

Python custom Mercurial merge tool in process?


Given a custom hg merge tool mymergetool.py

On Linux, I can do this:

merge-tools.MyMergeTool.executable=mymergetool.py

which runs the python in a new process.

However on Windows one has to specify python.exe as the executable. But given that one might not exist on the system (I use hg embedded in an application)

I would like to be able to do something like this:

merge-tools.MyMergeTool.executable=python:mymergetool.py

which runs the merge tool in the same process as hg.

However when reading hg's filemerge.py it seems that the python: prepend isn't supported in this context.

Is there any other way of providing a custom merge tool that can run in process? (eg. using hooks or extensions)

Reasons why I want to do this

  1. I don't want to ship a python.exe with my application. (minor)
  2. On some systems, (eg. iOS) it hard to launch external processes, so having a custom merge tool run in process would make things a lot easier.

Solution

  • This is now possible in Mercurial 4.7 and newer. MergeTool configuration documentation

    (Release Notes)

    One specifies a python file along with a python function.

    merge-tools.MyMergeTool.executable=python:mymergetool.py:mergefn
    

    The function signature is this:

    def mergefn(ui, repo, args, **kwargs):