[PATCH 1 of 5 V2] shelve: widen wlock scope of unshelve for consistency while processing

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Dec 9 00:21:20 UTC 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1449617333 -32400
#      Wed Dec 09 08:28:53 2015 +0900
# Node ID 140d5ad6d256d355524d532a514a5432d8b29c2a
# Parent  a9f657bc38d3b401f4060ff758aa682371ff53d1
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.

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -616,6 +616,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:
@@ -656,11 +663,10 @@ def unshelve(ui, repo, *shelved, **opts)
         raise error.Abort(_("shelved change '%s' not found") % basename)
 
     oldquiet = ui.quiet
-    wlock = lock = tr = None
+    lock = tr = None
     forcemerge = ui.backupconfig('ui', 'forcemerge')
     try:
         ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve')
-        wlock = repo.wlock()
         lock = repo.lock()
 
         tr = repo.transaction('unshelve', report=lambda x: None)
@@ -755,7 +761,7 @@ def unshelve(ui, repo, *shelved, **opts)
         ui.quiet = oldquiet
         if tr:
             tr.release()
-        lockmod.release(lock, wlock)
+        lockmod.release(lock)
         ui.restoreconfig(forcemerge)
 
 @command('shelve',


More information about the Mercurial-devel mailing list