From patchwork Thu Aug 8 23:31:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1,of,4,V2] schemas: add schemas to repositories From: Durham Goode X-Patchwork-Id: 2097 Message-Id: To: mercurial-devel@selenic.com Date: Thu, 08 Aug 2013 16:31:45 -0700 # HG changeset patch # User Durham Goode # Date 1375827328 25200 # Tue Aug 06 15:15:28 2013 -0700 # Node ID c683c90d00b124f985f4d8b3b51c65210317eb38 # 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. 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 key difference between this and normal hgrc config options is that it is copied across to the client during clone/pull. So if a client clones from another client, they will also see the available schemas from the original server. The logic for clone/pull will happen in a later patch. This change enables an extension we're working on that will keep all of the file history on the server, and clients will all have shallow repos. 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 {} + + 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 addschemas(self, schemas): + existingschemas = self.schemas + existingschemas.update(schemas) + try: + file = self.opener('schemas', 'w') + except IOError, inst: + if inst.errno != errno.ENOENT: + raise + return + + try: + serialized = "" + for k, v in existingschemas.iteritems(): + if len(k) > 0 and len(v) > 0: + serialized += "%s = %s\n" % (k, v) + + file.write(serialized) + finally: + file.close() + def lookup(self, key): return self[key].node()