chiark / gitweb /
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 a4b5a8732d26cb50ab6403db30808c8b386eaf98..836884c434d91bf42846535dd178183988ba0653 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 cfbf0de568755f22ce5072771f2e53ceba8c0726..1b7dce8ad8802ef106c28c6dbfa41a3855eb7b2f 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 3ff6269c7c31ab06346f7be0367cfe83b07001b0..1aa83d0a1298b6e48942dcfa479274a4ad054321 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()