[PATCH] hg: support for auto sharing stores when cloning

Yuya Nishihara yuya at tcha.org
Sun Jul 5 09:01:53 CDT 2015


On Fri, 03 Jul 2015 14:19:17 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1435958308 25200
> #      Fri Jul 03 14:18:28 2015 -0700
> # Node ID 17d2b4b8eaaf8bab93d75cfded8042e2d82a3bff
> # Parent  84518051bc3b851f736872df045d662de548b3c9
> hg: support for auto sharing stores when cloning

I think this function is great. It will reduce bandwidth and disk space on
batch clone and subsequent pulls.

Just nitpicking follows:

> +    # In auto share mode, the store / actual source repo is in
> +    # the <autosharebasedir>/<rev0> directory. Clone consists of ensuring
> +    # that directory exists and is up to date followed by the creation of
> +    # a shared repo from that source.
> +    if sharebasepath:
> +        sharepath = None
> +        if sharenamemode == 'root':
> +            # Repositories can have multiple roots. But using revision 0 should
> +            # be good enough for almost all use cases. Worst case there is no
> +            # cache hit.
> +            rootnode = srcpeer.lookup('0')

If the revision 0 is hidden, it will abort.

> +            # Sharing empty repositories doesn't make sense.
> +            if rootnode != node.nullid:
> +                sharepath = os.path.join(sharebasepath, node.hex(rootnode))
> +        elif sharenamemode == 'remote':
> +            normpath = source
> +            replacements = (
> +                ('\\', '/'),
> +                ('://', '_'),
> +                (':', '_'),
> +                ('/', '_'),
> +            )
> +            for s, r in replacements:
> +                normpath = normpath.replace(s, r)
> +            normpath = normpath.lower()
> +            sharepath = os.path.join(sharebasepath, normpath)
> +        else:
> +            raise util.Abort('unknown sharenamemode: %s' % sharenamemode)

I might want to use the hash value of the remote path to avoid possible escaping
error. The name could be specified as template:

  share.name = "root"
             | "remote"
             | template (e.g. "{url|sha1}", "{rootnode}", etc.)


More information about the Mercurial-devel mailing list