author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Thu, 06 Jun 2019 14:24:19 +0200 | |
branch | stable |
changeset 4665 | 756db65030c6 |
parent 4324 | e913546b9d79 |
child 4814 | 48b30ff742cb |
permissions | -rw-r--r-- |
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 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
11 |
from mercurial.i18n import _ |
2286
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
12 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
13 |
from mercurial import ( |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
14 |
configitems, |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
15 |
error, |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
16 |
) |
2286
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
17 |
|
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
18 |
from . import exthelper |
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
19 |
|
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
20 |
eh = exthelper.exthelper() |
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
21 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
22 |
# hg <= 4.8 |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
23 |
if 'auto-publish' not in configitems.coreitems.get('experimental', {}): |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
24 |
|
4324
e913546b9d79
configitems: move the default values to the registrar decorator
Matt Harbison <matt_harbison@yahoo.com>
parents:
4287
diff
changeset
|
25 |
eh.configitem('experimental', 'auto-publish', 'publish') |
3080
461c9d940519
evolve: registed configitems if available
Boris Feld <boris.feld@octobus.net>
parents:
2286
diff
changeset
|
26 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
27 |
@eh.reposetup |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
28 |
def setuppublishprevention(ui, repo): |
2286
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
29 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
30 |
class noautopublishrepo(repo.__class__): |
2286
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
31 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
32 |
def checkpush(self, pushop): |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
33 |
super(noautopublishrepo, self).checkpush(pushop) |
4324
e913546b9d79
configitems: move the default values to the registrar decorator
Matt Harbison <matt_harbison@yahoo.com>
parents:
4287
diff
changeset
|
34 |
behavior = self.ui.config('experimental', 'auto-publish') |
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
35 |
nocheck = behavior not in ('warn', 'abort') |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
36 |
if nocheck or getattr(pushop, 'publish', False): |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
37 |
return |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
38 |
remotephases = pushop.remote.listkeys('phases') |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
39 |
publishing = remotephases.get('publishing', False) |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
40 |
if publishing: |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
41 |
if pushop.revs is None: |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
42 |
published = self.filtered('served').revs("not public()") |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
43 |
else: |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
44 |
published = self.revs("::%ln - public()", pushop.revs) |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
45 |
if published: |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
46 |
if behavior == 'warn': |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
47 |
self.ui.warn(_('%i changesets about to be published\n') |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
48 |
% len(published)) |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
49 |
elif behavior == 'abort': |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
50 |
msg = _('push would publish 1 changesets') |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
51 |
hint = _("behavior controlled by " |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
52 |
"'experimental.auto-publish' config") |
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
53 |
raise error.Abort(msg, hint=hint) |
2286
a4c5744a7b93
safeguard: add an option to disable automatic publishing
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
54 |
|
4287
b7b6a4524ef7
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
Anton Shestakov <av6@dwimlabs.net>
parents:
4286
diff
changeset
|
55 |
repo.__class__ = noautopublishrepo |