[PATCH 4 of 6 events v3] exchange: add pushafterdiscovery event

Gregory Szorc gregory.szorc at gmail.com
Sun Sep 28 16:01:42 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1408424584 25200
#      Mon Aug 18 22:03:04 2014 -0700
# Node ID 5fae746b4551e2c593aca077d25f8b6a4e5b6159
# Parent  33cbfe6b815d88ebee229e372af69c8276fce29c
exchange: add pushafterdiscovery event

Extensions may wish to inject code after discovery. For example,
they may wish to ban certain changesets or changesets with certain
content from being pushed. The "preoutgoing" hook facilitates this
today. However, it doesn't have access to the rich pushoperation
object because of backwards compatibility. The pushafterdiscovery
event gives extensions a more robust injection point.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -196,8 +196,9 @@ def push(repo, remote, force=False, revs
         if not unbundle:
             lock = pushop.remote.lock()
         try:
             _pushdiscovery(pushop)
+            pushop.repo.events.pushafterdiscovery(pushop=pushop)
             if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
                                           False)
                 and pushop.remote.capable('bundle2-exp')):
                 _pushbundle2(pushop)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1792,4 +1792,17 @@ class localrepoevents(util.eventmanager)
         Expected use cases include policy checking a push's parameters and
         modifying what a push attempts to do.
         '''
 
+    def pushafterdiscovery(pushop):
+        '''Event fired during push, after discovery has been performed.
+
+        Event handlers receive the repo instance and an exchange.pushoperation
+        corresponding to the active push.
+
+        One of the first operations done as part of push is to discover which
+        nodes are present on the remote and thus which nodes and heads will
+        be pushed. This event fires after discovery has been performed.
+
+        Expected use cases of this event include examining and possibly
+        modifying the set of outgoing nodes and heads.
+        '''
diff --git a/tests/test-events.t b/tests/test-events.t
--- a/tests/test-events.t
+++ b/tests/test-events.t
@@ -2,10 +2,16 @@
   > from mercurial import exchange
   > def pushbegin(pushop):
   >     assert isinstance(pushop, exchange.pushoperation)
   >     pushop.ui.write('pushbegin %s\n' % pushop.repo.path)
+  > 
+  > def pushafterdiscovery(pushop):
+  >     assert isinstance(pushop, exchange.pushoperation)
+  >     pushop.ui.write('pushafterdiscovery %s\n' % pushop.repo.path)
+  > 
   > def reposetup(ui, repo):
   >     repo.events.pushbegin += pushbegin
+  >     repo.events.pushafterdiscovery += pushafterdiscovery
   > EOF
 
   $ hg init server
   $ hg init client
@@ -23,8 +29,9 @@ Ensure push-related events are firing
   $ hg push ../server
   pushing to ../server
   pushbegin $TESTTMP/client/.hg
   searching for changes
+  pushafterdiscovery $TESTTMP/client/.hg
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files


More information about the Mercurial-devel mailing list