Re: [PATCH 3 of 7 🚿🍦] patchbomb: extract 'getbundle' closure in its own function

Martin von Zweigbergk martinvonz at google.com
Thu Nov 6 11:58:16 CST 2014


On Thu Nov 06 2014 at 7:46:58 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 1415136837 0
> #      Tue Nov 04 21:33:57 2014 +0000
> # Node ID 13f98632a2921017b3e5983a0bec73aeeb79d328
> # Parent  79339dac40621b463dda037eaf889252c2255120
> patchbomb: extract 'getbundle' 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
> @@ -185,10 +185,35 @@ def _getpatches(repo, revs, **opts):
>          output = cStringIO.StringIO()
>          cmdutil.export(repo, [r], fp=output,
>                       opts=patch.diffopts(ui, opts))
>          yield output.getvalue().split('\n')
>
> +def _getbundle(repo, dest, **opts):
> +    """return a bundle containing changesets missing in "dest"
> +
> +    The `opts` keyword-arguments are the same as the one accepted by the
> +    `bundle` command.
> +
> +    The bundle is a returned as a single, in memory, binary blob.
> +    """
> +    ui = repo.ui
>

Only used once, so inline?


> +    tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
> +    tmpfn = os.path.join(tmpdir, 'bundle')
> +    try:
> +        commands.bundle(ui, repo, tmpfn, dest, **opts)
> +        fp = open(tmpfn, 'rb')
> +        data = fp.read()
> +        fp.close()
> +        return data
> +    finally:
> +        try:
> +            os.unlink(tmpfn)
> +        except OSError:
> +            pass
> +        os.rmdir(tmpdir)
> +
> +


Drop duplicate blank line.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20141106/7912a487/attachment.html>


More information about the Mercurial-devel mailing list