changeset 14090:e24b5e3c2f27

add filteropener abstraction for store openers
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sat, 30 Apr 2011 19:37:13 +0200
parents d3f7e110c3c0
children 0aa60e4e0b76
files mercurial/scmutil.py mercurial/store.py
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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):