##// END OF EJS Templates
dirstate: use propertycache
Matt Mackall -
r8261:0fe1f57a default
parent child Browse files
Show More
@@ -12,6 +12,7 b' import cStringIO, osutil, sys, parsers'
12
12
13 _unknown = ('?', 0, 0, 0)
13 _unknown = ('?', 0, 0, 0)
14 _format = ">cllll"
14 _format = ">cllll"
15 propertycache = util.propertycache
15
16
16 def _finddirs(path):
17 def _finddirs(path):
17 pos = path.rfind('/')
18 pos = path.rfind('/')
@@ -43,70 +44,77 b' class dirstate(object):'
43 self._dirtypl = False
44 self._dirtypl = False
44 self._ui = ui
45 self._ui = ui
45
46
46 def __getattr__(self, name):
47 @propertycache
47 if name == '_map':
48 def _map(self):
48 self._read()
49 self._read()
49 return self._map
50 return self._map
50 elif name == '_copymap':
51
52 @propertycache
53 def _copymap(self):
51 self._read()
54 self._read()
52 return self._copymap
55 return self._copymap
53 elif name == '_foldmap':
56
54 _foldmap = {}
57 @propertycache
58 def _foldmap(self):
59 f = {}
55 for name in self._map:
60 for name in self._map:
56 norm = os.path.normcase(name)
61 f[os.path.normcase(name)] = name
57 _foldmap[norm] = name
62 return f
58 self._foldmap = _foldmap
63
59 return self._foldmap
64 @propertycache
60 elif name == '_branch':
65 def _branch(self):
61 try:
66 try:
62 self._branch = (self._opener("branch").read().strip()
67 return self._opener("branch").read().strip() or "default"
63 or "default")
64 except IOError:
68 except IOError:
65 self._branch = "default"
69 return "default"
66 return self._branch
70
67 elif name == '_pl':
71 @propertycache
68 self._pl = [nullid, nullid]
72 def _pl(self):
69 try:
73 try:
70 st = self._opener("dirstate").read(40)
74 st = self._opener("dirstate").read(40)
71 if len(st) == 40:
75 if len(st) == 40:
72 self._pl = st[:20], st[20:40]
76 return st[:20], st[20:40]
73 except IOError, err:
77 except IOError, err:
74 if err.errno != errno.ENOENT: raise
78 if err.errno != errno.ENOENT: raise
75 return self._pl
79 return [nullid, nullid]
76 elif name == '_dirs':
80
81 @propertycache
82 def _dirs(self):
77 dirs = {}
83 dirs = {}
78 for f,s in self._map.iteritems():
84 for f,s in self._map.iteritems():
79 if s[0] != 'r':
85 if s[0] != 'r':
80 _incdirs(dirs, f)
86 _incdirs(dirs, f)
81 self._dirs = dirs
87 return dirs
82 return self._dirs
88
83 elif name == '_ignore':
89 @propertycache
90 def _ignore(self):
84 files = [self._join('.hgignore')]
91 files = [self._join('.hgignore')]
85 for name, path in self._ui.configitems("ui"):
92 for name, path in self._ui.configitems("ui"):
86 if name == 'ignore' or name.startswith('ignore.'):
93 if name == 'ignore' or name.startswith('ignore.'):
87 files.append(os.path.expanduser(path))
94 files.append(os.path.expanduser(path))
88 self._ignore = ignore.ignore(self._root, files, self._ui.warn)
95 return ignore.ignore(self._root, files, self._ui.warn)
89 return self._ignore
96
90 elif name == '_slash':
97 @propertycache
91 self._slash = self._ui.configbool('ui', 'slash') and os.sep != '/'
98 def _slash(self):
92 return self._slash
99 return self._ui.configbool('ui', 'slash') and os.sep != '/'
93 elif name == '_checklink':
100
94 self._checklink = util.checklink(self._root)
101 @propertycache
95 return self._checklink
102 def _checklink(self):
96 elif name == '_checkexec':
103 return util.checklink(self._root)
97 self._checkexec = util.checkexec(self._root)
104
98 return self._checkexec
105 @propertycache
99 elif name == '_checkcase':
106 def _checkexec(self):
100 self._checkcase = not util.checkcase(self._join('.hg'))
107 return util.checkexec(self._root)
101 return self._checkcase
108
102 elif name == 'normalize':
109 @propertycache
110 def _checkcase(self):
111 return not util.checkcase(self._join('.hg'))
112
113 @propertycache
114 def normalize(self):
103 if self._checkcase:
115 if self._checkcase:
104 self.normalize = self._normalize
116 return self._normalize
105 else:
117 return lambda x, y=False: x
106 self.normalize = lambda x, y=False: x
107 return self.normalize
108 else:
109 raise AttributeError(name)
110
118
111 def _join(self, f):
119 def _join(self, f):
112 # much faster than os.path.join()
120 # much faster than os.path.join()
General Comments 0
You need to be logged in to leave comments. Login now