[PATCH 3 of 3] patchbomb: add --confirm option to show series details and ask for confirmation

Christian Ebert blacktrash at gmx.net
Fri Aug 27 11:01:52 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1282924408 -3600
# Node ID 8c4b8700de000b8a0dca3bc395a467a7fe6f0160
# Parent  9e79771529eb3aaea6f30267fb50a6d73b5309fa
patchbomb: add --confirm option to show series details and ask for confirmation

A simple test is included.
The confirmation check summary looks like this:

  Patchbomb details:
  From: sender
  To: recipient(s)
  Cc: if present or empty
  Bcc: if present or empty
  Reply-To: if present or empty
  Subject: [patch 0 of x [flags]] subject of intro or single patch
  Subject: [patch 1 of x [flags]] subject
  [ ... ]
  are you sure you want to send (yn)?

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -50,6 +50,9 @@
 variable is set, your pager will be fired up once for each patchbomb
 message, so you can verify everything is alright.
 
+With the --confirm option you will be asked for confirmation before
+the messages are sent.
+
 The -m/--mbox option is also very useful. Instead of previewing each
 patchbomb message in a pager or sending the messages directly, it will
 create a UNIX mailbox file with the patch emails. This mailbox file
@@ -399,9 +402,17 @@
     else:
         msgs = getpatchmsgs(list(getpatches(revs)))
 
+    showaddrs = []
+
     def getaddrs(opt, prpt=None, default=None):
         addrs = opts.get(opt.replace('-', '_'))
+        if opt != 'reply-to':
+            showaddr = '%s:' % opt.capitalize()
+        else:
+            showaddr = 'Reply-To:'
+
         if addrs:
+            showaddrs.append('%s %s' % (showaddr, ', '.join(addrs)))
             return mail.addrlistencode(ui, addrs, _charsets,
                                        opts.get('test'))
 
@@ -409,6 +420,10 @@
         if not addrs and prpt:
             addrs = prompt(ui, prpt, default)
 
+        if addrs:
+            showaddr = '%s %s' % (showaddr, addrs)
+        showaddrs.append(showaddr)
+
         return mail.addrlistencode(ui, [addrs], _charsets, opts.get('test'))
 
     to = getaddrs('to', 'To')
@@ -418,6 +433,18 @@
 
     ui.write('\n')
 
+    if opts.get('confirm'):
+        ui.write(_('Patchbomb details:\n'))
+        ui.write('From: %s\n' % sender)
+        for addr in showaddrs:
+            ui.write('%s\n' % addr)
+        for m, subj in msgs:
+            ui.write('Subject: %s\n' % subj)
+        if promptchoice(ui, _('are you sure you want to send (yn)?'),
+                        (_('&Yes'), _('&No'))):
+            raise util.Abort(_('patchbomb canceled'))
+        ui.write('\n')
+
     parent = opts.get('in_reply_to') or None
     # angle brackets may be omitted, they're not semantically part of the msg-id
     if parent is not None:
@@ -499,6 +526,7 @@
           ('i', 'inline', None, _('send patches as inline attachments')),
           ('', 'bcc', [], _('email addresses of blind carbon copy recipients')),
           ('c', 'cc', [], _('email addresses of copy recipients')),
+          ('', 'confirm', None, _('ask for confirmation before sending')),
           ('d', 'diffstat', None, _('add diffstat output to messages')),
           ('', 'date', '', _('use the given date as the sending date')),
           ('', 'desc', '', _('use the given file as the series description')),
diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -46,6 +46,21 @@
   +a
   
 
+  $ hg --config ui.interactive=1 email --confirm -n -f quux -t foo -c bar -r tip<<EOF
+  > n
+  > EOF
+  This patch series consists of 1 patches.
+  
+  
+  Patchbomb details:
+  From: quux
+  To: foo
+  Cc: bar
+  Bcc:
+  Reply-To:
+  Subject: [PATCH] a
+  are you sure you want to send (yn)? abort: patchbomb canceled
+
   $ echo b > b
   $ hg commit -Amb -d '2 0'
   adding b


More information about the Mercurial-devel mailing list