--- a/hgext3rd/evolve/safeguard.py Tue Apr 07 19:33:40 2020 +0200
+++ b/hgext3rd/evolve/safeguard.py Wed Apr 08 16:16:09 2020 +0200
@@ -24,6 +24,30 @@
eh.configitem(b'experimental', b'auto-publish', b'publish')
+ def _checkpublish(pushop):
+ repo = pushop.repo
+ ui = repo.ui
+ behavior = ui.config(b'experimental', b'auto-publish')
+ nocheck = behavior not in (b'warn', b'abort')
+ if nocheck or getattr(pushop, 'publish', False):
+ return
+ remotephases = pushop.remote.listkeys(b'phases')
+ publishing = remotephases.get(b'publishing', False)
+ if publishing:
+ if pushop.revs is None:
+ published = repo.filtered(b'served').revs(b"not public()")
+ else:
+ published = repo.revs(b"::%ln - public()", pushop.revs)
+ if published:
+ if behavior == b'warn':
+ ui.warn(_(b'%i changesets about to be published\n')
+ % len(published))
+ elif behavior == b'abort':
+ msg = _(b'push would publish 1 changesets')
+ hint = _(b"behavior controlled by "
+ b"'experimental.auto-publish' config")
+ raise error.Abort(msg, hint=hint)
+
@eh.reposetup
def setuppublishprevention(ui, repo):
@@ -31,25 +55,6 @@
def checkpush(self, pushop):
super(noautopublishrepo, self).checkpush(pushop)
- behavior = self.ui.config(b'experimental', b'auto-publish')
- nocheck = behavior not in (b'warn', b'abort')
- if nocheck or getattr(pushop, 'publish', False):
- return
- remotephases = pushop.remote.listkeys(b'phases')
- publishing = remotephases.get(b'publishing', False)
- if publishing:
- if pushop.revs is None:
- published = self.filtered(b'served').revs(b"not public()")
- else:
- published = self.revs(b"::%ln - public()", pushop.revs)
- if published:
- if behavior == b'warn':
- self.ui.warn(_(b'%i changesets about to be published\n')
- % len(published))
- elif behavior == b'abort':
- msg = _(b'push would publish 1 changesets')
- hint = _(b"behavior controlled by "
- b"'experimental.auto-publish' config")
- raise error.Abort(msg, hint=hint)
+ _checkpublish(pushop)
repo.__class__ = noautopublishrepo