Patchwork pushkey: run hook after the lock release

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 23, 2014, 12:53 a.m.
Message ID <526505e8fe812752dbf4.1419296028@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7210/
State Accepted
Commit 915ac9403e138d251f6081e55e4eb838db193614
Headers show

Comments

Pierre-Yves David - Dec. 23, 2014, 12:53 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1419292119 28800
#      Mon Dec 22 15:48:39 2014 -0800
# Node ID 526505e8fe812752dbf45b475b3e9bea4aa322ba
# Parent  17b2ab77f4539e2ed0dd00d1ceefcf1d6b165346
pushkey: run hook after the lock release

The pushkey operation used to be in its own wireprotocol command and (in
practice) always be lock free when running the hook. With bundle2, it happen in
a greater scheme and a hook running locking command would get stuck. We now run
such hooks after the lock release as similar hook do.

Bundle2 test are altered to ensure we are lockfree at hook running time.
Matt Mackall - Dec. 23, 2014, 6:53 p.m.
On Mon, 2014-12-22 at 16:53 -0800, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1419292119 28800
> #      Mon Dec 22 15:48:39 2014 -0800
> # Node ID 526505e8fe812752dbf45b475b3e9bea4aa322ba
> # Parent  17b2ab77f4539e2ed0dd00d1ceefcf1d6b165346
> pushkey: run hook after the lock release

Queued for default, thanks.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1783,12 +1783,14 @@  class localrepository(object):
             if exc.hint:
                 self.ui.write_err(_("(%s)\n") % exc.hint)
             return False
         self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key))
         ret = pushkey.push(self, namespace, key, old, new)
-        self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
-                  ret=ret)
+        def runhook():
+            self.hook('pushkey', namespace=namespace, key=key, old=old, new=new,
+                      ret=ret)
+        self._afterlock(runhook)
         return ret
 
     def listkeys(self, namespace):
         self.hook('prelistkeys', throw=True, namespace=namespace)
         self.ui.debug('listing keys for "%s"\n' % namespace)
diff --git a/tests/test-bundle2-exchange.t b/tests/test-bundle2-exchange.t
--- a/tests/test-bundle2-exchange.t
+++ b/tests/test-bundle2-exchange.t
@@ -22,10 +22,11 @@  enable obsolescence
   > [hooks]
   > changegroup = sh -c  "HG_LOCAL= python \"$TESTDIR/printenv.py\" changegroup"
   > b2x-pretransactionclose.tip = hg log -r tip -T "pre-close-tip:{node|short} {phase} {bookmarks}\n"
   > b2x-transactionclose.tip = hg log -r tip -T "postclose-tip:{node|short} {phase} {bookmarks}\n"
   > b2x-transactionclose.env = sh -c  "HG_LOCAL= python \"$TESTDIR/printenv.py\" b2x-transactionclose"
+  > pushkey= echo pushkey: lock state after \"\$HG_NAMESPACE\"; hg debuglock
   > EOF
 
 The extension requires a repo (currently unused)
 
   $ hg init main
@@ -165,10 +166,16 @@  add extra data to test their exchange du
 push
   $ hg -R main push other --rev eea13746799a --bookmark book_eea1
   pushing to other
   searching for changes
   pre-close-tip:eea13746799a public book_eea1
+  pushkey: lock state after "phases"
+  lock:  free
+  wlock: free
+  pushkey: lock state after "bookmarks"
+  lock:  free
+  wlock: free
   postclose-tip:eea13746799a public book_eea1
   b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2-EXP=1 HG_NEW_OBSMARKERS=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_PHASES_MOVED=1 HG_SOURCE=push HG_URL=push
   changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_SOURCE=push HG_URL=push
   remote: adding changesets
   remote: adding manifests
@@ -252,10 +259,13 @@  push over ssh
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
   updating bookmark book_5fdd
   remote: pre-close-tip:5fddd98957c8 draft book_5fdd
+  remote: pushkey: lock state after "bookmarks"
+  remote: lock:  free
+  remote: wlock: free
   remote: postclose-tip:5fddd98957c8 draft book_5fdd
   remote: b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2-EXP=1 HG_NEW_OBSMARKERS=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
   remote: changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
   pre-close-tip:02de42196ebe draft book_02de
   postclose-tip:02de42196ebe draft book_02de