##// END OF EJS Templates
store: simplify walking...
Matt Mackall -
r6899:56a7a54e default
parent child Browse files
Show More
@@ -36,17 +36,6 b' def _buildencodefun():'
36 36
37 37 encodefilename, decodefilename = _buildencodefun()
38 38
39 def _dirwalk(path, recurse):
40 '''yields (filename, size)'''
41 for e, kind, st in osutil.listdir(path, stat=True):
42 pe = os.path.join(path, e)
43 if kind == stat.S_IFDIR:
44 if recurse:
45 for x in _dirwalk(pe, True):
46 yield x
47 elif kind == stat.S_IFREG:
48 yield pe, st.st_size
49
50 39 def _calcmode(path):
51 40 try:
52 41 # files in .hg/ will be created using this mode
@@ -69,23 +58,26 b' class basicstore:'
69 58 def join(self, f):
70 59 return os.path.join(self.path, f)
71 60
72 def _revlogfiles(self, relpath='', recurse=False):
61 def _walk(self, relpath, recurse):
73 62 '''yields (filename, size)'''
74 if relpath:
75 63 path = os.path.join(self.path, relpath)
76 else:
77 path = self.path
78 if not os.path.isdir(path):
79 return
80 64 striplen = len(self.path) + len(os.sep)
81 filetypes = ('.d', '.i')
82 for f, size in _dirwalk(path, recurse):
83 if (len(f) > 2) and f[-2:] in filetypes:
84 yield util.pconvert(f[striplen:]), size
65 prefix = path[striplen:]
66 l = []
67 if os.path.isdir(path):
68 visit = [path]
69 while visit:
70 p = visit.pop()
71 for f, kind, st in osutil.listdir(p, stat=True):
72 fp = os.path.join(p, f)
73 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
74 l.append((util.pconvert(fp[striplen:]), st.st_size))
75 elif kind == stat.S_IFDIR and recurse:
76 visit.append(fp)
77 return util.sort(l)
85 78
86 79 def datafiles(self, reporterror=None):
87 for x in self._revlogfiles('data', True):
88 yield x
80 return self._walk('data', True)
89 81
90 82 def walk(self):
91 83 '''yields (direncoded filename, size)'''
@@ -93,7 +85,7 b' class basicstore:'
93 85 for x in self.datafiles():
94 86 yield x
95 87 # yield manifest before changelog
96 meta = util.sort(self._revlogfiles())
88 meta = self._walk('', False)
97 89 meta.reverse()
98 90 for x in meta:
99 91 yield x
@@ -108,7 +100,7 b' class encodedstore(basicstore):'
108 100 self.opener = lambda f, *args, **kw: op(self.encodefn(f), *args, **kw)
109 101
110 102 def datafiles(self, reporterror=None):
111 for f, size in self._revlogfiles('data', True):
103 for f, size in self._walk('data', True):
112 104 try:
113 105 yield decodefilename(f), size
114 106 except KeyError:
General Comments 0
You need to be logged in to leave comments. Login now