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

[StGIT PATCH 2/5] Generate patch names of more uniform length

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

Cut the generated patch name at 30 characters after getting rid of unwanted characters, not before. This gives patch names of more uniform length, since consecutive unwanted characters were replaced by a single dash.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 stgit/utils.py |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/stgit/utils.py b/stgit/utils.py
index 18198c0..3612a4b 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -175,13 +175,13 @@ def call_editor(filename):
 
 def patch_name_from_msg(msg):
     """Return a string to be used as a patch name. This is generated
-    from the first 30 characters of the top line of the string passed
-    as argument."""
+    from the top line of the string passed as argument, and is at most
+    30 characters long."""
     if not msg:
         return None
 
-    subject_line = msg[:30].lstrip().split('\n', 1)[0].lower()
-    return re.sub('[\W]+', '-', subject_line).strip('-')
+    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):
Previous: Karl HasselströmNext: Karl Hasselström
Message 3 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.