[PATCH 2 of 3] patchbomb: add a 'patchbomb.intro' option
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Tue Dec 2 21:12:05 CST 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1417569892 28800
# Tue Dec 02 17:24:52 2014 -0800
# Node ID d943db1f1f572bf3c01b8ca6b5e728ebc30649aa
# Parent f5b943c897859b30aa362e0a7c61daa14e928a57
patchbomb: add a 'patchbomb.intro' option
This option allows to control the default behavior for including an introduction
message. This would avoid having to tirelessly skip the intro for people
contributing to mercurial.
The three possibles values are:
- always,
- auto (default, current behavior),
- never.
I was thinking of ("true", "false", "") (empty value being auto) but I ruled it
out as too confusing.
This new config option reuse the pre-existing 'patchnbomb' section.
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -41,10 +41,19 @@ changesets as a patchbomb.
You can also either configure the method option in the email section
to be a sendmail compatible mailer or fill out the [smtp] section so
that the patchbomb extension can automatically send patchbombs
directly from the commandline. See the [email] and [smtp] sections in
hgrc(5) for details.
+
+You can control the default inclusion of an introduction message with the
+``patchbomb.intro`` configuration option. The configuration is always
+overwritten by command line flags like --intro and --desc::
+
+ [patchbomb]
+ intro=auto # include introduction message if more than 1 patch (default)
+ intro=never # never included an introduction message
+ intro=always # always include an introduction message
'''
import os, errno, socket, tempfile, cStringIO
import email
# On python2.4 you have to import these by name or they fail to
@@ -64,13 +73,27 @@ testedwith = 'internal'
def prompt(ui, prompt, default=None, rest=':'):
if default:
prompt += ' [%s]' % default
return ui.prompt(prompt + rest, default)
-def introwanted(opts, number):
+def introwanted(ui, opts, number):
'''is an introductory message apparently wanted?'''
- return number > 1 or opts.get('intro') or opts.get('desc')
+ introconfig = ui.config('patchbomb', 'intro', 'auto')
+ if opts.get('intro') or opts.get('desc'):
+ intro = True
+ elif introconfig == 'always':
+ intro = True
+ elif introconfig == 'never':
+ intro = False
+ elif introconfig == 'auto':
+ intro = 1 < number
+ else:
+ ui.write_err(_('warning: invalid patchbomb.intro value "%s"\n')
+ % introconfig)
+ ui.write_err(_('(should be one of always, never, auto)\n'))
+ intro = 1 < number
+ return intro
def makepatch(ui, repo, patchlines, opts, _charsets, idx, total, numbered,
patchname=None):
desc = []
@@ -285,11 +308,11 @@ def _getpatchmsgs(repo, sender, patches,
ui.write(_('this patch series consists of %d patches.\n\n')
% len(patches))
# build the intro message, or skip it if the user declines
- if introwanted(opts, len(patches)):
+ if introwanted(ui, opts, len(patches)):
msg = _makeintro(repo, sender, patches, **opts)
if msg:
msgs.append(msg)
# are we going to send more than one message?
@@ -405,11 +428,13 @@ def patchbomb(ui, repo, *revs, **opts):
Then when all is done, patchbomb messages are displayed. If the
PAGER environment variable is set, your pager will be fired up once
for each patchbomb message, so you can verify everything is alright.
In case email sending fails, you will find a backup of your series
- introductory message in ``.hg/last-email.txt``.
+ introductory message in ``.hg/last-email.txt``. The inclusion the
+ introduction can also be control using the ``patchbomb.intro`` option. (see
+ hg help patchbomb for details)
Examples::
hg email -r 3000 # send patch 3000 only
hg email -r 3000 -r 3001 # send patches 3000 and 3001
diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -2661,6 +2661,129 @@ dest#branch URIs:
+++ b/d Thu Jan 01 00:00:04 1970 +0000
@@ -0,0 +1,1 @@
+d
- $ cd ..
+Test introduction configuration
+=================================
+
+ $ echo '[patchbomb]' >> $HGRCPATH
+
+"auto" setting
+----------------
+
+ $ echo 'intro=auto' >> $HGRCPATH
+
+single rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' | grep "Write the introductory message for the patch series."
+ [1]
+
+single rev + flag
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' --intro | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+
+Multi rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '9::' | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+"never" setting
+-----------------
+
+ $ echo 'intro=never' >> $HGRCPATH
+
+single rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' | grep "Write the introductory message for the patch series."
+ [1]
+
+single rev + flag
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' --intro | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+
+Multi rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '9::' | grep "Write the introductory message for the patch series."
+ [1]
+
+Multi rev + flag
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '9::' --intro | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+"always" setting
+-----------------
+
+ $ echo 'intro=always' >> $HGRCPATH
+
+single rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+single rev + flag
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10' --intro | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+
+Multi rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '9::' | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+Multi rev + flag
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '9::' --intro | grep "Write the introductory message for the patch series."
+ Write the introductory message for the patch series.
+
+bad value setting
+-----------------
+
+ $ echo 'intro=mpmwearaclownnose' >> $HGRCPATH
+
+single rev
+
+ $ hg email --date '1980-1-1 0:1' -n -t foo -s test -r '10'
+ From [test]: test
+ this patch series consists of 1 patches.
+
+ warning: invalid patchbomb.intro value "mpmwearaclownnose"
+ (should be one of always, never, auto)
+ Cc:
+
+ displaying [PATCH] test ...
+ Content-Type: text/plain; charset="us-ascii"
+ MIME-Version: 1.0
+ Content-Transfer-Encoding: 7bit
+ Subject: [PATCH] test
+ X-Mercurial-Node: 3b6f1ec9dde933a40a115a7990f8b320477231af
+ X-Mercurial-Series-Index: 1
+ X-Mercurial-Series-Total: 1
+ Message-Id: <3b6f1ec9dde933a40a11*> (glob)
+ X-Mercurial-Series-Id: <3b6f1ec9dde933a40a11.*> (glob)
+ User-Agent: Mercurial-patchbomb/* (glob)
+ Date: Tue, 01 Jan 1980 00:01:00 +0000
+ From: test
+ To: foo
+
+ # HG changeset patch
+ # User test
+ # Date 5 0
+ # Thu Jan 01 00:00:05 1970 +0000
+ # Branch test
+ # Node ID 3b6f1ec9dde933a40a115a7990f8b320477231af
+ # Parent 2f9fa9b998c5fe3ac2bd9a2b14bfcbeecbc7c268
+ dd
+
+ diff -r 2f9fa9b998c5 -r 3b6f1ec9dde9 d
+ --- a/d Thu Jan 01 00:00:04 1970 +0000
+ +++ b/d Thu Jan 01 00:00:05 1970 +0000
+ @@ -1,1 +1,2 @@
+ d
+ +d
+
More information about the Mercurial-devel
mailing list