Patchwork [4,of,6] exchange: add pushafterdiscovery event

login
register
mail settings
Submitter Gregory Szorc
Date Aug. 19, 2014, 5:30 a.m.
Message ID <8548dee3e8f6699c0e2c.1408426216@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/5504/
State Changes Requested
Headers show

Comments

Gregory Szorc - Aug. 19, 2014, 5:30 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1408424584 25200
#      Mon Aug 18 22:03:04 2014 -0700
# Node ID 8548dee3e8f6699c0e2c530f1d5fa7e1009a540c
# Parent  be70417132e8c06c4634150cca755b3742bc7ac3
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.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -180,8 +180,9 @@  def push(repo, remote, force=False, revs
         if not unbundle:
             lock = pushop.remote.lock()
         try:
             _pushdiscovery(pushop)
+            pushop.repo.events.pushafterdiscovery(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
@@ -310,8 +310,14 @@  class localrepository(object):
         # argument. Event handlers can modify the pushop to change what will
         # be done by the push operation.
         self.events.register('pushbegin')
 
+        # pushafterdiscovery is fired in the middle of a push operation, after
+        # discovery has been performed but before data is pushed to the remote.
+        # Event handlers receive the exchange.pushoperation instance for the
+        # in-progress push.
+        self.events.register('pushafterdiscovery')
+
     def close(self):
         pass
 
     def _restrictcapabilities(self, caps):
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