mq: use fallback patch name if no alpha-numeric in summary line (issue5025) stable
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 23 Dec 2015 22:28:52 +0900
branchstable
changeset 27513 707cdf2c3700
parent 27441 e47841c8343d
child 27528 7cc654610204
mq: use fallback patch name if no alpha-numeric in summary line (issue5025) Before this patch, "hg qimport -r REV" fails, if the summary line of description of REV doesn't contain any alpha-numeric bytes. In this case, all bytes in the summary line 'title' are dropped from 'namebase' by the code path below. namebase = re.sub('[\s\W_]+', '_', title.lower()).strip('_') 'makepatchname()' immediately returns this empty string as valid patch name, because patch name conflicting against empty string never exists. Then, "hg qimport -r REV" is aborted at creation of patch file with empty filename. This situation isn't so rare. For example, ordinary texts in Japanese often consist of non alpha-numeric bytes in UTF-8. This patch makes 'makepatchname()' use fallback patch name if the summary line of imported revision doesn't contain any alpha-numeric bytes.
hgext/mq.py
tests/test-mq-qimport.t
--- a/hgext/mq.py	Fri Dec 18 20:54:41 2015 -0800
+++ b/hgext/mq.py	Wed Dec 23 22:28:52 2015 +0900
@@ -395,10 +395,12 @@
 class AbortNoCleanup(error.Abort):
     pass
 
-def makepatchname(existing, title):
+def makepatchname(existing, title, fallbackname):
     """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:
+        namebase = fallbackname
     name = namebase
     i = 0
     while name in existing:
@@ -2101,7 +2103,8 @@
 
                     if not patchname:
                         patchname = makepatchname(self.fullseries,
-                            repo[r].description().split('\n', 1)[0])
+                            repo[r].description().split('\n', 1)[0],
+                            '%d.diff' % r)
                     checkseries(patchname)
                     self.checkpatchname(patchname, force)
                     self.fullseries.insert(0, patchname)
--- a/tests/test-mq-qimport.t	Fri Dec 18 20:54:41 2015 -0800
+++ b/tests/test-mq-qimport.t	Wed Dec 23 22:28:52 2015 +0900
@@ -290,3 +290,26 @@
   $ cd ..
 
   $ killdaemons.py
+
+check patch name generation for non-alpha-numeric summary line
+
+  $ cd repo
+
+  $ hg qpop -a -q
+  patch queue now empty
+  $ hg qseries -v
+  0 U imported_patch_b_diff
+  1 U 0
+  2 U this-name-is-better
+  3 U url.diff
+
+  $ echo bb >> b
+  $ hg commit -m '==++--=='
+
+  $ hg qimport -r tip
+  $ hg qseries -v
+  0 A 1.diff
+  1 U imported_patch_b_diff
+  2 U 0
+  3 U this-name-is-better
+  4 U url.diff