[PATCH 4 of 9 STABLE] commands: execute checkunfinished and bailifchanged inside wlock scope

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


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1448993528 -32400
#      Wed Dec 02 03:12:08 2015 +0900
# Branch stable
# Node ID c60cb46202d3d6ff082d21ef295edb975ebdfa33
# Parent  397ed952c13bea2229620bee338962dcf68bf518
commands: execute checkunfinished and bailifchanged inside wlock scope

Before this patch, "hg import" executes below before acquisition of
wlock:

  - cmdutil.checkunfinished()
  - cmdutil.bailifchanged()

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

To avoid this issue, this patch executes 'cmdutil.checkunfinished()'
and 'cmdutil.bailifchanged()' inside wlock scope of "hg import".

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4462,11 +4462,6 @@ def import_(ui, repo, patch1=None, *patc
     if opts.get('exact') and opts.get('prefix'):
         raise error.Abort(_('cannot use --exact with --prefix'))
 
-    if update:
-        cmdutil.checkunfinished(repo)
-    if (opts.get('exact') or not opts.get('force')) and update:
-        cmdutil.bailifchanged(repo)
-
     base = opts["base"]
     wlock = dsguard = lock = tr = None
     msgs = []
@@ -4476,6 +4471,12 @@ def import_(ui, repo, patch1=None, *patc
     try:
         try:
             wlock = repo.wlock()
+
+            if update:
+                cmdutil.checkunfinished(repo)
+            if (opts.get('exact') or not opts.get('force')) and update:
+                cmdutil.bailifchanged(repo)
+
             if not opts.get('no_commit'):
                 lock = repo.lock()
                 tr = repo.transaction('import')


More information about the Mercurial-devel mailing list