topic: hg <= 4.8 compatibility for wrapping exchange._checkpublish() stable
authorAnton Shestakov <av6@dwimlabs.net>
Wed, 08 Apr 2020 01:02:23 +0800
branchstable
changeset 5277 9ed5f9c5d8ae
parent 5275 1a81bbc94d45
child 5278 6434f3c4f7aa
child 5285 8d955635cf45
topic: hg <= 4.8 compatibility for wrapping exchange._checkpublish() phase-divergent update to 1a81bbc94d45:
hgext3rd/evolve/safeguard.py
hgext3rd/topic/__init__.py
--- a/hgext3rd/evolve/safeguard.py	Wed Apr 08 01:02:23 2020 +0800
+++ b/hgext3rd/evolve/safeguard.py	Wed Apr 08 01:02:23 2020 +0800
@@ -19,11 +19,35 @@
 
 eh = exthelper.exthelper()
 
-# hg <= 4.8
+# hg <= 4.8 (33d30fb1e4ae)
 if b'auto-publish' not in configitems.coreitems.get(b'experimental', {}):
 
     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
--- a/hgext3rd/topic/__init__.py	Wed Apr 08 01:02:23 2020 +0800
+++ b/hgext3rd/topic/__init__.py	Wed Apr 08 01:02:23 2020 +0800
@@ -383,9 +383,16 @@
     extensions.wrapfunction(changelog.changelog, 'add', wrapadd)
     # Make exchange._checkpublish handle experimental.topic.publish-bare-branch
     if util.safehasattr(exchange, '_checkpublish'):
-        # hg <= 4.8 (33d30fb1e4ae)
         extensions.wrapfunction(exchange, '_checkpublish',
                                 flow.replacecheckpublish)
+    else:
+        # hg <= 4.8 (33d30fb1e4ae)
+        try:
+            evolve = extensions.find(b'evolve')
+            extensions.wrapfunction(evolve.safeguard, '_checkpublish',
+                                    flow.replacecheckpublish)
+        except (KeyError, AttributeError):
+            pass
 
     server.setupserver(ui)