Patchwork [5,of,6] mq: convert mqrepo.checkpush into a beforepush pyhook

login
register
mail settings
Submitter Gregory Szorc
Date July 12, 2014, 8:12 p.m.
Message ID <be71c972fa2c2fe40060.1405195945@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/5152/
State Changes Requested
Headers show

Comments

Gregory Szorc - July 12, 2014, 8:12 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1405194867 25200
#      Sat Jul 12 12:54:27 2014 -0700
# Node ID be71c972fa2c2fe40060626ac4d150fa39b29c14
# Parent  b8382807ed1766b93799b94eaabe2774fbca65e2
mq: convert mqrepo.checkpush into a beforepush pyhook

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -3266,8 +3266,28 @@  def mqphasedefaults(repo, roots):
         qbase = repo[repo.mq.applied[0].node]
         roots[mqphase].add(qbase.node())
     return roots
 
+def mqrepobeforepush(repo, pushop=None):
+    """pyhook for beforepush"""
+    if repo.mq.applied and repo.mq.checkapplied and not pushop.force:
+        outapplied = [e.node for e in repo.mq.applied]
+        if pushop.revs:
+            # Assume applied patches have no non-patch descendants and
+            # are not on remote already. Filtering any changeset not
+            # pushed.
+            heads = set(pushop.revs)
+            for node in reversed(outapplied):
+                if node in heads:
+                    break
+                else:
+                    outapplied.pop()
+        # looking for pushed and shared changeset
+        for node in outapplied:
+            if repo[node].phase() < phases.secret:
+                raise util.Abort(_('source has mq patches applied'))
+        # no non-secret patches pushed
+
 def reposetup(ui, repo):
     class mqrepo(repo.__class__):
         @localrepo.unfilteredpropertycache
         def mq(self):
@@ -3294,28 +3314,8 @@  def reposetup(ui, repo):
 
             return super(mqrepo, self).commit(text, user, date, match, force,
                                               editor, extra)
 
-        def checkpush(self, pushop):
-            if self.mq.applied and self.mq.checkapplied and not pushop.force:
-                outapplied = [e.node for e in self.mq.applied]
-                if pushop.revs:
-                    # Assume applied patches have no non-patch descendants and
-                    # are not on remote already. Filtering any changeset not
-                    # pushed.
-                    heads = set(pushop.revs)
-                    for node in reversed(outapplied):
-                        if node in heads:
-                            break
-                        else:
-                            outapplied.pop()
-                # looking for pushed and shared changeset
-                for node in outapplied:
-                    if self[node].phase() < phases.secret:
-                        raise util.Abort(_('source has mq patches applied'))
-                # no non-secret patches pushed
-            super(mqrepo, self).checkpush(pushop)
-
         def _findtags(self):
             '''augment tags from base class with patch tags'''
             result = super(mqrepo, self)._findtags()
 
@@ -3355,8 +3355,9 @@  def reposetup(ui, repo):
     if repo.local():
         repo.__class__ = mqrepo
 
         repo._phasedefaults.append(mqphasedefaults)
+        repo.addpyhook('beforepush', mqrepobeforepush)
 
 def mqimport(orig, ui, repo, *args, **kwargs):
     if (util.safehasattr(repo, 'abortifwdirpatched')
         and not kwargs.get('no_commit', False)):