non-graphical merge tool
Colin Caughie
c.caughie at gmail.com
Fri May 16 15:42:32 UTC 2014
On 5/14/2014 6:36 PM, Michael Mossey wrote:
> I'm working on Windows in a two-developer project, and the other guy
> is not an experienced programmer. If he runs "hg merge" I don't want
> it to pop him into kdiff3 as he probably won't understand it. I would
> rather that Mercurial leave conflicting merges in the file with merge
> marks so he can send it off to me to fix. How would I set Mercurial to
> do a non-graphical merge in the presence of conflicts, i.e. leave
> merge marks?
I am an experienced programmer and I still much prefer text-based
merging to graphical tools like kdiff3. You could use internal:merge as
Pierre-Yves suggests, but that has the downside that it only shows you
the "local" and "other" version of each conflicting change; it doesn't
show you the original version which I usually find essential to
understanding the intent of each change.
I use a Python wrapper to the diff3 program for this purpose, as that
does show all three versions where relevant. The script is included
below in case you find it useful. You need to have diff3 installed and
in your path, which it probably is if you're using Linux, you can use
the cygwin version if you're using Windows. You can enable it in
hgrc/mercurial.ini as follows:
[ui]
merge = /path/to/hgdiff3.py
Colin
----------------
#!/usr/bin/python
import sys
import subprocess
import os.path
if len(sys.argv) != 4:
print "Usage: hgdiff3 <my> <orig> <your>"
sys.exit(1)
my = sys.argv[1]
orig = sys.argv[2]
your = sys.argv[3]
merged = my + '.hgmerge'
if not os.path.exists(my) or not os.path.exists(orig) or \
not os.path.exists(your):
print "One or more of the merge files do not exist"
sys.exit(1)
if os.path.exists(merged):
os.remove(merged)
output = open(merged, 'w')
p = subprocess.Popen(['diff3', '-m',
'-L', 'local', '-L', 'base', '-L', 'other',
my, orig, your], stdout=output)
result = p.wait()
output.close()
if result == 0 or result == 1:
os.remove(my)
os.rename(merged, my)
if result == 0:
print "diff3 merged automatically"
elif result == 1:
print " Conflicts: " + my
log = open('hgmerge.log', 'a')
log.write( "Conflicts: " + my + "\n" )
log.close()
else:
print " Merge failed (binary file?): " + my
log = open('hgmerge.log', 'a')
log.write( "Failed: " + my + "\n" )
log.close()
sys.exit(result)
More information about the Mercurial
mailing list