[PATCH 3 of 6] exchange: add pushbegin event

Gregory Szorc gregory.szorc at gmail.com
Tue Aug 19 00:30:15 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1408423943 25200
#      Mon Aug 18 21:52:23 2014 -0700
# Node ID be70417132e8c06c4634150cca755b3742bc7ac3
# Parent  ec6632877a28678be887e4041409c398aadec529
exchange: add pushbegin event

Extensions may wish to influence what is being done by a push
operation. To facilitate this, we establish the "pushbegin"
event, which fires immediately after a pushoperation is created
and gives extensions the ability to inspect and/or change
the pushoperation before any additional action is taken.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -138,8 +138,9 @@ def push(repo, remote, force=False, revs
         we have outgoing changesets but refused to push
       - other values as described by addchangegroup()
     '''
     pushop = pushoperation(repo, remote, force, revs, newbranch)
+    repo.events.pushbegin(pushop)
     if pushop.remote.local():
         missing = (set(pushop.repo.requirements)
                    - pushop.remote.local().supported)
         if missing:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -304,8 +304,14 @@ class localrepository(object):
         self.filteredrevcache = {}
 
         self.events = util.eventmanager()
 
+        # pushbefore is fired when a push operation is about to be performed.
+        # Event handlers will receive an exchange.pushoperation as a single
+        # argument. Event handlers can modify the pushop to change what will
+        # be done by the push operation.
+        self.events.register('pushbegin')
+
     def close(self):
         pass
 
     def _restrictcapabilities(self, caps):
diff --git a/tests/test-events.t b/tests/test-events.t
new file mode 100644
--- /dev/null
+++ b/tests/test-events.t
@@ -0,0 +1,30 @@
+  $ cat >> events.py << EOF
+  > from mercurial import exchange
+  > def pushbegin(pushop):
+  >     assert isinstance(pushop, exchange.pushoperation)
+  >     pushop.ui.write('pushbegin %s\n' % pushop.repo.path)
+  > def reposetup(ui, repo):
+  >     repo.events.pushbegin += pushbegin
+  > EOF
+
+  $ hg init server
+  $ hg init client
+  $ cd client
+  $ cat >> .hg/hgrc << EOF
+  > [extensions]
+  > events = $TESTTMP/events.py
+  > EOF
+
+Ensure push-related events are firing
+
+  $ touch foo
+  $ hg commit -A -m 'initial'
+  adding foo
+  $ hg push ../server
+  pushing to ../server
+  pushbegin $TESTTMP/client/.hg
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files


More information about the Mercurial-devel mailing list