##// END OF EJS Templates
store: simplify class hierarchy
Matt Mackall -
r6898:69aeaaaf default
parent child Browse files
Show More
@@ -47,19 +47,24 b' def _dirwalk(path, recurse):'
47 elif kind == stat.S_IFREG:
47 elif kind == stat.S_IFREG:
48 yield pe, st.st_size
48 yield pe, st.st_size
49
49
50 class _store:
50 def _calcmode(path):
51 '''base class for local repository stores'''
52 def __init__(self, path):
53 self.path = path
54 try:
51 try:
55 # files in .hg/ will be created using this mode
52 # files in .hg/ will be created using this mode
56 mode = os.stat(self.path).st_mode
53 mode = os.stat(path).st_mode
57 # avoid some useless chmods
54 # avoid some useless chmods
58 if (0777 & ~util._umask) == (0777 & mode):
55 if (0777 & ~util._umask) == (0777 & mode):
59 mode = None
56 mode = None
60 except OSError:
57 except OSError:
61 mode = None
58 mode = None
62 self.createmode = mode
59 return mode
60
61 class basicstore:
62 '''base class for local repository stores'''
63 def __init__(self, path, opener):
64 self.path = path
65 self.createmode = _calcmode(path)
66 self.opener = opener(self.path)
67 self.opener.createmode = self.createmode
63
68
64 def join(self, f):
69 def join(self, f):
65 return os.path.join(self.path, f)
70 return os.path.join(self.path, f)
@@ -93,15 +98,10 b' class _store:'
93 for x in meta:
98 for x in meta:
94 yield x
99 yield x
95
100
96 class directstore(_store):
101 class encodedstore(basicstore):
97 def __init__(self, path, opener):
102 def __init__(self, path, opener):
98 _store.__init__(self, path)
103 self.path = os.path.join(path, 'store')
99 self.opener = opener(self.path)
104 self.createmode = _calcmode(self.path)
100 self.opener.createmode = self.createmode
101
102 class encodedstore(_store):
103 def __init__(self, path, opener):
104 _store.__init__(self, os.path.join(path, 'store'))
105 self.encodefn = encodefilename
105 self.encodefn = encodefilename
106 op = opener(self.path)
106 op = opener(self.path)
107 op.createmode = self.createmode
107 op.createmode = self.createmode
@@ -120,7 +120,6 b' class encodedstore(_store):'
120 return os.path.join(self.path, self.encodefn(f))
120 return os.path.join(self.path, self.encodefn(f))
121
121
122 def store(requirements, path, opener):
122 def store(requirements, path, opener):
123 if 'store' not in requirements:
123 if 'store' in requirements:
124 return directstore(path, opener)
125 else:
126 return encodedstore(path, opener)
124 return encodedstore(path, opener)
125 return basicstore(path, opener)
@@ -23,4 +23,4 b' echo'
23 echo % verify
23 echo % verify
24 hg verify
24 hg verify
25
25
26 return 0
26 exit 0
General Comments 0
You need to be logged in to leave comments. Login now