Patchwork [2,of,3] patchbomb: add a 'patchbomb.intro' option

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 3, 2014, 3:12 a.m.
Message ID <d943db1f1f572bf3c01b.1417576325@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6969/
State Accepted
Headers show

Comments

Pierre-Yves David - Dec. 3, 2014, 3:12 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.
Ryan McElroy - Dec. 3, 2014, 5:05 a.m.
Just typos and nits, inline.

> -----Original Message-----

> From: Mercurial-devel [mailto:mercurial-devel-bounces@selenic.com] On

> Behalf Of Pierre-Yves David

> Sent: Tuesday, December 2, 2014 7:12 PM

> To: mercurial-devel@selenic.com

> Cc: Pierre-Yves David

> Subject: [PATCH 2 of 3] patchbomb: add a 'patchbomb.intro' option

> 

> # HG changeset patch

> # User Pierre-Yves David <pierre-yves.david@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.


Whoops, typo: 'patchnbomb' should be 'patchbomb'

> 

> 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

>  '''


Style nit: It feels to me that intro=always should start on its own line

> 

>  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

> +

> _______________________________________________

> Mercurial-devel mailing list

> Mercurial-devel@selenic.com

> http://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Dec. 3, 2014, 11:49 p.m.
On 12/02/2014 09:05 PM, Ryan McElroy wrote:
> Just typos and nits, inline.
>
>> -----Original Message-----
>> From: Mercurial-devel [mailto:mercurial-devel-bounces@selenic.com] On
>> Behalf Of Pierre-Yves David
>> Sent: Tuesday, December 2, 2014 7:12 PM
>> To: mercurial-devel@selenic.com
>> Cc: Pierre-Yves David
>> Subject: [PATCH 2 of 3] patchbomb: add a 'patchbomb.intro' option
>>
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@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.
>
> Whoops, typo: 'patchnbomb' should be 'patchbomb'


Whoops right.

>
>>
>> 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
>>   '''
>
> Style nit: It feels to me that intro=always should start on its own line

It does have it own line. Not sure what your mailer is doing wrong here.

Patch

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
+