git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGIT PATCH 3/5] Remove an unnecessary parameter to make_patch_name

From
Karl Hasselström <kha@treskal.com>
Date
May 11, 2007, 01:40 UTC
Message-ID
<20070511014016.13161.33634.stgit@yoghurt>
In-Reply-To
<20070511013400.13161.9160.stgit@yoghurt>
From: Karl Hasselström <kha@treskal.com>

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 |    8 +++++---
 stgit/utils.py          |    5 ++---
 2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 89af472..6fcdc62 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -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('-')
diff --git a/stgit/utils.py b/stgit/utils.py
index 3612a4b..fbfe748 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -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
Previous: Karl HasselströmNext: Karl Hasselström
Message 4 of 6 in “Some tweaks and enhancements”
  1. 0/5 Some tweaks and enhancementsKarl Hasselström, May 11, 2007
  2. 1/5 Make the "name" argument to "stg new" optionalKarl Hasselström, May 11, 2007
  3. 2/5 Generate patch names of more uniform lengthKarl Hasselström, May 11, 2007
  4. 3/5 Remove an unnecessary parameter to make_patch_nameKarl Hasselström, May 11, 2007
  5. 4/5 If any uncommit would fail, don't uncommit anythingKarl Hasselström, May 11, 2007
  6. 5/5 Uncommit to a named commitKarl Hasselström, May 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.