[PATCH] mq: factor out push conditions checks

Patrick Mezard pmezard at gmail.com
Wed Jan 26 16:42:01 CST 2011


# HG changeset patch
# User Patrick Mezard <pmezard at gmail.com>
# Date 1296081661 -3600
# Node ID bfe69b3208110e2c99f7ffa0f8d1761ea5099fc5
# Parent  4b07578967e63df462e6bb683d9d9281d049da9f
mq: factor out push conditions checks

Some extensions (e.g. hgsubversion) completely override push command. Because
extensions load order is unspecified, if hgsubversion loads before mq, mq
checks about not pushing applied patches will be bypassed. Short of finding a
way to fix load order, extracting the checking logic will allow
hgsubversion-like extensions to run the check themselves.

diff -r 4b07578967e6 -r bfe69b320811 hgext/mq.py
--- a/hgext/mq.py	Wed Jan 26 12:35:02 2011 +0100
+++ b/hgext/mq.py	Wed Jan 26 23:41:01 2011 +0100
@@ -2919,7 +2919,7 @@
             return super(mqrepo, self).commit(text, user, date, match, force,
                                               editor, extra)
 
-        def push(self, remote, force=False, revs=None, newbranch=False):
+        def checkpush(self, force, revs):
             if self.mq.applied and not force:
                 haspatches = True
                 if revs:
@@ -2930,7 +2930,7 @@
                     haspatches = bool([n for n in revs if n in applied])
                 if haspatches:
                     raise util.Abort(_('source has mq patches applied'))
-            return super(mqrepo, self).push(remote, force, revs, newbranch)
+            super(mqrepo, self).checkpush(force, revs)
 
         def _findtags(self):
             '''augment tags from base class with patch tags'''
diff -r 4b07578967e6 -r bfe69b320811 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Wed Jan 26 12:35:02 2011 +0100
+++ b/mercurial/localrepo.py	Wed Jan 26 23:41:01 2011 +0100
@@ -1305,6 +1305,13 @@
         finally:
             lock.release()
 
+    def checkpush(self, force, revs):
+        """Extensions can override this function if additional checks have
+        to be performed before pushing, or call it if they override push
+        command.
+        """
+        pass
+
     def push(self, remote, force=False, revs=None, newbranch=False):
         '''Push outgoing changesets (limited by revs) from the current
         repository to remote. Return an integer:
@@ -1321,6 +1328,7 @@
         # unbundle assumes local user cannot lock remote repo (new ssh
         # servers, http servers).
 
+        self.checkpush(force, revs)
         lock = None
         unbundle = remote.capable('unbundle')
         if not unbundle:


More information about the Mercurial-devel mailing list