chiark / gitweb /
Remove an unnecessary parameter to make_patch_name
authorKarl Hasselström <kha@treskal.com>
Tue, 15 May 2007 17:10:00 +0000 (18:10 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 15 May 2007 21:13:15 +0000 (22:13 +0100)
The "alternative" parameter was a boolean that indicated whether we
were interested in testing if the first generated name was acceptable,
or if we would just always accept it. But that can be accomplished by
giving an "unacceptable" function that always returns False, so
there's no need for an additional parameter.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/imprt.py
stgit/utils.py

index 89af472218a9379426ecb0632a5691e50de656f1..6fcdc62ae8de6f96007a1058e722c04910e3d134 100644 (file)
@@ -242,9 +242,11 @@ def __create_patch(filename, message, author_name, author_email,
         patch = __strip_patch_name(patch)
 
     if not patch:
-        patch = make_patch_name(message, crt_series.patch_exists,
-                                alternative = not (options.ignore
-                                                   or options.replace))
+        if options.ignore or options.replace:
+            unacceptable_name = lambda name: False
+        else:
+            unacceptable_name = crt_series.patch_exists
+        patch = make_patch_name(message, unacceptable_name)
     else:
         # fix possible invalid characters in the patch name
         patch = re.sub('[^\w.]+', '-', patch).strip('-')
index 3612a4bf26fa0b4f92482a7fb6ef4df4f1552c23..fbfe748c42910ed7e951608efb14fb01c7664dd9 100644 (file)
@@ -183,15 +183,14 @@ def patch_name_from_msg(msg):
     subject_line = msg.split('\n', 1)[0].lstrip().lower()
     return re.sub('[\W]+', '-', subject_line).strip('-')[:30]
 
-def make_patch_name(msg, unacceptable, default_name = 'patch',
-                    alternative = True):
+def make_patch_name(msg, unacceptable, default_name = 'patch'):
     """Return a patch name generated from the given commit message,
     guaranteed to make unacceptable(name) be false. If the commit
     message is empty, base the name on default_name instead."""
     patchname = patch_name_from_msg(msg)
     if not patchname:
         patchname = default_name
-    if alternative and unacceptable(patchname):
+    if unacceptable(patchname):
         suffix = 0
         while unacceptable('%s-%d' % (patchname, suffix)):
             suffix += 1