[PATCH 2 of 9 STABLE] commands: make backout acquire locks before processing

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Dec 1 12:18:40 CST 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1448993527 -32400
#      Wed Dec 02 03:12:07 2015 +0900
# Branch stable
# Node ID 206b6490a12ba8baf4224df3436457524fcb854d
# Parent  2934ccaf3b6f3d35de6a9783a5cc2f7197af85c2
commands: make backout acquire locks before processing

Before this patch, "hg backout" executes below before acquisition of
wlock.

  - cmdutil.checkunfinished()
  - cmdutil.bailifchanged()
  - repo.dirstate.parents()

It may cause unintentional result, if another command runs parallelly
(see also issue4368).

In addition to it, "hg backout" refers changelog for purposes below
without acquisition of store lock (slock), and it may cause
unintentional result, if store is updated parallelly.

  - show and update to the revision by 'repo.changelog.tip()'

  - examine for "created new head" by 'repo.branchheads()' and
    'cmdutil.commitstatus()'

To avoid this issue, this patch makes "hg backout" acquire wlock and
slock before processing.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -504,6 +504,15 @@ def backout(ui, repo, node=None, rev=Non
     Returns 0 on success, 1 if nothing to backout or there are unresolved
     files.
     '''
+    wlock = lock = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        return _dobackout(ui, repo, node, rev, commit, **opts)
+    finally:
+        release(lock, wlock)
+
+def _dobackout(ui, repo, node=None, rev=None, commit=False, **opts):
     if rev and node:
         raise error.Abort(_("please specify just one revision"))
 
@@ -542,7 +551,6 @@ def backout(ui, repo, node=None, rev=Non
         parent = p1
 
     # the backout should appear on the same branch
-    wlock = repo.wlock()
     try:
         branch = repo.dirstate.branch()
         bheads = repo.branchheads(branch)
@@ -605,7 +613,9 @@ def backout(ui, repo, node=None, rev=Non
             finally:
                 ui.setconfig('ui', 'forcemerge', '', '')
     finally:
-        wlock.release()
+        # TODO: get rid of this meaningless try/finally enclosing.
+        # this is kept only to reduce changes in a patch.
+        pass
     return 0
 
 @command('bisect',


More information about the Mercurial-devel mailing list