[PATCH 1 of 2] localrepo: add afterpush()

Gregory Szorc gregory.szorc at gmail.com
Mon Jul 7 22:43:06 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1404785357 25200
#      Mon Jul 07 19:09:17 2014 -0700
# Node ID 30333e516874716b8d9b41450282d1f22b87eba1
# Parent  7537e57f5dbd0805aad3c9e5e4f7dd8bbf6bbde1
localrepo: add afterpush()

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 introduces localrepo.afterpush() to complement
localrepo.checkpush(). It gives extensions a clear and easy-to-use
extensibility point for "do your post-push operations here."

Changing localrepo.push() to return a pushoperation was considered.
However, this would break a long-standing API and would likely break a
handful of extensions. While this API is internal, the author believed
it best to avoid the concern entirely by introducing a new method.

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.afterpush(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
@@ -1588,8 +1588,24 @@ class localrepository(object):
 
     def push(self, remote, force=False, revs=None, newbranch=False):
         return exchange.push(self, remote, force, revs, newbranch)
 
+    def afterpush(self, pushop):
+        """Extensibility point to do work after push.
+
+        Extensions can wrap this method if they wish to perform additional
+        work after a push has completed.
+
+        The method receives an exchange.pushoperation instance.
+
+        When this is called, the lock on both the local and remote repositories
+        has already been released.
+
+        This is called even if the remote rejected the push. Extensions should
+        consult pushop.ret to determine whether the push was successful.
+        """
+        pass
+
     def stream_in(self, remote, requirements):
         lock = self.lock()
         try:
             # Save remote branchmap. We will use it later


More information about the Mercurial-devel mailing list