[PATCH 1 of 4] schemas: add schemas to repositories

Durham Goode durham at fb.com
Tue Aug 6 19:28:26 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 f6fca02b697a67bec6e6ca2c9a48d7c7d7f1d077
# 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] = v[:-1]
+
+            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()
 


More information about the Mercurial-devel mailing list