Patchwork [09,of,10] changegroup: use the `postclose` API on transaction

login
register
mail settings
Submitter Pierre-Yves David
Date Oct. 28, 2014, 3:41 p.m.
Message ID <195377110370544ac2e4.1414510883@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6485/
State Accepted
Headers show

Comments

Pierre-Yves David - Oct. 28, 2014, 3:41 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1414507463 -3600
#      Tue Oct 28 15:44:23 2014 +0100
# Branch stable
# Node ID 195377110370544ac2e4e74beb520f9b0af4e67f
# Parent  39eeb239ab3d900bad9adad309cfaa09ac95d810
changegroup: use the `postclose` API on transaction

The post transaction hooks run after the lock release (because hooks may want to
touch the repository). But they must only run if the transaction is successfully
closed.

We use the new `addpostclose` method on transaction to register a callback
installing this post lock release call.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -720,13 +720,10 @@  def addchangegroup(repo, source, srctype
             # publishing only alter behavior during push
             #
             # strip should not touch boundary at all
             phases.retractboundary(repo, tr, targetphase, added)
 
-
-        tr.close()
-
         if changesets > 0:
             if srctype != 'strip':
                 # During strip, branchcache is invalid but coming call to
                 # `destroyed` will repair it.
                 # In other case we can safely update cache on disk.
@@ -751,11 +748,15 @@  def addchangegroup(repo, source, srctype
                 newheads = [h for h in repo.heads() if h not in oldheads]
                 repo.ui.log("incoming",
                             "%s incoming changes - new heads: %s\n",
                             len(added),
                             ', '.join([hex(c[:6]) for c in newheads]))
-            repo._afterlock(runhooks)
+
+            tr.addpostclose('changegroup-runhooks-%020i' % clstart,
+                            lambda: repo._afterlock(runhooks))
+
+        tr.close()
 
     finally:
         tr.release()
     # never return 0 here:
     if dh < 0:
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
@@ -460,21 +460,19 @@  Doing the actual push: hook abort
   $ hg -R main push other -r e7ec4e813ba6
   pushing to other
   searching for changes
   transaction abort!
   rollback completed
-  changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=e7ec4e813ba6b07be2a0516ce1a74bb4e503f91a HG_SOURCE=push HG_URL=push
   abort: b2x-pretransactionclose.failpush hook exited with status 1
   [255]
 
   $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
   pushing to ssh://user@dummy/other
   searching for changes
   abort: b2x-pretransactionclose.failpush hook exited with status 1
   remote: transaction abort!
   remote: rollback completed
-  remote: changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=e7ec4e813ba6b07be2a0516ce1a74bb4e503f91a HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
   [255]
 
   $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
   pushing to http://localhost:$HGPORT2/
   searching for changes