hgext3rd/evolve/safeguard.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 22 Nov 2017 13:40:47 +0100
changeset 3238 88f11b9881b2
parent 3080 461c9d940519
child 3647 626c5fa0ef07
permissions -rw-r--r--
cache: introduce a changelogsourcebase class This abstract class will help code that need a cache tracking the changelog content (eg: the branchmap cache). The cache key used is the same as what the branchmap uses. This code was headed for core during the 4.3 cycle but never made it there. So we starts with a copy in the evolve repository.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2286
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     1
# Code dedicated to adding various "safeguard" around evolution
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     2
#
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     3
# Some of these will be pollished and upstream when mature. Some other will be
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     4
# replaced by better alternative later.
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     5
#
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     6
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     7
#
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     8
# This software may be used and distributed according to the terms of the
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
     9
# GNU General Public License version 2 or any later version.
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    10
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    11
from mercurial import error
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    12
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    13
from mercurial.i18n import _
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    14
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    15
from . import exthelper
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    16
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    17
eh = exthelper.exthelper()
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    18
3080
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2286
diff changeset
    19
eh.configitem('experimental', 'auto-publish')
461c9d940519 evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents: 2286
diff changeset
    20
2286
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    21
@eh.reposetup
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    22
def setuppublishprevention(ui, repo):
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    23
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    24
    class noautopublishrepo(repo.__class__):
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    25
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    26
        def checkpush(self, pushop):
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    27
            super(noautopublishrepo, self).checkpush(pushop)
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    28
            behavior = repo.ui.config('experimental', 'auto-publish', 'default')
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    29
            remotephases = pushop.remote.listkeys('phases')
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    30
            publishing = remotephases.get('publishing', False)
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    31
            if behavior in ('warn', 'abort') and publishing:
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    32
                if pushop.revs is None:
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    33
                    published = repo.filtered('served').revs("not public()")
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    34
                else:
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    35
                    published = repo.revs("::%ln - public()", pushop.revs)
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    36
                if published:
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    37
                    if behavior == 'warn':
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    38
                        repo.ui.warn(_('%i changesets about to be published\n') % len(published))
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    39
                    elif behavior == 'abort':
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    40
                        msg = _('push would publish 1 changesets')
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    41
                        hint = _("behavior controlled by 'experimental.auto-publish' config")
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    42
                        raise error.Abort(msg, hint=hint)
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    43
a4c5744a7b93 safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff changeset
    44
    repo.__class__ = noautopublishrepo