From 14b32f640c552cd63916a27b7969fa6ec6b85a48 Mon Sep 17 00:00:00 2001 From: David Champion Date: Wed, 21 Apr 2010 11:57:45 -0500 Subject: [PATCH] merge: tool.premerge=keep will leave premerge markers in $local --- doc/hgrc.5.txt | 3 ++- mercurial/filemerge.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt index ab49ec9914..87d6d85bf4 100644 --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -454,7 +454,8 @@ Supported arguments: Default: ``$local $base $other`` ``premerge`` Attempt to run internal non-interactive 3-way merge tool before - launching external tool. + launching external tool. Options are ``true``, ``false``, or ``keep`` + to leave markers in the file if the premerge fails. Default: True ``binary`` This tool can merge binary files. Defaults to False, unless tool diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py index 0863d541a9..644ac693d3 100644 --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -7,7 +7,7 @@ from node import short from i18n import _ -import util, simplemerge, match +import util, simplemerge, match, error import os, tempfile, re, filecmp def _toolstr(ui, tool, part, default=""): @@ -176,7 +176,18 @@ def filemerge(repo, mynode, orig, fcd, fco, fca): ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) # do we attempt to simplemerge first? - if _toolbool(ui, tool, "premerge", not (binary or symlink)): + try: + premerge = _toolbool(ui, tool, "premerge", not (binary or symlink)) + except error.ConfigError: + premerge = _toolstr(ui, tool, "premerge").lower() + valid = 'keep'.split() + if premerge not in valid: + _valid = ', '.join(["'" + v + "'" for v in valid]) + raise error.ConfigError(_("%s.premerge not valid " + "('%s' is neither boolean nor %s)") % + (tool, premerge, _valid)) + + if premerge: r = simplemerge.simplemerge(ui, a, b, c, quiet=True) if not r: ui.debug(" premerge successful\n") @@ -184,7 +195,8 @@ def filemerge(repo, mynode, orig, fcd, fco, fca): os.unlink(b) os.unlink(c) return 0 - util.copyfile(back, a) # restore from backup and try again + if premerge != 'keep': + util.copyfile(back, a) # restore from backup and try again env = dict(HG_FILE=fd, HG_MY_NODE=short(mynode),