safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
authorAnton Shestakov <av6@dwimlabs.net>
Sat, 01 Dec 2018 16:08:42 +0800
changeset 4287 b7b6a4524ef7
parent 4286 f9a9d2fe4af5
child 4288 00bc03f56f37
safeguard: don't reimplement auto-publish if it's in core (will be in 4.9)
hgext3rd/evolve/safeguard.py
tests/test-obsolete-push.t
--- a/hgext3rd/evolve/safeguard.py	Sat Dec 01 16:07:55 2018 +0800
+++ b/hgext3rd/evolve/safeguard.py	Sat Dec 01 16:08:42 2018 +0800
@@ -8,40 +8,48 @@
 # 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 error
+from mercurial.i18n import _
 
-from mercurial.i18n import _
+from mercurial import (
+    configitems,
+    error,
+)
 
 from . import exthelper
 
 eh = exthelper.exthelper()
 
-eh.configitem('experimental', 'auto-publish')
+# hg <= 4.8
+if 'auto-publish' not in configitems.coreitems.get('experimental', {}):
+
+    eh.configitem('experimental', 'auto-publish')
 
-@eh.reposetup
-def setuppublishprevention(ui, repo):
+    @eh.reposetup
+    def setuppublishprevention(ui, repo):
 
-    class noautopublishrepo(repo.__class__):
+        class noautopublishrepo(repo.__class__):
 
-        def checkpush(self, pushop):
-            super(noautopublishrepo, self).checkpush(pushop)
-            behavior = self.ui.config('experimental', 'auto-publish', 'publish')
-            nocheck = behavior not in ('warn', 'abort')
-            if nocheck or getattr(pushop, 'publish', False):
-                return
-            remotephases = pushop.remote.listkeys('phases')
-            publishing = remotephases.get('publishing', False)
-            if publishing:
-                if pushop.revs is None:
-                    published = self.filtered('served').revs("not public()")
-                else:
-                    published = self.revs("::%ln - public()", pushop.revs)
-                if published:
-                    if behavior == 'warn':
-                        self.ui.warn(_('%i changesets about to be published\n') % len(published))
-                    elif behavior == 'abort':
-                        msg = _('push would publish 1 changesets')
-                        hint = _("behavior controlled by 'experimental.auto-publish' config")
-                        raise error.Abort(msg, hint=hint)
+            def checkpush(self, pushop):
+                super(noautopublishrepo, self).checkpush(pushop)
+                behavior = self.ui.config('experimental', 'auto-publish', 'publish')
+                nocheck = behavior not in ('warn', 'abort')
+                if nocheck or getattr(pushop, 'publish', False):
+                    return
+                remotephases = pushop.remote.listkeys('phases')
+                publishing = remotephases.get('publishing', False)
+                if publishing:
+                    if pushop.revs is None:
+                        published = self.filtered('served').revs("not public()")
+                    else:
+                        published = self.revs("::%ln - public()", pushop.revs)
+                    if published:
+                        if behavior == 'warn':
+                            self.ui.warn(_('%i changesets about to be published\n')
+                                         % len(published))
+                        elif behavior == 'abort':
+                            msg = _('push would publish 1 changesets')
+                            hint = _("behavior controlled by "
+                                     "'experimental.auto-publish' config")
+                            raise error.Abort(msg, hint=hint)
 
-    repo.__class__ = noautopublishrepo
+        repo.__class__ = noautopublishrepo
--- a/tests/test-obsolete-push.t	Sat Dec 01 16:07:55 2018 +0800
+++ b/tests/test-obsolete-push.t	Sat Dec 01 16:08:42 2018 +0800
@@ -73,12 +73,12 @@
   $ hg push -r .
   pushing to $TESTTMP/source
   abort: push would publish 1 changesets
-  (behavior controlled by 'experimental.auto-publish' config)
+  (* 'experimental.auto-publish' config) (glob)
   [255]
   $ hg push
   pushing to $TESTTMP/source
   abort: push would publish 1 changesets
-  (behavior controlled by 'experimental.auto-publish' config)
+  (* 'experimental.auto-publish' config) (glob)
   [255]
 
 warning behavior