[PATCH 02 of 18 V2] vfs: add a read only vfs

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jan 3 19:04:05 CST 2013


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1357258045 -3600
# Node ID f8a602bc30ba2903fcdf0d0a84c20c3f5c394ad3
# Parent  584a4a3d20906768dbb3fc57f77cbfc0a41bc75e
vfs: add a read only vfs

This read only wrapper is intended to be used bundle repo. See follow up commit
for details.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -380,10 +380,22 @@ class filtervfs(abstractvfs, auditvfs):
         else:
             return self.vfs.join(path)
 
 filteropener = filtervfs
 
+class readonlyvfs(abstractvfs, auditvfs):
+    '''Wrapper vfs preventing any writing.'''
+
+    def __init__(self, vfs):
+        auditvfs.__init__(self, vfs)
+
+    def __call__(self, path, mode='r', *args, **kw):
+        if mode not in ('r', 'rb'):
+            raise util.Abort('this vfs is read only')
+        return self.vfs(path, mode, *args, **kw)
+
+
 def canonpath(root, cwd, myname, auditor=None):
     '''return the canonical path of myname, given cwd and root'''
     if util.endswithsep(root):
         rootsep = root
     else:


More information about the Mercurial-devel mailing list