hgext/patchbomb.py
changeset 9071 141e3ef20d84
parent 9047 8263d98ffb1c
child 9214 b1b0c845ba6e
equal deleted inserted replaced
9070:1933220e0284 9071:141e3ef20d84
     8 '''command to send changesets as (a series of) patch emails
     8 '''command to send changesets as (a series of) patch emails
     9 
     9 
    10 The series is started off with a "[PATCH 0 of N]" introduction, which
    10 The series is started off with a "[PATCH 0 of N]" introduction, which
    11 describes the series as a whole.
    11 describes the series as a whole.
    12 
    12 
    13 Each patch email has a Subject line of "[PATCH M of N] ...", using the
    13 Each patch email has a Subject line of "[PATCH M of N] ...", using the first
    14 first line of the changeset description as the subject text. The
    14 line of the changeset description as the subject text. The message contains
    15 message contains two or three body parts:
    15 two or three body parts:
    16 
    16 
    17   The changeset description.
    17   The changeset description.
    18 
    18 
    19   [Optional] The result of running diffstat on the patch.
    19   [Optional] The result of running diffstat on the patch.
    20 
    20 
    21   The patch itself, as generated by "hg export".
    21   The patch itself, as generated by "hg export".
    22 
    22 
    23 Each message refers to the first in the series using the In-Reply-To
    23 Each message refers to the first in the series using the In-Reply-To and
    24 and References headers, so they will show up as a sequence in threaded
    24 References headers, so they will show up as a sequence in threaded mail and
    25 mail and news readers, and in mail archives.
    25 news readers, and in mail archives.
    26 
    26 
    27 With the -d/--diffstat option, you will be prompted for each changeset
    27 With the -d/--diffstat option, you will be prompted for each changeset with a
    28 with a diffstat summary and the changeset summary, so you can be sure
    28 diffstat summary and the changeset summary, so you can be sure you are sending
    29 you are sending the right changes.
    29 the right changes.
    30 
    30 
    31 To configure other defaults, add a section like this to your hgrc
    31 To configure other defaults, add a section like this to your hgrc file:
    32 file:
       
    33 
    32 
    34   [email]
    33   [email]
    35   from = My Name <my@email>
    34   from = My Name <my@email>
    36   to = recipient1, recipient2, ...
    35   to = recipient1, recipient2, ...
    37   cc = cc1, cc2, ...
    36   cc = cc1, cc2, ...
    38   bcc = bcc1, bcc2, ...
    37   bcc = bcc1, bcc2, ...
    39 
    38 
    40 Then you can use the "hg email" command to mail a series of changesets
    39 Then you can use the "hg email" command to mail a series of changesets as a
    41 as a patchbomb.
    40 patchbomb.
    42 
    41 
    43 To avoid sending patches prematurely, it is a good idea to first run
    42 To avoid sending patches prematurely, it is a good idea to first run the
    44 the "email" command with the "-n" option (test only). You will be
    43 "email" command with the "-n" option (test only). You will be prompted for an
    45 prompted for an email recipient address, a subject and an introductory
    44 email recipient address, a subject and an introductory message describing the
    46 message describing the patches of your patchbomb. Then when all is
    45 patches of your patchbomb. Then when all is done, patchbomb messages are
    47 done, patchbomb messages are displayed. If the PAGER environment
    46 displayed. If the PAGER environment variable is set, your pager will be fired
    48 variable is set, your pager will be fired up once for each patchbomb
    47 up once for each patchbomb message, so you can verify everything is alright.
    49 message, so you can verify everything is alright.
    48 
    50 
    49 The -m/--mbox option is also very useful. Instead of previewing each patchbomb
    51 The -m/--mbox option is also very useful. Instead of previewing each
    50 message in a pager or sending the messages directly, it will create a UNIX
    52 patchbomb message in a pager or sending the messages directly, it will
    51 mailbox file with the patch emails. This mailbox file can be previewed with
    53 create a UNIX mailbox file with the patch emails. This mailbox file
    52 any mail user agent which supports UNIX mbox files, e.g. with mutt:
    54 can be previewed with any mail user agent which supports UNIX mbox
       
    55 files, e.g. with mutt:
       
    56 
    53 
    57   % mutt -R -f mbox
    54   % mutt -R -f mbox
    58 
    55 
    59 When you are previewing the patchbomb messages, you can use `formail'
    56 When you are previewing the patchbomb messages, you can use `formail' (a
    60 (a utility that is commonly installed as part of the procmail
    57 utility that is commonly installed as part of the procmail package), to send
    61 package), to send each message out:
    58 each message out:
    62 
    59 
    63   % formail -s sendmail -bm -t < mbox
    60   % formail -s sendmail -bm -t < mbox
    64 
    61 
    65 That should be all. Now your patchbomb is on its way out.
    62 That should be all. Now your patchbomb is on its way out.
    66 
    63 
    67 You can also either configure the method option in the email section
    64 You can also either configure the method option in the email section to be a
    68 to be a sendmail compatible mailer or fill out the [smtp] section so
    65 sendmail compatible mailer or fill out the [smtp] section so that the
    69 that the patchbomb extension can automatically send patchbombs
    66 patchbomb extension can automatically send patchbombs directly from the
    70 directly from the commandline. See the [email] and [smtp] sections in
    67 commandline. See the [email] and [smtp] sections in hgrc(5) for details.
    71 hgrc(5) for details.'''
    68 '''
    72 
    69 
    73 import os, errno, socket, tempfile, cStringIO, time
    70 import os, errno, socket, tempfile, cStringIO, time
    74 import email.MIMEMultipart, email.MIMEBase
    71 import email.MIMEMultipart, email.MIMEBase
    75 import email.Utils, email.Encoders, email.Generator
    72 import email.Utils, email.Encoders, email.Generator
    76 from mercurial import cmdutil, commands, hg, mail, patch, util
    73 from mercurial import cmdutil, commands, hg, mail, patch, util
   174     return msg, subj
   171     return msg, subj
   175 
   172 
   176 def patchbomb(ui, repo, *revs, **opts):
   173 def patchbomb(ui, repo, *revs, **opts):
   177     '''send changesets by email
   174     '''send changesets by email
   178 
   175 
   179     By default, diffs are sent in the format generated by hg export,
   176     By default, diffs are sent in the format generated by hg export, one per
   180     one per message. The series starts with a "[PATCH 0 of N]"
   177     message. The series starts with a "[PATCH 0 of N]" introduction, which
   181     introduction, which describes the series as a whole.
   178     describes the series as a whole.
   182 
   179 
   183     Each patch email has a Subject line of "[PATCH M of N] ...", using
   180     Each patch email has a Subject line of "[PATCH M of N] ...", using the
   184     the first line of the changeset description as the subject text.
   181     first line of the changeset description as the subject text. The message
   185     The message contains two or three parts. First, the changeset
   182     contains two or three parts. First, the changeset description. Next,
   186     description. Next, (optionally) if the diffstat program is
   183     (optionally) if the diffstat program is installed and -d/--diffstat is
   187     installed and -d/--diffstat is used, the result of running
   184     used, the result of running diffstat on the patch. Finally, the patch
   188     diffstat on the patch. Finally, the patch itself, as generated by
   185     itself, as generated by "hg export".
   189     "hg export".
   186 
   190 
   187     By default the patch is included as text in the email body for easy
   191     By default the patch is included as text in the email body for
   188     reviewing. Using the -a/--attach option will instead create an attachment
   192     easy reviewing. Using the -a/--attach option will instead create
   189     for the patch. With -i/--inline an inline attachment will be created.
   193     an attachment for the patch. With -i/--inline an inline attachment
   190 
   194     will be created.
   191     With -o/--outgoing, emails will be generated for patches not found in the
   195 
   192     destination repository (or only those which are ancestors of the specified
   196     With -o/--outgoing, emails will be generated for patches not found
   193     revisions if any are provided)
   197     in the destination repository (or only those which are ancestors
   194 
   198     of the specified revisions if any are provided)
   195     With -b/--bundle, changesets are selected as for --outgoing, but a single
   199 
   196     email containing a binary Mercurial bundle as an attachment will be sent.
   200     With -b/--bundle, changesets are selected as for --outgoing, but a
       
   201     single email containing a binary Mercurial bundle as an attachment
       
   202     will be sent.
       
   203 
   197 
   204     Examples:
   198     Examples:
   205 
   199 
   206     hg email -r 3000          # send patch 3000 only
   200     hg email -r 3000          # send patch 3000 only
   207     hg email -r 3000 -r 3001  # send patches 3000 and 3001
   201     hg email -r 3000 -r 3001  # send patches 3000 and 3001
   216     hg email -b               # send bundle of all patches not in default
   210     hg email -b               # send bundle of all patches not in default
   217     hg email -b DEST          # send bundle of all patches not in DEST
   211     hg email -b DEST          # send bundle of all patches not in DEST
   218     hg email -b -r 3000       # bundle of all ancestors of 3000 not in default
   212     hg email -b -r 3000       # bundle of all ancestors of 3000 not in default
   219     hg email -b -r 3000 DEST  # bundle of all ancestors of 3000 not in DEST
   213     hg email -b -r 3000 DEST  # bundle of all ancestors of 3000 not in DEST
   220 
   214 
   221     Before using this command, you will need to enable email in your
   215     Before using this command, you will need to enable email in your hgrc. See
   222     hgrc. See the [email] section in hgrc(5) for details.
   216     the [email] section in hgrc(5) for details.
   223     '''
   217     '''
   224 
   218 
   225     _charsets = mail._charsets(ui)
   219     _charsets = mail._charsets(ui)
   226 
   220 
   227     def outgoing(dest, revs):
   221     def outgoing(dest, revs):