[PATCH 1 of 3 V3] schemas: add schemas to repositories

Martin Geisler martin at geisler.net
Thu Aug 15 02:58:23 CDT 2013


Durham Goode <durham at fb.com> writes:

> # HG changeset patch
> # User Durham Goode <durham at fb.com>
> # Date 1375827328 25200
> #      Tue Aug 06 15:15:28 2013 -0700
> # Node ID 84ac4b920802805474d203b5b5dc1cd4aa861256
> # Parent  3e34e7b223d10bbe8814f82d7a1f53575fe09096
> schemas: add schemas to repositories
>
> This adds the concept of schemas to repositories. A schema is a
> key/value pair indicating alternative means of accessing the remote
> repository.

When reading this I wonder how this differs from the pushkey system?
That's also a key/value store and as we've discussed, it could be used
for "schemas" too. Noting the advantage of a new key/value store would
probably be a good idea.

> For example, the largefiles extension might provide a schema such as:
>
> largefiles = http://some.cdn.com/myrepo
>
> When a user interacts with the repository, if the client knows how to
> handle the largefiles schema, it will read the url and obtain
> largefiles from the url. Thus letting you serve large files from a
> CDN.
>
> The next patch will allow querying schemas via the wire protocol.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -661,6 +661,47 @@
>              bt[bn] = self._branchtip(heads)
>          return bt
>  
> +    @repofilecache('schemas')
> +    def schemas(self):
> +        try:
> +            file = self.opener('schemas')
> +        except IOError, inst:
> +            if inst.errno != errno.ENOENT:
> +                raise
> +            return {}

This pattern is also in abstractvfs.tryread. Maybe that could be used
instead somehow?

> +        try:
> +            schemas = {}
> +            lines = file.readlines()
> +            for line in lines:
> +                if line.find('=') > 0:
> +                    k, v = line.split('=', 1)
> +                    schemas[k.strip()] = v[:-1].strip()
> +
> +            return schemas
> +        finally:
> +            file.close()
> +
> +    def registerschema(self, name, url):
> +        existingschemas = self.schemas
> +        existingschemas[name] = url
> +        try:
> +            file = self.opener('schemas', 'w')
> +        except IOError, inst:
> +            if inst.errno != errno.ENOENT:
> +                raise
> +            return

Isn't this pattern only used when reading (not writing) a possibly
missing file?

Here you end up not serializing the schemes if a directory on the path
to <repo>/.hg/schemes doesn't exist -- which seems unlikely :)

> +        try:
> +            serialized = ""
> +            for k, v in existingschemas.iteritems():
> +                if len(k) > 0 and len(v) > 0:

I think 'if k and v:' is the usual style here.

-- 
Martin Geisler


More information about the Mercurial-devel mailing list