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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Dec. 1, 2015, 6:18 p.m.
Message ID <064cd627433570e5efc7.1448993924@feefifofum>
Download mbox | patch
Permalink /patch/11717/
State Accepted
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 064cd627433570e5efc70c9de69d68d278a13bb9
# Parent  e6dc1867c9b7fb47de43087bdaacbcd148430033
shelve: widen wlock scope of shelve for consistency while processing

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

  - 'repo.dirstate.parents()' via 'repo[None].parents()'
  - 'repo._activebookmark'

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

This patch widens wlock scope of "hg shelve" 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
@@ -224,7 +224,13 @@  def _aborttransaction(repo):
 
 def createcmd(ui, repo, pats, opts):
     """subcommand that creates a new shelve"""
-
+    wlock = repo.wlock()
+    try:
+        return _docreatecmd(ui, repo, pats, opts)
+    finally:
+        lockmod.release(wlock)
+
+def _docreatecmd(ui, repo, pats, opts):
     def mutableancestors(ctx):
         """return all mutable ancestors for ctx (included)
 
@@ -285,9 +291,8 @@  def createcmd(ui, repo, pats, opts):
 
     name = opts['name']
 
-    wlock = lock = tr = None
-    try:
-        wlock = repo.wlock()
+    lock = tr = None
+    try:
         lock = repo.lock()
 
         # use an uncommitted transaction to generate the bundle to avoid
@@ -346,7 +351,7 @@  def createcmd(ui, repo, pats, opts):
 
         _aborttransaction(repo)
     finally:
-        lockmod.release(tr, lock, wlock)
+        lockmod.release(tr, lock)
 
 def cleanupcmd(ui, repo):
     """subcommand that deletes all shelves"""