##// 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 encodefilename, decodefilename = _buildencodefun()
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 def _calcmode(path):
39 def _calcmode(path):
51 try:
40 try:
52 # files in .hg/ will be created using this mode
41 # files in .hg/ will be created using this mode
@@ -69,23 +58,26 b' class basicstore:'
69 def join(self, f):
58 def join(self, f):
70 return os.path.join(self.path, f)
59 return os.path.join(self.path, f)
71
60
72 def _revlogfiles(self, relpath='', recurse=False):
61 def _walk(self, relpath, recurse):
73 '''yields (filename, size)'''
62 '''yields (filename, size)'''
74 if relpath:
63 path = os.path.join(self.path, relpath)
75 path = os.path.join(self.path, relpath)
76 else:
77 path = self.path
78 if not os.path.isdir(path):
79 return
80 striplen = len(self.path) + len(os.sep)
64 striplen = len(self.path) + len(os.sep)
81 filetypes = ('.d', '.i')
65 prefix = path[striplen:]
82 for f, size in _dirwalk(path, recurse):
66 l = []
83 if (len(f) > 2) and f[-2:] in filetypes:
67 if os.path.isdir(path):
84 yield util.pconvert(f[striplen:]), size
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 def datafiles(self, reporterror=None):
79 def datafiles(self, reporterror=None):
87 for x in self._revlogfiles('data', True):
80 return self._walk('data', True)
88 yield x
89
81
90 def walk(self):
82 def walk(self):
91 '''yields (direncoded filename, size)'''
83 '''yields (direncoded filename, size)'''
@@ -93,7 +85,7 b' class basicstore:'
93 for x in self.datafiles():
85 for x in self.datafiles():
94 yield x
86 yield x
95 # yield manifest before changelog
87 # yield manifest before changelog
96 meta = util.sort(self._revlogfiles())
88 meta = self._walk('', False)
97 meta.reverse()
89 meta.reverse()
98 for x in meta:
90 for x in meta:
99 yield x
91 yield x
@@ -108,7 +100,7 b' class encodedstore(basicstore):'
108 self.opener = lambda f, *args, **kw: op(self.encodefn(f), *args, **kw)
100 self.opener = lambda f, *args, **kw: op(self.encodefn(f), *args, **kw)
109
101
110 def datafiles(self, reporterror=None):
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 try:
104 try:
113 yield decodefilename(f), size
105 yield decodefilename(f), size
114 except KeyError:
106 except KeyError:
General Comments 0
You need to be logged in to leave comments. Login now