Make diff flags handling more modular.
[stgit] / stgit / commands / mail.py
index 151a408..7113cff 100644 (file)
@@ -120,6 +120,9 @@ options = [make_option('-a', '--all',
                        help = 'username for SMTP authentication'),
            make_option('-b', '--branch',
                        help = 'use BRANCH instead of the default one'),
+           make_option('--binary',
+                       help = 'output a diff even for binary files',
+                       action = 'store_true'),
            make_option('-m', '--mbox',
                        help = 'generate an mbox file instead of sending',
                        action = 'store_true')]
@@ -223,7 +226,7 @@ def __get_signers_list(msg):
     """
     addr_list = []
 
-    r = re.compile('^(signed-off-by|acked-by):\s+(.+)$', re.I)
+    r = re.compile('^(signed-off-by|acked-by|cc):\s+(.+)$', re.I)
     for line in msg.split('\n'):
         m = r.match(line)
         if m:
@@ -374,6 +377,11 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
     else:
         prefix_str = ''
         
+    if options.binary:
+        diff_flags = [ '--binary' ]
+    else:
+        diff_flags = []
+
     total_nr_str = str(total_nr)
     patch_nr_str = str(patch_nr).zfill(len(total_nr_str))
     if total_nr > 1:
@@ -390,7 +398,8 @@ def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options):
                  # for backward template compatibility
                  'endofheaders': '',
                  'diff':         git.diff(rev1 = git_id('%s//bottom' % patch),
-                                          rev2 = git_id('%s//top' % patch)),
+                                          rev2 = git_id('%s//top' % patch),
+                                          diff_flags = diff_flags ),
                  'diffstat':     git.diffstat(rev1 = git_id('%s//bottom'%patch),
                                               rev2 = git_id('%s//top' % patch)),
                  # for backward template compatibility
@@ -496,13 +505,12 @@ def func(parser, options, args):
             ref_id = msg_id
 
         if options.mbox:
-            print msg_string
+            out.stdout_raw(msg_string + '\n')
         else:
-            print 'Sending the cover message...',
-            sys.stdout.flush()
+            out.start('Sending the cover message')
             __send_message(smtpserver, from_addr, to_addr_list, msg_string,
                            sleep, smtpuser, smtppassword)
-            print 'done'
+            out.done()
 
     # send the patches
     if options.template:
@@ -525,10 +533,9 @@ def func(parser, options, args):
             ref_id = msg_id
 
         if options.mbox:
-            print msg_string
+            out.stdout_raw(msg_string + '\n')
         else:
-            print 'Sending patch "%s"...' % p,
-            sys.stdout.flush()
+            out.start('Sending patch "%s"' % p)
             __send_message(smtpserver, from_addr, to_addr_list, msg_string,
                            sleep, smtpuser, smtppassword)
-            print 'done'
+            out.done()