add filteropener abstraction for store openers
authorDan Villiom Podlaski Christiansen <danchr@gmail.com>
Sat, 30 Apr 2011 19:37:13 +0200
changeset 14090 e24b5e3c2f27
parent 14089 d3f7e110c3c0
child 14091 0aa60e4e0b76
add filteropener abstraction for store openers
mercurial/scmutil.py
mercurial/store.py
--- a/mercurial/scmutil.py	Sat Apr 30 19:36:48 2011 +0200
+++ b/mercurial/scmutil.py	Sat Apr 30 19:37:13 2011 +0200
@@ -231,6 +231,16 @@
             f.close()
             self._fixfilemode(dst)
 
+class filteropener(abstractopener):
+    '''Wrapper opener for filtering filenames with a function.'''
+
+    def __init__(self, opener, filter):
+        self._filter = filter
+        self._orig = opener
+
+    def __call__(self, path, *args, **kwargs):
+        return self._orig(self._filter(path), *args, **kwargs)
+
 def canonpath(root, cwd, myname, auditor=None):
     '''return the canonical path of myname, given cwd and root'''
     if util.endswithsep(root):
--- a/mercurial/store.py	Sat Apr 30 19:36:48 2011 +0200
+++ b/mercurial/store.py	Sat Apr 30 19:37:13 2011 +0200
@@ -6,7 +6,7 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import osutil, util
+import osutil, scmutil, util
 import os, stat
 
 _sha = util.sha1
@@ -241,7 +241,7 @@
         self.createmode = _calcmode(path)
         op = opener(self.path)
         op.createmode = self.createmode
-        self.opener = lambda f, *args, **kw: op(encodedir(f), *args, **kw)
+        self.opener = scmutil.filteropener(op, encodedir)
 
     def join(self, f):
         return self.path + '/' + encodedir(f)
@@ -290,7 +290,7 @@
         self.createmode = _calcmode(self.path)
         op = opener(self.path)
         op.createmode = self.createmode
-        self.opener = lambda f, *args, **kw: op(encodefilename(f), *args, **kw)
+        self.opener = scmutil.filteropener(op, encodefilename)
 
     def datafiles(self):
         for a, b, size in self._walk('data', True):