Patchwork [1,of,5] mq: take wlock when 'qqueu' is doing write operations

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 8, 2016, 10:12 p.m.
Message ID <ef6aa171bb9b23b5ab19.1470694356@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16218/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 8, 2016, 10:12 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1470582045 -7200
#      Sun Aug 07 17:00:45 2016 +0200
# Node ID ef6aa171bb9b23b5ab192561073e476cba23b20e
# Parent  3dbc95f3eb31874ab4633f936acff4609714dc41
# EXP-Topic vfs.ward
mq: take wlock when 'qqueu' is doing write operations

Apparently when this commend was added, the locking was forgotten. No code
changes beside the indentation from the locking context.
Yuya Nishihara - Aug. 9, 2016, 3:07 p.m.
On Tue, 09 Aug 2016 00:12:36 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1470582045 -7200
> #      Sun Aug 07 17:00:45 2016 +0200
> # Node ID ef6aa171bb9b23b5ab192561073e476cba23b20e
> # Parent  3dbc95f3eb31874ab4633f936acff4609714dc41
> # EXP-Topic vfs.ward
> mq: take wlock when 'qqueu' is doing write operations

The series looks good to me, queued, thanks.

Patch

diff -r 3dbc95f3eb31 -r ef6aa171bb9b hgext/mq.py
--- a/hgext/mq.py	Fri Aug 05 15:01:16 2016 +0200
+++ b/hgext/mq.py	Sun Aug 07 17:00:45 2016 +0200
@@ -3354,53 +3354,54 @@  def qqueue(ui, repo, name=None, **opts):
         raise error.Abort(
                 _('invalid queue name, may not contain the characters ":\\/."'))
 
-    existing = _getqueues()
-
-    if opts.get('create'):
-        if name in existing:
-            raise error.Abort(_('queue "%s" already exists') % name)
-        if _noqueues():
-            _addqueue(_defaultqueue)
-        _addqueue(name)
-        _setactive(name)
-    elif opts.get('rename'):
-        current = _getcurrent()
-        if name == current:
-            raise error.Abort(_('can\'t rename "%s" to its current name')
-                              % name)
-        if name in existing:
-            raise error.Abort(_('queue "%s" already exists') % name)
-
-        olddir = _queuedir(current)
-        newdir = _queuedir(name)
-
-        if os.path.exists(newdir):
-            raise error.Abort(_('non-queue directory "%s" already exists') %
-                    newdir)
-
-        fh = repo.vfs('patches.queues.new', 'w')
-        for queue in existing:
-            if queue == current:
-                fh.write('%s\n' % (name,))
-                if os.path.exists(olddir):
-                    util.rename(olddir, newdir)
-            else:
-                fh.write('%s\n' % (queue,))
-        fh.close()
-        util.rename(repo.join('patches.queues.new'), repo.join(_allqueues))
-        _setactivenocheck(name)
-    elif opts.get('delete'):
-        _delete(name)
-    elif opts.get('purge'):
-        if name in existing:
+    with repo.wlock():
+        existing = _getqueues()
+
+        if opts.get('create'):
+            if name in existing:
+                raise error.Abort(_('queue "%s" already exists') % name)
+            if _noqueues():
+                _addqueue(_defaultqueue)
+            _addqueue(name)
+            _setactive(name)
+        elif opts.get('rename'):
+            current = _getcurrent()
+            if name == current:
+                raise error.Abort(_('can\'t rename "%s" to its current name')
+                                  % name)
+            if name in existing:
+                raise error.Abort(_('queue "%s" already exists') % name)
+
+            olddir = _queuedir(current)
+            newdir = _queuedir(name)
+
+            if os.path.exists(newdir):
+                raise error.Abort(_('non-queue directory "%s" already exists') %
+                        newdir)
+
+            fh = repo.vfs('patches.queues.new', 'w')
+            for queue in existing:
+                if queue == current:
+                    fh.write('%s\n' % (name,))
+                    if os.path.exists(olddir):
+                        util.rename(olddir, newdir)
+                else:
+                    fh.write('%s\n' % (queue,))
+            fh.close()
+            util.rename(repo.join('patches.queues.new'), repo.join(_allqueues))
+            _setactivenocheck(name)
+        elif opts.get('delete'):
             _delete(name)
-        qdir = _queuedir(name)
-        if os.path.exists(qdir):
-            shutil.rmtree(qdir)
-    else:
-        if name not in existing:
-            raise error.Abort(_('use --create to create a new queue'))
-        _setactive(name)
+        elif opts.get('purge'):
+            if name in existing:
+                _delete(name)
+            qdir = _queuedir(name)
+            if os.path.exists(qdir):
+                shutil.rmtree(qdir)
+        else:
+            if name not in existing:
+                raise error.Abort(_('use --create to create a new queue'))
+            _setactive(name)
 
 def mqphasedefaults(repo, roots):
     """callback used to set mq changeset as secret when no phase data exists"""