hgext3rd/topic/flow.py
changeset 3159 90515d0bfb08
parent 3158 678a9802c56b
child 3204 a342c454ccf3
equal deleted inserted replaced
3158:678a9802c56b 3159:90515d0bfb08
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
     3 from mercurial import (
     3 from mercurial import (
       
     4     commands,
     4     error,
     5     error,
       
     6     exchange,
       
     7     extensions,
     5     node,
     8     node,
     6     phases,
     9     phases,
       
    10     util,
     7 )
    11 )
     8 
    12 
     9 from mercurial.i18n import _
    13 from mercurial.i18n import _
    10 
    14 
    11 def enforcesinglehead(repo, tr):
    15 def enforcesinglehead(repo, tr):
    23     topublish = repo.revs('not public() and (%n:) - hidden() - topic()', startnode)
    27     topublish = repo.revs('not public() and (%n:) - hidden() - topic()', startnode)
    24     if topublish:
    28     if topublish:
    25         cl = repo.changelog
    29         cl = repo.changelog
    26         nodes = [cl.node(r) for r in topublish]
    30         nodes = [cl.node(r) for r in topublish]
    27         repo._phasecache.advanceboundary(repo, tr, phases.public, nodes)
    31         repo._phasecache.advanceboundary(repo, tr, phases.public, nodes)
       
    32 
       
    33 def wrappush(orig, repo, remote, *args, **kwargs):
       
    34     """interpret the --publish flag and pass it to the push operation"""
       
    35     newargs = kwargs.copy()
       
    36     if kwargs.pop('publish', False):
       
    37         opargs = kwargs.get('opargs')
       
    38         if opargs is None:
       
    39             opargs = {}
       
    40         newargs['opargs'] = opargs.copy()
       
    41         newargs['opargs']['publish'] = True
       
    42     return orig(repo, remote, *args, **newargs)
       
    43 
       
    44 def extendpushoperation(orig, *args, **kwargs):
       
    45     publish = kwargs.pop('publish', False)
       
    46     op = orig(*args, **kwargs)
       
    47     op.publish = publish
       
    48     return op
       
    49 
       
    50 def wrapphasediscovery(orig, pushop):
       
    51     orig(pushop)
       
    52     if pushop.publish:
       
    53         if not util.safehasattr(pushop, 'remotephases'):
       
    54             msg = _('--publish flag only supported from Mercurial 4.4 and higher')
       
    55             raise error.Abort(msg)
       
    56         if not pushop.remotephases.publishing:
       
    57             unfi = pushop.repo.unfiltered()
       
    58             droots = pushop.remotephases.draftroots
       
    59             revset = '%ln and (not public() or %ln::)'
       
    60             future = list(unfi.set(revset, pushop.futureheads, droots))
       
    61             pushop.outdatedphases = future
       
    62 
       
    63 def installpushflag(ui):
       
    64     entry = extensions.wrapcommand(commands.table, 'push', wrappush)
       
    65     entry[1].append(('', 'publish', False,
       
    66                     _('push the changeset as public')))
       
    67     extensions.wrapfunction(exchange, 'pushoperation', extendpushoperation)
       
    68     extensions.wrapfunction(exchange, '_pushdiscoveryphase', wrapphasediscovery)
       
    69     exchange.pushdiscoverymapping['phase'] = exchange._pushdiscoveryphase