changeset 11270:457813cb3024

mq: fix naming issues for qqueue directories
author Henrik Stuart <hg@hstuart.dk>
date Wed, 02 Jun 2010 19:39:45 +0200
parents 5f01fd602542
children d1aca0863a9d
files hgext/mq.py tests/test-mq-qqueue tests/test-mq-qqueue.out
diffstat 3 files changed, 48 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Wed Jun 02 14:54:25 2010 +0200
+++ b/hgext/mq.py	Wed Jun 02 19:39:45 2010 +0200
@@ -238,8 +238,12 @@
     def __init__(self, ui, path, patchdir=None):
         self.basepath = path
         try:
-            fh = open(os.path.join(path, '.queue'))
-            curpath = os.path.join(path, fh.read().rstrip())
+            fh = open(os.path.join(path, 'patches.queue'))
+            cur = fh.read().rstrip()
+            if not cur:
+                curpath = os.path.join(path, 'patches')
+            else:
+                curpath = os.path.join(path, 'patches-' + cur)
         except IOError:
             curpath = os.path.join(path, 'patches')
         self.path = patchdir or curpath
@@ -2562,11 +2566,14 @@
     q = repo.mq
 
     _defaultqueue = 'patches'
-    _allqueues = '.queues'
-    _activequeue = '.queue'
+    _allqueues = 'patches.queues'
+    _activequeue = 'patches.queue'
 
     def _getcurrent():
-        return os.path.basename(q.path)
+        cur = os.path.basename(q.path)
+        if cur.startswith('patches-'):
+            cur = cur[8:]
+        return cur
 
     def _noqueues():
         try:
@@ -2595,7 +2602,8 @@
             raise util.Abort(_('patches applied - cannot set new queue active'))
 
         fh = repo.opener(_activequeue, 'w')
-        fh.write(name)
+        if name != 'patches':
+            fh.write(name)
         fh.close()
 
     def _addqueue(name):
@@ -2603,6 +2611,12 @@
         fh.write('%s\n' % (name,))
         fh.close()
 
+    def _validname(name):
+        for n in name:
+            if n in ':\\/.':
+                return False
+        return True
+
     if not name or opts.get('list'):
         current = _getcurrent()
         for queue in _getqueues():
@@ -2613,6 +2627,10 @@
                 ui.write('\n')
         return
 
+    if not _validname(name):
+        raise util.Abort(
+                _('invalid queue name, may not contain the characters ":\\/."'))
+
     existing = _getqueues()
 
     if name not in existing and opts.get('delete'):
@@ -2631,13 +2649,13 @@
         if name == current:
             raise util.Abort(_('cannot delete currently active queue'))
 
-        fh = repo.opener('.queues.new', 'w')
+        fh = repo.opener('patches.queues.new', 'w')
         for queue in existing:
             if queue == name:
                 continue
             fh.write('%s\n' % (queue,))
         fh.close()
-        util.rename(repo.join('.queues.new'), repo.join(_allqueues))
+        util.rename(repo.join('patches.queues.new'), repo.join(_allqueues))
     else:
         _setactive(name)
 
--- a/tests/test-mq-qqueue	Wed Jun 02 14:54:25 2010 +0200
+++ b/tests/test-mq-qqueue	Wed Jun 02 19:39:45 2010 +0200
@@ -44,4 +44,17 @@
 hg qqueue patches
 hg qqueue foo --delete
 hg qqueue
+
+echo %% tricky cases
+hg qqueue store --create
+hg qnew test
+hg qqueue
+hg qpop -a
+hg qqueue patches
+hg qun
+
+echo %% invalid names
+hg qqueue test/../../bar --create
+hg qqueue . --create
+
 cd ..
--- a/tests/test-mq-qqueue.out	Wed Jun 02 14:54:25 2010 +0200
+++ b/tests/test-mq-qqueue.out	Wed Jun 02 19:39:45 2010 +0200
@@ -21,3 +21,12 @@
 popping otherstuff
 patch queue now empty
 patches (active)
+%% tricky cases
+patches
+store (active)
+popping test
+patch queue now empty
+somestuff
+%% invalid names
+abort: invalid queue name, may not contain the characters ":\/."
+abort: invalid queue name, may not contain the characters ":\/."