mq: check for reserved patch name with qimport -r (issue5033) stable
authorMads Kiilerich <madski@unity3d.com>
Tue, 19 Jan 2016 06:00:59 +0100
branchstable
changeset 27919 db24d6888896
parent 27918 c7cd551f07d0
child 27920 da5f23362517
mq: check for reserved patch name with qimport -r (issue5033) Fix regression from 143b52fce68e. Catching aborts might not be pretty but it works and is a small change.
hgext/mq.py
tests/test-mq-qimport.t
--- a/hgext/mq.py	Tue Jan 19 06:00:30 2016 +0100
+++ b/hgext/mq.py	Tue Jan 19 06:00:59 2016 +0100
@@ -1117,11 +1117,22 @@
         """Return a suitable filename for title, adding a suffix to make
         it unique in the existing list"""
         namebase = re.sub('[\s\W_]+', '_', title.lower()).strip('_')
-        if not namebase:
+        if namebase:
+            try:
+                self.checkreservedname(namebase)
+            except error.Abort:
+                namebase = fallbackname
+        else:
             namebase = fallbackname
         name = namebase
         i = 0
-        while name in self.fullseries:
+        while True:
+            if name not in self.fullseries:
+                try:
+                    self.checkpatchname(name)
+                    break
+                except error.Abort:
+                    pass
             i += 1
             name = '%s__%s' % (namebase, i)
         return name
--- a/tests/test-mq-qimport.t	Tue Jan 19 06:00:30 2016 +0100
+++ b/tests/test-mq-qimport.t	Tue Jan 19 06:00:59 2016 +0100
@@ -200,9 +200,8 @@
   patch b.diff finalized without changeset message
   $ touch .hg/patches/append_foo
   $ hg qimport -r 'p1(.)::'
-  abort: patch "append_foo" already exists
-  [255]
   $ hg qapplied
+  append_foo__1
   append_bar
   $ hg qfin -a
   $ rm .hg/patches/append_foo
@@ -313,3 +312,22 @@
   2 U 0
   3 U this-name-is-better
   4 U url.diff
+
+check reserved patch names
+
+  $ hg qpop -qa
+  patch queue now empty
+  $ echo >> b
+  $ hg commit -m 'status'
+  $ echo >> b
+  $ hg commit -m '.'
+  $ echo >> b
+  $ hg commit -m 'taken'
+  $ mkdir .hg/patches/taken
+  $ touch .hg/patches/taken__1
+  $ hg qimport -r -3::
+  $ hg qap
+  1.diff__1
+  2.diff
+  taken__2
+