src/topic/destination.py
changeset 1871 58ef5699fb35
parent 1870 8dd5200b4086
child 1878 c44f161575ba
equal deleted inserted replaced
1870:8dd5200b4086 1871:58ef5699fb35
     1 from mercurial import revset
       
     2 from mercurial import error
     1 from mercurial import error
       
     2 from mercurial import util
       
     3 from mercurial import destutil
       
     4 from mercurial import extensions
       
     5 from mercurial.i18n import _
       
     6 
       
     7 def _destmergebranch(orig, repo):
       
     8     p1 = repo['.']
       
     9     top = p1.topic()
       
    10     if top:
       
    11         heads = repo.revs('heads(topic(.)::topic(.))')
       
    12         if p1.rev() not in heads:
       
    13             raise error.Abort(_("not at topic head, update or explicit"))
       
    14         elif 1 == len(heads):
       
    15             # should look at all branch involved but... later
       
    16             bhead = ngtip(repo, p1.branch(), all=True)
       
    17             if not bhead:
       
    18                 raise error.Abort(_("nothing to merge"))
       
    19             elif 1 == len(bhead):
       
    20                 return bhead.first()
       
    21             else:
       
    22                 raise error.Abort(_("branch '%s' has %d heads - "
       
    23                                    "please merge with an explicit rev")
       
    24                                  % (p1.branch(), len(bhead)),
       
    25                                  hint=_("run 'hg heads .' to see heads"))
       
    26         elif 2 == len(heads):
       
    27             heads = [r for r in heads if r != p1.rev()]
       
    28             # XXX: bla bla bla bla bla
       
    29             if 1 < len(heads):
       
    30                 raise error.Abort(_('working directory not at a head revision'),
       
    31                                  hint=_("use 'hg update' or merge with an "
       
    32                                         "explicit revision"))
       
    33             return heads[0]
       
    34         elif 2 < len(heads):
       
    35             raise error.Abort(_("topic '%s' has %d heads - "
       
    36                                 "please merge with an explicit rev")
       
    37                               % (top, len(heads)))
       
    38         else:
       
    39             assert False # that's impossible
       
    40     return orig(repo)
       
    41 
       
    42 def setupdest():
       
    43     if util.safehasattr(destutil, '_destmergebranch'):
       
    44         extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch)
       
    45 
     3 def ngtip(repo, branch, all=False):
    46 def ngtip(repo, branch, all=False):
     4     """tip new generation"""
    47     """tip new generation"""
     5     ## search for untopiced heads of branch
    48     ## search for untopiced heads of branch
     6     # could be heads((::branch(x) - topic()))
    49     # could be heads((::branch(x) - topic()))
     7     # but that is expensive
    50     # but that is expensive