Re: [PATCH 7 of 7 🚿🍦] patchbomb: extract 'getpatchmsgs' closure in its own function
Martin von Zweigbergk
martinvonz at google.com
Thu Nov 6 12:08:34 CST 2014
On Thu Nov 06 2014 at 7:47:13 AM Pierre-Yves David <
pierre-yves.david at ens-lyon.org> wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1415274937 0
> # Thu Nov 06 11:55:37 2014 +0000
> # Node ID 3947124af76ea099c53aff2dbb61ffd1400d61d6
> # Parent 1c2a64da69f91d37af44d0126ea2c3d73b3a8790
> patchbomb: extract 'getpatchmsgs' closure in its own function
>
> Keep marching toward the promised land of simplification!
>
> diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
> --- a/hgext/patchbomb.py
> +++ b/hgext/patchbomb.py
> @@ -289,10 +289,44 @@ def _makeintro(repo, sender, patches, **
> msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
> msg['Subject'] = mail.headencode(ui, subj, _charsets,
> opts.get('test'))
> return (msg, subj, diffstat)
>
> +def _getpatchmsgs(repo, sender, patches, patchnames=None, **opts):
> + """return a list of emails from a list of patches
> +
> + This involve introduction message creation if necessary.
> +
> + This function return a list of "email" tuple (subject, content, None).
>
The diffstat doesn't seem to be None in this function.
> + """
> + ui = repo.ui
> + _charsets = mail._charsets(ui)
> + msgs = []
> +
> + 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)):
> + msg = _makeintro(repo, sender, patches, **opts)
> + if msg:
> + msgs.append(msg)
> +
> + # are we going to send more than one message?
> + numbered = len(msgs) + len(patches) > 1
> +
> + # now generate the actual patch messages
> + name = None
> + for i, p in enumerate(patches):
> + if patchnames:
> + name = patchnames[i]
> + msg = makepatch(ui, repo, p, opts, _charsets, i + 1,
> + len(patches), numbered, name)
> + msgs.append(msg)
> +
> + return msgs
> +
> emailopts = [
> ('', 'body', None, _('send patches as inline message text
> (default)')),
> ('a', 'attach', None, _('send patches as attachments')),
> ('i', 'inline', None, _('send patches as inline attachments')),
> ('', 'bcc', [], _('email addresses of blind carbon copy recipients')),
> @@ -449,50 +483,25 @@ def patchbomb(ui, repo, *revs, **opts):
> start_time = util.makedate()
>
> def genmsgid(id):
> return '<%s.%s@%s>' % (id[:20], int(start_time[0]),
> socket.getfqdn())
>
> - def getpatchmsgs(patches, patchnames=None):
> - msgs = []
> -
> - 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)):
> - msg = _makeintro(repo, sender, patches, **opts)
> - if msg:
> - msgs.append(msg)
> -
> - # are we going to send more than one message?
> - numbered = len(msgs) + len(patches) > 1
> -
> - # now generate the actual patch messages
> - name = None
> - for i, p in enumerate(patches):
> - if patchnames:
> - name = patchnames[i]
> - msg = makepatch(ui, repo, p, opts, _charsets, i + 1,
> - len(patches), numbered, name)
> - msgs.append(msg)
> -
> - return msgs
> -
> -
> sender = (opts.get('from') or ui.config('email', 'from') or
> ui.config('patchbomb', 'from') or
> prompt(ui, 'From', ui.username()))
>
> if patches:
> - msgs = getpatchmsgs(patches, opts.get('patchnames'))
> + msgs = _getpatchmsgs(repo, sender, patches,
> opts.get('patchnames'),
> + **opts)
> elif bundle:
> bundledata = _getbundle(repo, dest, **opts)
> bundleopts = opts.copy()
> bundleopts.pop('bundle', None) # already processed
> msgs = _getbundlemsgs(repo, sender, bundledata, **bundleopts)
> else:
> - msgs = getpatchmsgs(list(_getpatches(repo, revs, **opts)))
> + _patches = list(_getpatches(repo, revs, **opts))
> + msgs = _getpatchmsgs(repo, sender, _patches, **opts)
>
> showaddrs = []
>
> def getaddrs(header, ask=False, default=None):
> configkey = header.lower()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20141106/60ac62dc/attachment.html>
More information about the Mercurial-devel
mailing list