Patchwork [8,of,9,STABLE] shelve: widen wlock scope of unshelve for consistency while processing

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Dec. 1, 2015, 6:18 p.m.
Message ID <96c4b87476f3a511d060.1448993926@feefifofum>
Download mbox | patch
Permalink /patch/11722/
State Superseded
Commit c9ceea3f2d8e352efe13b1b6e5d98f84bdf19b2f
Headers show

Comments

Katsunori FUJIWARA - Dec. 1, 2015, 6:18 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1448993528 -32400
#      Wed Dec 02 03:12:08 2015 +0900
# Branch stable
# Node ID 96c4b87476f3a511d06006bd70cfefe7fd672ebc
# Parent  f001138597fb71160d2acce9c5838a2f0d03c1e8
shelve: widen wlock scope of unshelve for consistency while processing

Before this patch, "hg unshelve" of shelve extension executes below
before acquisition of wlock:

  - cmdutil.checkunfinished()
  - examine existence of (specified) shelve file

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

This patch widens wlock scope of "hg unshelve" of shelve extension for
consistency while processing.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -615,6 +615,13 @@  def unshelve(ui, repo, *shelved, **opts)
        than ``maxbackups`` backups are kept, if same timestamp
        prevents from deciding exact order of them, for safety.
     """
+    wlock = repo.wlock()
+    try:
+        return _dounshelve(ui, repo, *shelved, **opts)
+    finally:
+        lockmod.release(wlock)
+
+def _dounshelve(ui, repo, *shelved, **opts):
     abortf = opts['abort']
     continuef = opts['continue']
     if not abortf and not continuef:
@@ -653,9 +660,8 @@  def unshelve(ui, repo, *shelved, **opts)
         raise error.Abort(_("shelved change '%s' not found") % basename)
 
     oldquiet = ui.quiet
-    wlock = lock = tr = None
-    try:
-        wlock = repo.wlock()
+    lock = tr = None
+    try:
         lock = repo.lock()
 
         tr = repo.transaction('unshelve', report=lambda x: None)
@@ -749,7 +755,7 @@  def unshelve(ui, repo, *shelved, **opts)
         ui.quiet = oldquiet
         if tr:
             tr.release()
-        lockmod.release(lock, wlock)
+        lockmod.release(lock)
 
 @command('shelve',
          [('A', 'addremove', None,