changeset 1675:03191e1a4230

merge with crew
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 01 Feb 2006 08:50:45 +0100
parents dee55c4a4963 (current diff) bd53710c7780 (diff)
children 0690d0f202e1
files contrib/patchbomb
diffstat 1 files changed, 33 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
rename from contrib/patchbomb
rename to hgext/patchbomb.py
--- a/contrib/patchbomb
+++ b/hgext/patchbomb.py
@@ -1,7 +1,5 @@
-#!/usr/bin/python
-#
-# Interactive script for sending a collection of Mercurial changesets
-# as a series of patch emails.
+# Command for sending a collection of Mercurial changesets as a series
+# of patch emails.
 #
 # The series is started off with a "[PATCH 0 of N]" introduction,
 # which describes the series as a whole.
@@ -50,9 +48,9 @@
 from email.MIMEMultipart import MIMEMultipart
 from email.MIMEText import MIMEText
 from mercurial import commands
-from mercurial import fancyopts
 from mercurial import hg
 from mercurial import ui
+from mercurial.i18n import gettext as _
 import os
 import popen2
 import smtplib
@@ -89,6 +87,17 @@ def diffstat(patch):
         except: pass
 
 def patchbomb(ui, repo, *revs, **opts):
+    '''send changesets as a series of patch emails
+
+    The series starts with a "[PATCH 0 of N]" introduction, which
+    describes the series as a whole.
+
+    Each patch email has a Subject line of "[PATCH M of N] ...", using
+    the first line of the changeset description as the subject text.
+    The message contains two or three body parts.  First, the rest of
+    the changeset description.  Next, (optionally) if the diffstat
+    program is installed, the result of running diffstat on the patch.
+    Finally, the patch itself, as generated by "hg export".'''
     def prompt(prompt, default = None, rest = ': ', empty_ok = False):
         if default: prompt += ' [%s]' % default
         prompt += rest
@@ -97,7 +106,7 @@ def patchbomb(ui, repo, *revs, **opts):
             if r: return r
             if default is not None: return default
             if empty_ok: return r
-            ui.warn('Please enter a valid value.\n')
+            ui.warn(_('Please enter a valid value.\n'))
 
     def confirm(s):
         if not prompt(s, default = 'y', rest = '? ').lower().startswith('y'):
@@ -109,7 +118,7 @@ def patchbomb(ui, repo, *revs, **opts):
             if summary:
                 ui.write(summary, '\n')
                 ui.write(s, '\n')
-            confirm('Does the diffstat above look okay')
+            confirm(_('Does the diffstat above look okay'))
         return s
 
     def makepatch(patch, idx, total):
@@ -162,20 +171,20 @@ def patchbomb(ui, repo, *revs, **opts):
             self.container.append(''.join(self.lines).split('\n'))
             self.lines = []
 
-    commands.export(ui, repo, *args, **{'output': exportee(patches),
+    commands.export(ui, repo, *revs, **{'output': exportee(patches),
                                         'switch_parent': False,
                                         'text': None})
 
     jumbo = []
     msgs = []
 
-    ui.write('This patch series consists of %d patches.\n\n' % len(patches))
+    ui.write(_('This patch series consists of %d patches.\n\n') % len(patches))
 
     for p, i in zip(patches, range(len(patches))):
         jumbo.extend(p)
         msgs.append(makepatch(p, i + 1, len(patches)))
 
-    ui.write('\nWrite the introductory message for the patch series.\n\n')
+    ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
 
     sender = (opts['from'] or ui.config('patchbomb', 'from') or
               prompt('From', ui.username()))
@@ -193,7 +202,7 @@ def patchbomb(ui, repo, *revs, **opts):
     to = getaddrs('to', 'To')
     cc = getaddrs('cc', 'Cc', '')
 
-    ui.write('Finish with ^D or a dot on a line by itself.\n\n')
+    ui.write(_('Finish with ^D or a dot on a line by itself.\n\n'))
 
     body = []
 
@@ -208,7 +217,7 @@ def patchbomb(ui, repo, *revs, **opts):
     ui.write('\n')
 
     if opts['diffstat']:
-        d = cdiffstat('Final summary:\n', jumbo)
+        d = cdiffstat(_('Final summary:\n'), jumbo)
         if d: msg.attach(MIMEText(d))
 
     msgs.insert(0, msg)
@@ -252,25 +261,15 @@ def patchbomb(ui, repo, *revs, **opts):
     if not opts['test']:
         s.close()
 
-if __name__ == '__main__':
-    optspec = [('c', 'cc', [], 'email addresses of copy recipients'),
-               ('d', 'diffstat', None, 'add diffstat output to messages'),
-               ('f', 'from', '', 'email address of sender'),
-               ('', 'plain', None, 'omit hg patch header'),
-               ('n', 'test', None, 'print messages that would be sent'),
-               ('s', 'subject', '', 'subject of introductory message'),
-               ('t', 'to', [], 'email addresses of recipients')]
-    options = {}
-    try:
-        args = fancyopts.fancyopts(sys.argv[1:], commands.globalopts + optspec,
-                                   options)
-    except fancyopts.getopt.GetoptError, inst:
-        u = ui.ui()
-        u.warn('error: %s' % inst)
-        sys.exit(1)
-
-    u = ui.ui(options["verbose"], options["debug"], options["quiet"],
-              not options["noninteractive"])
-    repo = hg.repository(ui = u)
-
-    patchbomb(u, repo, *args, **options)
+cmdtable = {
+    'email':
+    (patchbomb,
+     [('c', 'cc', [], 'email addresses of copy recipients'),
+      ('d', 'diffstat', None, 'add diffstat output to messages'),
+      ('f', 'from', '', 'email address of sender'),
+      ('', 'plain', None, 'omit hg patch header'),
+      ('n', 'test', None, 'print messages that would be sent'),
+      ('s', 'subject', '', 'subject of introductory message'),
+      ('t', 'to', [], 'email addresses of recipients')],
+     "hg email [OPTION]... [REV]...")
+    }