[StGit PATCH 3/7] Add --sign and --ack options to "stg import"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>

---

 stgit/commands/imprt.py   |    6 ++++--
 stgit/commands/refresh.py |   24 ++++--------------------
 stgit/stack.py            |    9 +--------
 stgit/utils.py            |   28 +++++++++++++++++++++++++++-
 4 files changed, 36 insertions(+), 31 deletions(-)


diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 57bf2c8..fad5136 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -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):
diff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py
index f44c58c..f70d808 100644
--- a/stgit/commands/refresh.py
+++ b/stgit/commands/refresh.py
@@ -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):
diff --git a/stgit/stack.py b/stgit/stack.py
index d92d0cf..b19ff4d 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -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()
 
diff --git a/stgit/utils.py b/stgit/utils.py
index 34c0f96..857c0f0 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -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)

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux