mercurial/filemerge.py
changeset 11146 523330d567cf
parent 10944 6f1894d6a6b0
child 11148 a912f26777d3
equal deleted inserted replaced
11145:06586648eeec 11146:523330d567cf
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from node import short
     8 from node import short
     9 from i18n import _
     9 from i18n import _
    10 import util, simplemerge, match
    10 import util, simplemerge, match, error
    11 import os, tempfile, re, filecmp
    11 import os, tempfile, re, filecmp
    12 
    12 
    13 def _toolstr(ui, tool, part, default=""):
    13 def _toolstr(ui, tool, part, default=""):
    14     return ui.config("merge-tools", tool + "." + part, default)
    14     return ui.config("merge-tools", tool + "." + part, default)
    15 
    15 
   174         ui.status(_("merging %s\n") % fd)
   174         ui.status(_("merging %s\n") % fd)
   175 
   175 
   176     ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
   176     ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca))
   177 
   177 
   178     # do we attempt to simplemerge first?
   178     # do we attempt to simplemerge first?
   179     if _toolbool(ui, tool, "premerge", not (binary or symlink)):
   179     try:
       
   180         premerge = _toolbool(ui, tool, "premerge", not (binary or symlink))
       
   181     except error.ConfigError:
       
   182         premerge = _toolstr(ui, tool, "premerge").lower()
       
   183         valid = 'keep'.split()
       
   184         if premerge not in valid:
       
   185             _valid = ', '.join(["'" + v + "'" for v in valid])
       
   186             raise error.ConfigError(_("%s.premerge not valid "
       
   187                                       "('%s' is neither boolean nor %s)") %
       
   188                                     (tool, premerge, _valid))
       
   189 
       
   190     if premerge:
   180         r = simplemerge.simplemerge(ui, a, b, c, quiet=True)
   191         r = simplemerge.simplemerge(ui, a, b, c, quiet=True)
   181         if not r:
   192         if not r:
   182             ui.debug(" premerge successful\n")
   193             ui.debug(" premerge successful\n")
   183             os.unlink(back)
   194             os.unlink(back)
   184             os.unlink(b)
   195             os.unlink(b)
   185             os.unlink(c)
   196             os.unlink(c)
   186             return 0
   197             return 0
   187         util.copyfile(back, a) # restore from backup and try again
   198         if premerge != 'keep':
       
   199             util.copyfile(back, a) # restore from backup and try again
   188 
   200 
   189     env = dict(HG_FILE=fd,
   201     env = dict(HG_FILE=fd,
   190                HG_MY_NODE=short(mynode),
   202                HG_MY_NODE=short(mynode),
   191                HG_OTHER_NODE=str(fco.changectx()),
   203                HG_OTHER_NODE=str(fco.changectx()),
   192                HG_BASE_NODE=str(fca.changectx()),
   204                HG_BASE_NODE=str(fca.changectx()),