mq: refactor makepatchname into class method stable
authorMads Kiilerich <madski@unity3d.com>
Tue, 19 Jan 2016 06:00:30 +0100
branchstable
changeset 27918 c7cd551f07d0
parent 27917 97e0dc6d248c
child 27919 db24d6888896
mq: refactor makepatchname into class method
hgext/mq.py
--- a/hgext/mq.py	Wed Jan 20 13:43:01 2016 -0800
+++ b/hgext/mq.py	Tue Jan 19 06:00:30 2016 +0100
@@ -396,19 +396,6 @@
 class AbortNoCleanup(error.Abort):
     pass
 
-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:
-        i += 1
-        name = '%s__%s' % (namebase, i)
-    return name
-
 class queue(object):
     def __init__(self, ui, baseui, path, patchdir=None):
         self.basepath = path
@@ -1126,6 +1113,19 @@
             else:
                 raise error.Abort(_('patch "%s" already exists') % name)
 
+    def makepatchname(self, 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 self.fullseries:
+            i += 1
+            name = '%s__%s' % (namebase, i)
+        return name
+
     def checkkeepchanges(self, keepchanges, force):
         if force and keepchanges:
             raise error.Abort(_('cannot use both --force and --keep-changes'))
@@ -2097,7 +2097,7 @@
                     lastparent = p1
 
                     if not patchname:
-                        patchname = makepatchname(self.fullseries,
+                        patchname = self.makepatchname(
                             repo[r].description().split('\n', 1)[0],
                             '%d.diff' % r)
                     checkseries(patchname)