[PATCH] WIP: lookaside clone extension

Augie Fackler raf at durin42.com
Wed Mar 12 22:01:00 CDT 2014


Messed up a for loop in my shell, drop this one for now please.

On Wed, Mar 12, 2014 at 7:58 PM, Augie Fackler <raf at durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <raf at durin42.com>
> # Date 1380062977 14400
> #      Tue Sep 24 18:49:37 2013 -0400
> # Node ID c51e6e04d8c581e6d7109fb3a54a69121c12d7e5
> # Parent  1cd5bff45db28150d7c140be493fe851e6560f27
> WIP: lookaside clone extension
>
> diff --git a/hgext/lookaside.py b/hgext/lookaside.py
> new file mode 100644
> --- /dev/null
> +++ b/hgext/lookaside.py
> @@ -0,0 +1,53 @@
> +"""Hacky proof of concept for lookaside bundle.
> +
> +Right now this doesn't do anything clever about bundle generation or
> +distribution. Put a bundle file (generated with 'hg bundle --all' at a
> +URL that urllib2 can fetch, then put that url in
> +.hg/durin42-lookaside-location.
> +
> +This might mulch your data somehow. It's relatively untested, but it
> +proves the concept.
> +"""
> +
> +import shutil
> +import urllib2
> +
> +from mercurial import changegroup
> +from mercurial import extensions
> +from mercurial import wireproto
> +
> +def addcap(orig, *args, **kwargs):
> +    c = orig(*args, **kwargs)
> +    return c + ' x-durin42-lookaside'
> +
> +extensions.wrapfunction(wireproto, 'capabilities', addcap)
> +wireproto.commands['capabilities'] = wireproto.capabilities, ''
> +
> +def lookaside(repo, proto):
> +    try:
> +        with repo.opener('durin42-lookaside-location') as f:
> +            return f.read().strip()
> +    except IOError:
> +        return ''
> +
> +
> +wireproto.commands['x-durin42-lookaside-clone'] = lookaside, ''
> +
> +def reposetup(ui, repo):
> +    origcls = repo.__class__
> +
> +    class lookasiderepo(origcls):
> +
> +        def clone(self, remote, heads=[], stream=False):
> +            if not heads and remote.capable('x-durin42-lookaside'):
> +                url = remote._call('x-durin42-lookaside-clone')
> +                if url:
> +                    ui.debug('fetching lookaside bundle %s\n' % url)
> +                    # TODO: support resuming the bundle stream if a
> connection fails
> +                    self.addchangegroup(
> +                        changegroup.readbundle(urllib2.urlopen(url),
> 'lookaside bundle'),
> +                        'unbundle', 'bundle:lookaside bundle')
> +                return self.pull(remote, heads)
> +            return origcls.clone(self, remote, heads, stream=False)
> +
> +    repo.__class__ = lookasiderepo
> _______________________________________________
> 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/20140312/37cd9523/attachment.html>


More information about the Mercurial-devel mailing list