store: simplify class hierarchy
authorMatt Mackall <mpm@selenic.com>
Wed, 13 Aug 2008 20:18:43 -0500
changeset 6898 69aeaaaf6e07
parent 6897 faea0d27e38f
child 6899 56a7a54e074f
store: simplify class hierarchy
mercurial/store.py
tests/test-verify
--- a/mercurial/store.py	Wed Aug 13 20:18:43 2008 -0500
+++ b/mercurial/store.py	Wed Aug 13 20:18:43 2008 -0500
@@ -47,19 +47,24 @@
         elif kind == stat.S_IFREG:
             yield pe, st.st_size
 
-class _store:
+def _calcmode(path):
+    try:
+        # files in .hg/ will be created using this mode
+        mode = os.stat(path).st_mode
+            # avoid some useless chmods
+        if (0777 & ~util._umask) == (0777 & mode):
+            mode = None
+    except OSError:
+        mode = None
+    return mode
+
+class basicstore:
     '''base class for local repository stores'''
-    def __init__(self, path):
+    def __init__(self, path, opener):
         self.path = path
-        try:
-            # files in .hg/ will be created using this mode
-            mode = os.stat(self.path).st_mode
-            # avoid some useless chmods
-            if (0777 & ~util._umask) == (0777 & mode):
-                mode = None
-        except OSError:
-            mode = None
-        self.createmode = mode
+        self.createmode = _calcmode(path)
+        self.opener = opener(self.path)
+        self.opener.createmode = self.createmode
 
     def join(self, f):
         return os.path.join(self.path, f)
@@ -93,15 +98,10 @@
         for x in meta:
             yield x
 
-class directstore(_store):
+class encodedstore(basicstore):
     def __init__(self, path, opener):
-        _store.__init__(self, path)
-        self.opener = opener(self.path)
-        self.opener.createmode = self.createmode
-
-class encodedstore(_store):
-    def __init__(self, path, opener):
-        _store.__init__(self, os.path.join(path, 'store'))
+        self.path = os.path.join(path, 'store')
+        self.createmode = _calcmode(self.path)
         self.encodefn = encodefilename
         op = opener(self.path)
         op.createmode = self.createmode
@@ -120,7 +120,6 @@
         return os.path.join(self.path, self.encodefn(f))
 
 def store(requirements, path, opener):
-    if 'store' not in requirements:
-        return directstore(path, opener)
-    else:
+    if 'store' in requirements:
         return encodedstore(path, opener)
+    return basicstore(path, opener)
--- a/tests/test-verify	Wed Aug 13 20:18:43 2008 -0500
+++ b/tests/test-verify	Wed Aug 13 20:18:43 2008 -0500
@@ -23,4 +23,4 @@
 echo % verify
 hg verify
 
-return 0
+exit 0