# HG changeset patch # User Matt Mackall # Date 1218676723 18000 # Node ID 69aeaaaf6e07e1eb3f1259dfa8201727af2bbb9f # Parent faea0d27e38fb1a61ab35982d9d46c77b58b8680 store: simplify class hierarchy diff -r faea0d27e38f -r 69aeaaaf6e07 mercurial/store.py --- 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) diff -r faea0d27e38f -r 69aeaaaf6e07 tests/test-verify --- 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