[PATCH 3 of 6] exchange: add afterpush pyhook

Gregory Szorc gregory.szorc at gmail.com
Sat Jul 12 15:12:23 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1405192232 25200
#      Sat Jul 12 12:10:32 2014 -0700
# Node ID 5a9b80c2b3e681e15a62a6692a03594149feb998
# Parent  8fa7b8de6cf5c6f809cabfd530d7f14383a18c2c
exchange: add afterpush pyhook

The exchange.pushoperation type exposes a lot of useful information
about the push. This information can be very valuable to extensions
wishing to perform additional activity at push time. For example, an
extension may wish to initiate code review against pushed changesets or
may wish to communicate to a 3rd party service that a push took place.

Until this patch, there was no easy way to do this. Extensions could
wrap localrepo.checkpush() to obtain an instance of the
exchange.pushoperation. They would have to stuff a reference somewhere
and later consult it after the wrapped localrepo.push() completed.
This was a bit hacky.

This patch adds an "afterpush" pyhook to complement localrepo.checkpush().
It gives extensions a clear and easy-to-use extensibility point for
"do your post-push operations here."

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -148,8 +148,9 @@ def push(repo, remote, force=False, revs
         if locallock is not None:
             locallock.release()
 
     _pushbookmark(pushop)
+    pushop.repo.runpyhook('afterpush', pushop=pushop)
     return pushop.ret
 
 def _pushdiscovery(pushop):
     # discovery
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -301,9 +301,11 @@ class localrepository(object):
         # - bookmark changes
         self.filteredrevcache = {}
 
         # Maps names to list of callables.
-        self._hooks = {}
+        self._hooks = {
+            'afterpush': [],
+        }
 
     def close(self):
         pass
 


More information about the Mercurial-devel mailing list