mercurial/filemerge.py
changeset 40478 86dfae98a3a2
parent 39359 bc0eb1dc6aae
child 41365 876494fd967d
equal deleted inserted replaced
40477:592feb3f88b1 40478:86dfae98a3a2
    11 import os
    11 import os
    12 import re
    12 import re
    13 import shutil
    13 import shutil
    14 
    14 
    15 from .i18n import _
    15 from .i18n import _
    16 from .node import nullid, short
    16 from .node import (
       
    17     hex,
       
    18     nullid,
       
    19     short,
       
    20 )
    17 
    21 
    18 from . import (
    22 from . import (
    19     encoding,
    23     encoding,
    20     error,
    24     error,
    21     formatter,
    25     formatter,
    25     scmutil,
    29     scmutil,
    26     simplemerge,
    30     simplemerge,
    27     tagmerge,
    31     tagmerge,
    28     templatekw,
    32     templatekw,
    29     templater,
    33     templater,
       
    34     templateutil,
    30     util,
    35     util,
    31 )
    36 )
    32 
    37 
    33 from .utils import (
    38 from .utils import (
    34     procutil,
    39     procutil,
   534     # directory and tell the user how to get it is my best idea, but it's
   539     # directory and tell the user how to get it is my best idea, but it's
   535     # clunky.)
   540     # clunky.)
   536     raise error.InMemoryMergeConflictsError('in-memory merge does not support '
   541     raise error.InMemoryMergeConflictsError('in-memory merge does not support '
   537                                             'external merge tools')
   542                                             'external merge tools')
   538 
   543 
       
   544 def _describemerge(ui, repo, mynode, fcl, fcb, fco, env, toolpath, args):
       
   545     tmpl = ui.config('ui', 'pre-merge-tool-output-template')
       
   546     if not tmpl:
       
   547         return
       
   548 
       
   549     mappingdict = templateutil.mappingdict
       
   550     props = {'ctx': fcl.changectx(),
       
   551              'node': hex(mynode),
       
   552              'path': fcl.path(),
       
   553              'local': mappingdict({'ctx': fcl.changectx(),
       
   554                                    'fctx': fcl,
       
   555                                    'node': hex(mynode),
       
   556                                    'name': _('local'),
       
   557                                    'islink': 'l' in fcl.flags(),
       
   558                                    'label': env['HG_MY_LABEL']}),
       
   559              'base': mappingdict({'ctx': fcb.changectx(),
       
   560                                   'fctx': fcb,
       
   561                                   'name': _('base'),
       
   562                                   'islink': 'l' in fcb.flags(),
       
   563                                   'label': env['HG_BASE_LABEL']}),
       
   564              'other': mappingdict({'ctx': fco.changectx(),
       
   565                                    'fctx': fco,
       
   566                                    'name': _('other'),
       
   567                                    'islink': 'l' in fco.flags(),
       
   568                                    'label': env['HG_OTHER_LABEL']}),
       
   569              'toolpath': toolpath,
       
   570              'toolargs': args}
       
   571 
       
   572     # TODO: make all of this something that can be specified on a per-tool basis
       
   573     tmpl = templater.unquotestring(tmpl)
       
   574 
       
   575     # Not using cmdutil.rendertemplate here since it causes errors importing
       
   576     # things for us to import cmdutil.
       
   577     tres = formatter.templateresources(ui, repo)
       
   578     t = formatter.maketemplater(ui, tmpl, defaults=templatekw.keywords,
       
   579                                 resources=tres)
       
   580     ui.status(t.renderdefault(props))
       
   581 
   539 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
   582 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
   540     tool, toolpath, binary, symlink, scriptfn = toolconf
   583     tool, toolpath, binary, symlink, scriptfn = toolconf
   541     if fcd.isabsent() or fco.isabsent():
   584     if fcd.isabsent() or fco.isabsent():
   542         repo.ui.warn(_('warning: %s cannot merge change/delete conflict '
   585         repo.ui.warn(_('warning: %s cannot merge change/delete conflict '
   543                        'for %s\n') % (tool, fcd.path()))
   586                        'for %s\n') % (tool, fcd.path()))
   582             repo.ui.status(_('running merge tool %s for file %s\n') %
   625             repo.ui.status(_('running merge tool %s for file %s\n') %
   583                            (tool, fcd.path()))
   626                            (tool, fcd.path()))
   584         if scriptfn is None:
   627         if scriptfn is None:
   585             cmd = toolpath + ' ' + args
   628             cmd = toolpath + ' ' + args
   586             repo.ui.debug('launching merge tool: %s\n' % cmd)
   629             repo.ui.debug('launching merge tool: %s\n' % cmd)
       
   630             _describemerge(ui, repo, mynode, fcd, fca, fco, env, toolpath, args)
   587             r = ui.system(cmd, cwd=repo.root, environ=env,
   631             r = ui.system(cmd, cwd=repo.root, environ=env,
   588                           blockedtag='mergetool')
   632                           blockedtag='mergetool')
   589         else:
   633         else:
   590             repo.ui.debug('launching python merge script: %s:%s\n' %
   634             repo.ui.debug('launching python merge script: %s:%s\n' %
   591                           (toolpath, scriptfn))
   635                           (toolpath, scriptfn))