Patchwork [3,of,6] exchange: add afterpush pyhook

login
register
mail settings
Submitter Gregory Szorc
Date July 12, 2014, 8:12 p.m.
Message ID <5a9b80c2b3e681e15a62.1405195943@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/5150/
State Changes Requested
Headers show

Comments

Gregory Szorc - July 12, 2014, 8:12 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@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."
Matt Mackall - July 14, 2014, 10:15 p.m.
On Sat, 2014-07-12 at 13:12 -0700, Gregory Szorc wrote:
>          # Maps names to list of callables.
> -        self._hooks = {}
> +        self._hooks = {
> +            'afterpush': [],
> +        }

Seems like we should handle missing entries instead.

Patch

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