localrepo: introduce "prepushoutgoinghooks" to extend outgoing check easily
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 16 Apr 2014 00:37:24 +0900
changeset 21043 6c383c871fdb
parent 21042 32b3331f18eb
child 21044 52a5eabf1f2f
localrepo: introduce "prepushoutgoinghooks" to extend outgoing check easily This patch introduces "prepushoutgoinghooks" to extend outgoing check before pushing changesets to remote easily. This chooses the function returning "util.hooks" instead of the one to be overridden. The latter may cause problems silently, if one of overriders forgets (or fails) to execute a kind of "super(xxx, self).overridden(...)". In the other hand, the former can ensure that all registered functions are invoked, unless one of them raises an exception.
mercurial/exchange.py
mercurial/localrepo.py
--- a/mercurial/exchange.py	Wed Apr 16 00:37:24 2014 +0900
+++ b/mercurial/exchange.py	Wed Apr 16 00:37:24 2014 +0900
@@ -103,6 +103,9 @@
         try:
             _pushdiscovery(pushop)
             if _pushcheckoutgoing(pushop):
+                pushop.repo.prepushoutgoinghooks(pushop.repo,
+                                                 pushop.remote,
+                                                 pushop.outgoing)
                 _pushchangeset(pushop)
             _pushcomputecommonheads(pushop)
             _pushsyncphase(pushop)
--- a/mercurial/localrepo.py	Wed Apr 16 00:37:24 2014 +0900
+++ b/mercurial/localrepo.py	Wed Apr 16 00:37:24 2014 +0900
@@ -1696,6 +1696,13 @@
         """
         pass
 
+    @unfilteredpropertycache
+    def prepushoutgoinghooks(self):
+        """Return util.hooks consists of "(repo, remote, outgoing)"
+        functions, which are called before pushing changesets.
+        """
+        return util.hooks()
+
     def push(self, remote, force=False, revs=None, newbranch=False):
         return exchange.push(self, remote, force, revs, newbranch)