chiark / gitweb /
Add --sign and --ack options to "stg import"
authorKarl Hasselström <kha@treskal.com>
Tue, 11 Sep 2007 03:57:14 +0000 (05:57 +0200)
committerKarl Hasselström <kha@treskal.com>
Tue, 11 Sep 2007 03:57:14 +0000 (05:57 +0200)
Do this by factoring out the handling of these options from "stg
refresh".

Also, don't add sign lines that are already present.

Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/commands/imprt.py
stgit/commands/refresh.py
stgit/stack.py
stgit/utils.py

index 57bf2c8c87adb1635d83e6c4320e40d3422cdf8b..fad51363f373918032959379e66437201c45cf87 100644 (file)
@@ -87,7 +87,8 @@ options = [make_option('-m', '--mail',
            make_option('--commname',
                        help = 'use COMMNAME as the committer name'),
            make_option('--commemail',
-                       help = 'use COMMEMAIL as the committer e-mail')]
+                       help = 'use COMMEMAIL as the committer e-mail')
+           ] + make_sign_options()
 
 
 def __end_descr(line):
@@ -293,7 +294,8 @@ def __create_patch(filename, message, author_name, author_email,
         else:
             git.apply_patch(diff = diff)
         crt_series.refresh_patch(edit = options.edit,
-                                 show_patch = options.showpatch)
+                                 show_patch = options.showpatch,
+                                 sign_str = options.sign_str)
         out.done()
 
 def __import_file(filename, options, patch = None):
index f44c58ce21972631dc06ed2cc5ab2ecc66ce7534..f70d8082ebc06cfa0f02b3399a0447b7489fdf7e 100644 (file)
@@ -73,14 +73,8 @@ options = [make_option('-f', '--force',
                        help = 'use COMMEMAIL as the committer ' \
                        'e-mail'),
            make_option('-p', '--patch',
-                       help = 'refresh (applied) PATCH instead of the top one'),
-           make_option('--sign',
-                       help = 'add Signed-off-by line',
-                       action = 'store_true'),
-           make_option('--ack',
-                       help = 'add Acked-by line',
-                       action = 'store_true')]
-
+                       help = 'refresh (applied) PATCH instead of the top one')
+           ] + make_sign_options()
 
 def func(parser, options, args):
     autoresolved = config.get('stgit.autoresolved')
@@ -112,15 +106,6 @@ def func(parser, options, args):
     if options.author:
         options.authname, options.authemail = name_email(options.author)
 
-    if options.sign:
-        sign_str = 'Signed-off-by'
-        if options.ack:
-            raise CmdException, '--ack and --sign were both specified'
-    elif options.ack:
-        sign_str = 'Acked-by'
-    else:
-        sign_str = None
-
     files = [path for (stat,path) in git.tree_status(verbose = True)]
     if args:
         files = [f for f in files if f in args]
@@ -128,8 +113,7 @@ def func(parser, options, args):
     if files or not crt_series.head_top_equal() \
            or options.edit or options.message \
            or options.authname or options.authemail or options.authdate \
-           or options.commname or options.commemail \
-           or options.sign or options.ack:
+           or options.commname or options.commemail or options.sign_str:
 
         if options.patch:
             applied = crt_series.get_applied()
@@ -157,7 +141,7 @@ def func(parser, options, args):
                                  author_date = options.authdate,
                                  committer_name = options.commname,
                                  committer_email = options.commemail,
-                                 backup = True, sign_str = sign_str,
+                                 backup = True, sign_str = options.sign_str,
                                  notes = options.annotate)
 
         if crt_series.empty_patch(patch):
index d92d0cfe70c103e6479b792f18d0d028d9d5afff..b19ff4d059c7d373e6478ca338a05ab2747d411f 100644 (file)
@@ -773,14 +773,7 @@ class Series(PatchSet):
         if not committer_email:
             committer_email = patch.get_commemail()
 
-        if sign_str:
-            descr = descr.rstrip()
-            if descr.find("\nSigned-off-by:") < 0 \
-               and descr.find("\nAcked-by:") < 0:
-                descr = descr + "\n"
-
-            descr = '%s\n%s: %s <%s>\n' % (descr, sign_str,
-                                           committer_name, committer_email)
+        descr = add_sign_line(descr, sign_str, committer_name, committer_email)
 
         bottom = patch.get_bottom()
 
index 34c0f96a57babbc825e41781ad698b551c7eea8e..857c0f0986c05c7dc49624087ba579e809091385 100644 (file)
@@ -1,7 +1,7 @@
 """Common utility functions
 """
 
-import errno, os, os.path, re, sys
+import errno, optparse, os, os.path, re, sys
 from stgit.config import config
 from stgit.out import *
 
@@ -229,3 +229,29 @@ if not 'all' in dir(__builtins__):
             if not b:
                 return False
         return True
+
+def make_sign_options():
+    def callback(option, opt_str, value, parser, sign_str):
+        if parser.values.sign_str not in [None, sign_str]:
+            raise optparse.OptionValueError(
+                '--ack and --sign were both specified')
+        parser.values.sign_str = sign_str
+    return [optparse.make_option('--sign', action = 'callback',
+                                 callback = callback, dest = 'sign_str',
+                                 callback_args = ('Signed-off-by',),
+                                 help = 'add Signed-off-by line'),
+            optparse.make_option('--ack', action = 'callback',
+                                 callback = callback, dest = 'sign_str',
+                                 callback_args = ('Acked-by',),
+                                 help = 'add Acked-by line')]
+
+def add_sign_line(desc, sign_str, name, email):
+    if not sign_str:
+        return desc
+    sign_str = '%s: %s <%s>' % (sign_str, name, email)
+    if sign_str in desc:
+        return desc
+    desc = desc.rstrip()
+    if not any(s in desc for s in ['\nSigned-off-by:', '\nAcked-by:']):
+        desc = desc + '\n'
+    return '%s\n%s\n' % (desc, sign_str)