[PATCH] patchbomb: allow multiple addresses in a single --to/cc/bcc argument

Marti Raudsepp marti at juffo.org
Sun Nov 1 00:00:57 CDT 2009


Hi,

Here's a patch to fix up the current patchbomb behavior that doesn't
allow multiple addresses separated by commas on command line.

The current behavior is quite surprising: 'hg email --to foo,bar'
silently discarded 'bar' recipient. You wouldn't realize the mistake
until you actually peek into the headers. The help screen suggests it
accepts "email addresses" as the argument.

So basically, before it did:
  addrs = opts.get(opt)
Now:
  addrs = ','.join(opts.get(opt)).split(',')

Regards,
Marti

# HG changeset patch
# User Marti Raudsepp <marti at juffo.org>
# Date 1257051066 -7200
# Node ID 9352f04a57f553bdd2ed0ae62ce55a0d99919e2e
# Parent  dd5a16ad420e6d5845d45dc7bde717a90900ccc2
patchbomb: allow multiple addresses in a single --to/cc/bcc argument

Previously, 'hg email --to=foo,bar' only respected foo and discarded bar.

Also refactors code so --bcc can be handled in a uniform way.

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -379,20 +379,22 @@
     else:
         msgs = getpatchmsgs(list(getpatches(revs)))
 
-    def getaddrs(opt, prpt, default = None):
-        addrs = opts.get(opt) or (ui.config('email', opt) or
-                                  ui.config('patchbomb', opt) or
-                                  prompt(ui, prpt, default)).split(',')
+    def getaddrs(opt, prpt = None, default = None):
+        # must handle many addresses in a single argument, e.g. --cc a --cc b,c
+        addrs = (','.join(opts.get(opt)) or
+                 ui.config('email', opt) or
+                 ui.config('patchbomb', opt))
+
+        if prpt and not addrs:
+            addrs = prompt(ui, prpt, default)
+
+        addrs = addrs.split(',')
         return [mail.addressencode(ui, a.strip(), _charsets, opts.get('test'))
                 for a in addrs if a.strip()]
 
     to = getaddrs('to', 'To')
     cc = getaddrs('cc', 'Cc', '')
-
-    bcc = opts.get('bcc') or (ui.config('email', 'bcc') or
-                          ui.config('patchbomb', 'bcc') or '').split(',')
-    bcc = [mail.addressencode(ui, a.strip(), _charsets, opts.get('test'))
-           for a in bcc if a.strip()]
+    bcc = getaddrs('bcc')
 
     ui.write('\n')
 
diff --git a/tests/test-patchbomb b/tests/test-patchbomb
--- a/tests/test-patchbomb
+++ b/tests/test-patchbomb
@@ -19,13 +19,13 @@
 echo a > a
 hg commit -Ama -d '1 0'
 
-hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar -r tip | \
+hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar,baz -r tip | \
   fixheaders
 
 echo b > b
 hg commit -Amb -d '2 0'
 
-hg email --date '1970-1-1 0:2' -n -f quux -t foo -c bar -s test -r 0:tip | \
+hg email --date '1970-1-1 0:2' -n -f quux -t foo -c bar -c baz -s test -r 0:tip | \
   fixheaders
 
 hg email -m test.mbox -f quux -t foo -c bar -s test 0:tip
diff --git a/tests/test-patchbomb.out b/tests/test-patchbomb.out
--- a/tests/test-patchbomb.out
+++ b/tests/test-patchbomb.out
@@ -13,7 +13,7 @@
 Date: Thu, 01 Jan 1970 00:01:00 +0000
 From: quux
 To: foo
-Cc: bar
+Cc: bar, baz
 
 # HG changeset patch
 # User test
@@ -45,7 +45,7 @@
 Date: Thu, 01 Jan 1970 00:02:00 +0000
 From: quux
 To: foo
-Cc: bar
+Cc: bar, baz
 
 
 Displaying [PATCH 1 of 2] a ...
@@ -61,7 +61,7 @@
 Date: Thu, 01 Jan 1970 00:02:01 +0000
 From: quux
 To: foo
-Cc: bar
+Cc: bar, baz
 
 # HG changeset patch
 # User test
@@ -89,7 +89,7 @@
 Date: Thu, 01 Jan 1970 00:02:02 +0000
 From: quux
 To: foo
-Cc: bar
+Cc: bar, baz
 
 # HG changeset patch
 # User test




More information about the Mercurial-devel mailing list