Patchwork [02,of,12,V2] localrepo: introduce "prepushoutgoinghooks" to extend outgoing check easily

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 15, 2014, 3:52 p.m.
Message ID <5d2bfff9bd3381e8f251.1397577143@juju>
Download mbox | patch
Permalink /patch/4371/
State Accepted
Commit 6c383c871fdb247d705f613f98def01ccdb94ea0
Headers show

Comments

Katsunori FUJIWARA - April 15, 2014, 3:52 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1397576244 -32400
#      Wed Apr 16 00:37:24 2014 +0900
# Node ID 5d2bfff9bd3381e8f2513fdd5cf1211de84a72b1
# Parent  12697af3f035c1a712edfcacf5e2e0d9324838d6
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.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -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)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -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)