--- a/hgext/mq.py Sun Aug 15 16:48:08 2010 +0200
+++ b/hgext/mq.py Sun Aug 15 13:29:46 2010 +0200
@@ -2675,6 +2675,12 @@
fh.write('%s\n' % (name,))
fh.close()
+ def _queuedir(name):
+ if name == 'patches':
+ return repo.join('patches')
+ else:
+ return repo.join('patches-' + name)
+
def _validname(name):
for n in name:
if n in ':\\/.':
@@ -2704,6 +2710,31 @@
_addqueue(_defaultqueue)
_addqueue(name)
_setactive(name)
+ elif opts.get('rename'):
+ current = _getcurrent()
+ if name == current:
+ raise util.Abort(_('can\'t rename "%s" to its current name') % name)
+ if name in existing:
+ raise util.Abort(_('queue "%s" already exists') % name)
+
+ olddir = _queuedir(current)
+ newdir = _queuedir(name)
+
+ if os.path.exists(newdir):
+ raise util.Abort(_('non-queue directory "%s" already exists') %
+ newdir)
+
+ fh = repo.opener('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'):
if name not in existing:
raise util.Abort(_('cannot delete queue that does not exist'))
@@ -3045,6 +3076,7 @@
[
('l', 'list', False, _('list all available queues')),
('c', 'create', False, _('create new queue')),
+ ('', 'rename', False, _('rename active queue')),
('', 'delete', False, _('delete reference to queue')),
],
_('[OPTION] [QUEUE]')),
--- a/tests/test-mq-qqueue Sun Aug 15 16:48:08 2010 +0200
+++ b/tests/test-mq-qqueue Sun Aug 15 13:29:46 2010 +0200
@@ -35,6 +35,25 @@
hg qqueue --create foo
hg qqueue
+echo %% create new queue for rename
+hg qqueue --create bar
+hg qqueue
+
+echo %% rename queue, same name
+hg qqueue --rename bar
+
+echo %% rename queue to existing
+hg qqueue --rename foo
+
+echo %% rename queue
+hg qqueue --rename buz
+hg qqueue
+
+echo %% switch back to previous queue
+hg qqueue foo
+hg qqueue --delete buz
+hg qqueue
+
echo %% unapplied patches
hg qun
echo c > a
--- a/tests/test-mq-qqueue.out Sun Aug 15 16:48:08 2010 +0200
+++ b/tests/test-mq-qqueue.out Sun Aug 15 13:29:46 2010 +0200
@@ -19,6 +19,21 @@
abort: queue "foo" already exists
foo (active)
patches
+%% create new queue for rename
+bar (active)
+foo
+patches
+%% rename queue, same name
+abort: can't rename "bar" to its current name
+%% rename queue to existing
+abort: queue "foo" already exists
+%% rename queue
+buz (active)
+foo
+patches
+%% switch back to previous queue
+foo (active)
+patches
%% unapplied patches
%% fail switching back
abort: patches applied - cannot set new queue active