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

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 4, 2013, 1:04 a.m.
Message ID <f8a602bc30ba2903fcdf.1357261445@yamac.lan>
Download mbox | patch
Permalink /patch/371/
State Accepted
Commit c38a62af000e3bd4a760066656751a8132c54c2c
Headers show

Comments

Pierre-Yves David - Jan. 4, 2013, 1:04 a.m.
# 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.

Patch

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: