{"thread":{"id":"43408","subject":"[PATCH 0/2] Generate saner automatic patch names","startedAt":"2006-11-07T06:57:10Z","lastAt":"2006-11-07T06:59:31Z","messageCount":3,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"294647","messageId":"20061107065710.10728.85618.stgit@localhost","threadId":"43408","inReplyTo":null,"subject":"[PATCH 0/2] Generate saner automatic patch names","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2006-11-07T06:57:10Z","receivedAt":"2006-11-07T06:57:10Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"This series fixes some quirks in the automatic patch name generation.\nIn particular, it limits the length of names, and makes sure that all\ncallers generate unique names so that name clashes won't be a problem.\n\n-- \nKarl Hasselström, kha@treskal.com\n"},{"id":"297314","messageId":"20061107065925.10728.85759.stgit@localhost","threadId":"43408","inReplyTo":"20061107065710.10728.85618.stgit@localhost","subject":"[PATCH 1/2] Generate shorter patch names","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2006-11-07T06:59:26Z","receivedAt":"2006-11-07T06:59:26Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"From: Karl Hasselström <kha@treskal.com>\n\nNot all commits are blessed with a really short first-line summary in\ntheir commit messages. This means that we shouldn't blindly take the\nentire first line of the comment, since that sometimes results in\ntruly spectacular patch names.\n\nI chose 30 characters as a reasonable value, considering that we don't\nyet have any tab-completion on patch names. There's probably not much\npoint in making it configurable.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n---\n\n stgit/commands/common.py |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/common.py b/stgit/commands/common.py\nindex 88b1b94..0e1bb44 100644\n--- a/stgit/commands/common.py\n+++ b/stgit/commands/common.py\n@@ -286,10 +286,10 @@ def name_email_date(address):\n \n def make_patch_name(msg):\n     \"\"\"Return a string to be used as a patch name. This is generated\n-    from the top line of the string passed as argument.\n-    \"\"\"\n+    from the first 30 characters of the top line of the string passed\n+    as argument.\"\"\"\n     if not msg:\n         return None\n \n-    subject_line = msg.lstrip().split('\\n', 1)[0].lower()\n+    subject_line = msg[:30].lstrip().split('\\n', 1)[0].lower()\n"},{"id":"297531","messageId":"20061107065931.10728.66377.stgit@localhost","threadId":"43408","inReplyTo":"20061107065710.10728.85618.stgit@localhost","subject":"[PATCH 2/2] Generate unique patch names","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2006-11-07T06:59:31Z","receivedAt":"2006-11-07T06:59:31Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"From: Karl Hasselström <kha@treskal.com>\n\n\"stg assimilate\" was already making sure that automatically generated\npatch names were non-empty and unique, by suffixing them with a dash\nand a number if necessary. This patch moves that functionality into\nthe autogeneration function itself, so that all its callers can\nbenefit from it (and the user can benefit from uniform behavior from\nall stgit commands).\n\nAs an added bonus, this permits the removal of a number of checks that\nwould abort with an error if the automatically generated name was\nempty.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n---\n\n stgit/commands/assimilate.py |    9 +--------\n stgit/commands/common.py     |   16 +++++++++++++++-\n stgit/commands/imprt.py      |    4 +---\n stgit/commands/pick.py       |    4 +---\n stgit/commands/uncommit.py   |    5 ++---\n 5 files changed, 20 insertions(+), 18 deletions(-)\n\ndiff --git a/stgit/commands/assimilate.py b/stgit/commands/assimilate.py\nindex 0821024..a8b3bfe 100644\n--- a/stgit/commands/assimilate.py\n+++ b/stgit/commands/assimilate.py\n@@ -73,14 +73,7 @@ def func(parser, options, args):\n         return name in name2patch or crt_series.patch_exists(name)\n \n     for victim in victims:\n-        patchname = make_patch_name(victim.get_log())\n-        if not patchname:\n-            patchname = 'patch'\n-        if name_taken(patchname):\n-            suffix = 0\n-            while name_taken('%s-%d' % (patchname, suffix)):\n-                suffix += 1\n-            patchname = '%s-%d' % (patchname, suffix)\n+        patchname = make_patch_name(victim.get_log(), name_taken)\n         patch2name[victim] = patchname\n         name2patch[patchname] = victim\n \ndiff --git a/stgit/commands/common.py b/stgit/commands/common.py\nindex 0e1bb44..d986711 100644\n--- a/stgit/commands/common.py\n+++ b/stgit/commands/common.py\n@@ -284,7 +284,7 @@ def name_email_date(address):\n \n     return str_list[0]\n \n-def make_patch_name(msg):\n+def patch_name_from_msg(msg):\n     \"\"\"Return a string to be used as a patch name. This is generated\n     from the first 30 characters of the top line of the string passed\n     as argument.\"\"\"\n@@ -293,3 +293,17 @@ def make_patch_name(msg):\n \n     subject_line = msg[:30].lstrip().split('\\n', 1)[0].lower()\n     return re.sub('[\\W]+', '-', subject_line).strip('-')\n+\n+def make_patch_name(msg, unacceptable, default_name = 'patch'):\n+    \"\"\"Return a patch name generated from the given commit message,\n+    guaranteed to make unacceptable(name) be false. If the commit\n+    message is empty, base the name on default_name instead.\"\"\"\n+    patchname = patch_name_from_msg(msg)\n+    if not patchname:\n+        patchname = 'patch'\n+    if unacceptable(patchname):\n+        suffix = 0\n+        while unacceptable('%s-%d' % (patchname, suffix)):\n+            suffix += 1\n+        patchname = '%s-%d' % (patchname, suffix)\n+    return patchname\ndiff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py\nindex c8cf42b..34cbf38 100644\n--- a/stgit/commands/imprt.py\n+++ b/stgit/commands/imprt.py\n@@ -240,9 +240,7 @@ def __import_patch(patch, filename, opti\n                  __parse_patch(filename)\n \n     if not patch:\n-        patch = make_patch_name(message)\n-        if not patch:\n-            raise CmdException, 'Unknown patch name'\n+        patch = make_patch_name(message, crt_series.patch_exists)\n \n     # refresh_patch() will invoke the editor in this case, with correct\n     # patch content\ndiff --git a/stgit/commands/pick.py b/stgit/commands/pick.py\nindex f8f3577..996e789 100644\n--- a/stgit/commands/pick.py\n+++ b/stgit/commands/pick.py\n@@ -71,9 +71,7 @@ def func(parser, options, args):\n         elif len(patch_branch) == 2:\n             patch = patch_branch[0]\n         else:\n-            patch = make_patch_name(commit.get_log())\n-            if not patch:\n-                raise CmdException, 'Unknown patch name'\n+            patch = make_patch_name(commit.get_log(), crt_series.patch_exists)\n \n     if options.parent:\n         parent = git_id(options.parent)\ndiff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py\nindex 45a2087..9798f19 100644\n--- a/stgit/commands/uncommit.py\n+++ b/stgit/commands/uncommit.py\n@@ -97,9 +97,8 @@ def func(parser, options, args):\n         if patchnames:\n             patchname = patchnames[n]\n         else:\n-            patchname = make_patch_name(commit.get_log())\n-        if not patchname:\n-            raise CmdException, 'Unknown patch name for commit %s' % commit_id\n+            patchname = make_patch_name(commit.get_log(),\n+                                        crt_series.patch_exists)\n \n         crt_series.new_patch(patchname,\n                              can_edit = False, before_existing = T"}]}