Patchwork [STABLE] merge: run update hook after the last wlock release

login
register
mail settings
Submitter Matt Harbison
Date April 29, 2015, 7:56 p.m.
Message ID <a4a74f5671b728e071cc.1430337364@MATT7H-PC.attotech.com>
Download mbox | patch
Permalink /patch/8818/
State Accepted
Commit 51844b8b5017658216129c1817af1a816e44b8bf
Headers show

Comments

Matt Harbison - April 29, 2015, 7:56 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1430337151 14400
#      Wed Apr 29 15:52:31 2015 -0400
# Branch stable
# Node ID a4a74f5671b728e071cc621489850532f1ed91d2
# Parent  e530cde6d115f4e97da783444a8ab722421c67e1
merge: run update hook after the last wlock release

There were 2 test failures in 3.4-rc when running test-hook.t with the
largefiles extension enabled.  For context, the first is a commit hook:

  @@ -618,9 +621,9 @@
     $ echo 'update = hg id' >> .hg/hgrc
     $ echo bb > a
     $ hg ci -ma
  -  223eafe2750c tip
  +  d3354c4310ed+
     $ hg up 0
  -  cb9a9f314b8b
  +  223eafe2750c+ tip
     1 files updated, 0 files merged, 0 files removed, 0 files unresolved

   make sure --verbose (and --quiet/--debug etc.) are propagated to the local ui

In both cases, largefiles acquires the wlock before calling into core, which
also acquires the wlock.  The first case was fixed in 57f1dbc99631 by ensuring
the hook only runs after the lock has been fully released.  The full release is
important, because that is what writes dirstate to the disk, allowing external
hooks to see the result of the update.  This simply changes how the update hook
is called, so that it too is deferred until the lock is finally released.

There are many uses of mergemod.update(), but in terms of commands, it looks
like the following commands take wlock while calling mergemod.update(), and
therefore will now have their hook fired at a later time:

    backout, fetch, histedit, qpush, rebase, shelve, transplant

Unlike the others, fetch immediately unlocks after calling update(), so for all
intents and purposes, its hook invocation is not deferred (but the external hook
still sees the proper state).
Pierre-Yves David - April 29, 2015, 7:58 p.m.
On 04/29/2015 12:56 PM, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1430337151 14400
> #      Wed Apr 29 15:52:31 2015 -0400
> # Branch stable
> # Node ID a4a74f5671b728e071cc621489850532f1ed91d2
> # Parent  e530cde6d115f4e97da783444a8ab722421c67e1
> merge: run update hook after the last wlock release

Patch looks good to me.
Matt Mackall - April 29, 2015, 8:56 p.m.
On Wed, 2015-04-29 at 15:56 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1430337151 14400
> #      Wed Apr 29 15:52:31 2015 -0400
> # Branch stable
> # Node ID a4a74f5671b728e071cc621489850532f1ed91d2
> # Parent  e530cde6d115f4e97da783444a8ab722421c67e1
> merge: run update hook after the last wlock release

Queued for stable, thanks.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1167,7 +1167,9 @@  def update(repo, node, branchmerge, forc
         wlock.release()
 
     if not partial:
-        repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
+        def updatehook(parent1=xp1, parent2=xp2, error=stats[3]):
+            repo.hook('update', parent1=parent1, parent2=parent2, error=error)
+        repo._afterlock(updatehook)
     return stats
 
 def graft(repo, ctx, pctx, labels):
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -613,7 +613,9 @@  make sure --traceback works on hook impo
 
 Issue1827: Hooks Update & Commit not completely post operation
 
-commit and update hooks should run after command completion
+commit and update hooks should run after command completion.  The largefiles
+use demonstrates a recursive wlock, showing the hook doesn't run until the
+final release (and dirstate flush).
 
   $ echo '[hooks]' > .hg/hgrc
   $ echo 'commit = hg id' >> .hg/hgrc
@@ -621,7 +623,7 @@  commit and update hooks should run after
   $ echo bb > a
   $ hg ci -ma
   223eafe2750c tip
-  $ hg up 0
+  $ hg up 0 --config extensions.largefiles=
   cb9a9f314b8b
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved