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

Durham Goode durham at fb.com
Wed Aug 14 16:02:03 CDT 2013


# 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. 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 {}
+
+        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
+
+        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()
 


More information about the Mercurial-devel mailing list