[PATCH] Added new send extension

Matt Mackall mpm at selenic.com
Wed Mar 21 19:30:48 CDT 2007


On Wed, Mar 21, 2007 at 06:05:31PM -0500, John Goerzen wrote:
> # HG changeset patch
> # User John Goerzen <jgoerzen at complete.org>
> # Date 1174518209 18000
> # Node ID c79cb4eb468867b70273c33c7b8414eaab43bdd4
> # Parent  fe0fe0b4d73b32f9197f386140f2eb9363a13f7f
> Added new send extension
> 
> diff --git a/hgext/send.py b/hgext/send.py
> new file mode 100644
> --- /dev/null
> +++ b/hgext/send.py
> @@ -0,0 +1,139 @@
> +# Command to send Mercurial changesets as a bundle.
> +#
> +# The subject line defaults to being based off the first patch
> +#
> +# To enable this extension:
> +#
> +#  [extensions]
> +#  hgext.send =
> +#
> +# To configure other defaults, add a section like this to your hgrc
> +# file:
> +#
> +#   [email]
> +#   from = My Name <my at email>
> +#   to = recipient1, recipient2, ...
> +#   cc = cc1, cc2, ...
> +#   bcc = bcc1, bcc2, ...
> +
> +import os, errno, socket, tempfile, os.path
> +import email.MIMEMultipart, email.MIMEText, email.MIMEBase
> +import email.Utils, email.Encoders
> +from mercurial import cmdutil, commands, hg, mail, ui, patch, util
> +from mercurial.node import *
> +
> +try:
> +    # readline gives raw_input editing capabilities, but is not
> +    # present on windows
> +    import readline
> +except ImportError: pass

We're pretty consistent about doing a line break after colons.

> +
> +try:
> +    # Dev branch has internationalization function
> +    from mercurial.i18n import _
> +except ImportError:
> +    def _(val):
> +        return val

We'll want to drop this bit for merge.

> +    def prompt(prompt, default = None, rest = ': ', empty_ok = False):
> +        if default: prompt += ' [%s]' % default
> +        prompt += rest
> +        while True:
> +            r = raw_input(prompt)
> +            if r: return r
> +            if default is not None: return default
> +            if empty_ok: return r
> +            ui.warn(_('Please enter a valid value.\n'))

ui.prompt already does this.

> +    def confirm(s):
> +        if not prompt(s, default = 'y', rest = '? ').lower().startswith('y'):
> +            raise ValueError

And this should be done with ui.prompt.

> +
> +    tmpdir = tempfile.mkdtemp(prefix='hg-send-')
> +    tmpfn = os.path.join(tmpdir, "bundle")

Why not mkstemp? We should probably have a util function to do this
sort of thing consistently.

Ideally we'd use generators to create and stream out the bundle, but
that's obviously harder.

> +        def genmsgid(id):
> +            return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())

This probably wants to be moved to mercurial.email.

> +        try:
> +            os.unlink(tmpfn)
> +        except:
> +            pass
> +        os.rmdir(tmpdir)

This stuff should all be done with try: finally:.

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list