[PATCH] Really fix import --edit invoking editor twice
[stgit] / stgit / commands / imprt.py
index 5e3eddd..e75536b 100644 (file)
@@ -42,6 +42,12 @@ options = [make_option('-m', '--mail',
                        action = 'store_true'),
            make_option('-n', '--name',
                        help = 'use NAME as the patch name'),
+           make_option('-e', '--edit',
+                       help = 'invoke an editor for the patch description',
+                       action = 'store_true'),
+           make_option('-s', '--showpatch',
+                       help = 'show the patch content in the editor buffer',
+                       action = 'store_true'),
            make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
                        help = 'use "NAME <EMAIL>" as the author details'),
            make_option('--authname',
@@ -81,17 +87,16 @@ def __parse_mail(filename = None):
             # end of headers
             break
 
-    # remove extra '[*PATCH]', 'name:' in the subject
+    # remove the '[*PATCH*]' expression in the subject
     if descr:
-        descr = re.findall('^(\[[^\s]*PATCH.*?\])?\s*([^\s]*:)?\s*(.*)$',
-                           descr)[0][2]
+        descr = re.findall('^(\[[^\s]*PATCH.*?\])?\s*(.*)$', descr)[0][1]
         descr += '\n\n'
     else:
         raise CmdException, 'Subject: line not found'
 
     # the rest of the patch description
     for line in f:
-        if re.match('----*\s*$', line) or re.match('diff -', line):
+        if re.match('---\s*$', line) or re.match('diff -', line):
             break
         else:
             descr += line
@@ -120,7 +125,7 @@ def __parse_patch(filename = None):
             auth = re.findall('^.*?:\s+(.*)$', line)[0]
             authname, authemail = name_email(auth)
 
-        if re.match('----*\s*$', line) or re.match('diff -', line):
+        if re.match('---\s*$', line) or re.match('diff -', line):
             break
         else:
             descr += line
@@ -146,10 +151,13 @@ def func(parser, options, args):
 
     if len(args) == 1:
         filename = args[0]
-        patch = os.path.basename(filename)
-    elif options.name:
+    else:
         filename = None
+
+    if options.name:
         patch = options.name
+    elif filename:
+        patch = os.path.basename(filename)
     else:
         raise CmdException, 'Unkown patch name'
 
@@ -167,6 +175,11 @@ def func(parser, options, args):
         message, author_name, author_email, author_date = \
                  __parse_patch(filename)
 
+    # refresh_patch() will invoke the editor in this case, with correct
+    # patch content
+    if not message:
+        can_edit = False
+
     # override the automatically parsed settings
     if options.authname:
         author_name = options.authname
@@ -179,7 +192,7 @@ def func(parser, options, args):
     if options.commemail:
         committer_email = options.commemail
 
-    crt_series.new_patch(patch, message = message,
+    crt_series.new_patch(patch, message = message, can_edit = False,
                          author_name = author_name,
                          author_email = author_email,
                          author_date = author_date,
@@ -190,7 +203,8 @@ def func(parser, options, args):
     sys.stdout.flush()
 
     git.apply_patch(filename)
-    crt_series.refresh_patch()
+    crt_series.refresh_patch(edit = options.edit,
+                             show_patch = options.showpatch)
 
     print 'done'
     print_crt_patch()