Get the patch name from the description
authorCatalin Marinas <catalin.marinas@gmail.com>
Wed, 5 Jul 2006 18:27:02 +0000 (19:27 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 5 Jul 2006 18:27:02 +0000 (19:27 +0100)
The import and pick commands can get the patch name from the patch
description if it wasn't passed on the command line or the patch is read
from the standard input (for import).

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/commands/common.py
stgit/commands/imprt.py
stgit/commands/pick.py

index a4b5a87..836884c 100644 (file)
@@ -233,3 +233,13 @@ def name_email_date(address):
         raise CmdException, 'Incorrect "name <email> date" string: %s' % address
 
     return str_list[0]
+
+def make_patch_name(msg):
+    """Return a string to be used as a patch name. This is generated
+    from the top line of the string passed as argument.
+    """
+    if not msg:
+        return None
+
+    subject_line = msg.lstrip().split('\n', 1)[0]
+    return re.sub('[\W]+', '-', subject_line).strip('-')
index cfbf0de..1b7dce8 100644 (file)
@@ -234,6 +234,11 @@ def __import_patch(patch, filename, options):
         message, author_name, author_email, author_date = \
                  __parse_patch(filename)
 
+    if not patch:
+        patch = make_patch_name(message)
+        if not patch:
+            raise CmdException, 'Unknown patch name'
+
     # refresh_patch() will invoke the editor in this case, with correct
     # patch content
     if not message:
@@ -323,7 +328,7 @@ def func(parser, options, args):
         elif filename:
             patch = os.path.basename(filename)
         else:
-            raise CmdException, 'Unknown patch name'
+            patch = ''
         if options.strip:
             patch = __strip_patch_name(patch)
 
index 3ff6269..1aa83d0 100644 (file)
@@ -56,6 +56,8 @@ def func(parser, options, args):
     check_head_top_equal()
 
     commit_str = args[0]
+    commit_id = git_id(commit_str)
+    commit = git.Commit(commit_id)
 
     if options.fold or options.update:
         if not crt_series.get_current():
@@ -67,10 +69,9 @@ def func(parser, options, args):
         elif len(patch_branch) == 2:
             patch = patch_branch[0]
         else:
-            raise CmdException, 'Unknown patch name'
-
-    commit_id = git_id(commit_str)
-    commit = git.Commit(commit_id)
+            patch = make_patch_name(commit.get_log())
+            if not patch:
+                raise CmdException, 'Unknown patch name'
 
     if not options.reverse:
         bottom = commit.get_parent()