contrib/nopushpublish.py
author Pulkit Goyal <7895pulkit@gmail.com>
Fri, 13 Oct 2017 10:01:38 +0530
changeset 3059 02b220984b01
parent 1670 4f5e915ddb71
permissions -rw-r--r--
topics: use stack.stack() instead of stack.stackdata() stack.stackdata() also calls stack.stack() internally. Moreover if we just want to calculate changesetcount, troubled count, it will be cheap to calculate using stack.stack rather than stackdata().

# Extension which prevent changeset to be turn public by push operation
#
# Copyright 2011 Logilab SA        <contact@logilab.fr>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


from mercurial import extensions, util
from mercurial import discovery

def checkpublish(orig, repo, remote, outgoing, *args):

    # is remote publishing?
    publish = True
    if 'phases' in remote.listkeys('namespaces'):
        remotephases = remote.listkeys('phases')
        publish = remotephases.get('publishing', False)

    npublish = 0
    if publish:
        for rev in outgoing.missing:
            if repo[rev].phase():
                npublish += 1
    if npublish:
        repo.ui.warn("Push would publish %s changesets" % npublish)

    ret = orig(repo, remote, outgoing, *args)
    if npublish:
        raise util.Abort("Publishing push forbidden",
                         hint="Use `hg phase -p <rev>` to manually publish them")

    return ret

def uisetup(ui):
    extensions.wrapfunction(discovery, 'checkheads', checkpublish)