##// 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
51 self._read()
52 @propertycache
52 return self._copymap
53 def _copymap(self):
53 elif name == '_foldmap':
54 self._read()
54 _foldmap = {}
55 return self._copymap
55 for name in self._map:
56
56 norm = os.path.normcase(name)
57 @propertycache
57 _foldmap[norm] = name
58 def _foldmap(self):
58 self._foldmap = _foldmap
59 f = {}
59 return self._foldmap
60 for name in self._map:
60 elif name == '_branch':
61 f[os.path.normcase(name)] = name
61 try:
62 return f
62 self._branch = (self._opener("branch").read().strip()
63
63 or "default")
64 @propertycache
64 except IOError:
65 def _branch(self):
65 self._branch = "default"
66 try:
66 return self._branch
67 return self._opener("branch").read().strip() or "default"
67 elif name == '_pl':
68 except IOError:
68 self._pl = [nullid, nullid]
69 return "default"
69 try:
70
70 st = self._opener("dirstate").read(40)
71 @propertycache
71 if len(st) == 40:
72 def _pl(self):
72 self._pl = st[:20], st[20:40]
73 try:
73 except IOError, err:
74 st = self._opener("dirstate").read(40)
74 if err.errno != errno.ENOENT: raise
75 if len(st) == 40:
75 return self._pl
76 return st[:20], st[20:40]
76 elif name == '_dirs':
77 except IOError, err:
77 dirs = {}
78 if err.errno != errno.ENOENT: raise
78 for f,s in self._map.iteritems():
79 return [nullid, nullid]
79 if s[0] != 'r':
80
80 _incdirs(dirs, f)
81 @propertycache
81 self._dirs = dirs
82 def _dirs(self):
82 return self._dirs
83 dirs = {}
83 elif name == '_ignore':
84 for f,s in self._map.iteritems():
84 files = [self._join('.hgignore')]
85 if s[0] != 'r':
85 for name, path in self._ui.configitems("ui"):
86 _incdirs(dirs, f)
86 if name == 'ignore' or name.startswith('ignore.'):
87 return dirs
87 files.append(os.path.expanduser(path))
88
88 self._ignore = ignore.ignore(self._root, files, self._ui.warn)
89 @propertycache
89 return self._ignore
90 def _ignore(self):
90 elif name == '_slash':
91 files = [self._join('.hgignore')]
91 self._slash = self._ui.configbool('ui', 'slash') and os.sep != '/'
92 for name, path in self._ui.configitems("ui"):
92 return self._slash
93 if name == 'ignore' or name.startswith('ignore.'):
93 elif name == '_checklink':
94 files.append(os.path.expanduser(path))
94 self._checklink = util.checklink(self._root)
95 return ignore.ignore(self._root, files, self._ui.warn)
95 return self._checklink
96
96 elif name == '_checkexec':
97 @propertycache
97 self._checkexec = util.checkexec(self._root)
98 def _slash(self):
98 return self._checkexec
99 return self._ui.configbool('ui', 'slash') and os.sep != '/'
99 elif name == '_checkcase':
100
100 self._checkcase = not util.checkcase(self._join('.hg'))
101 @propertycache
101 return self._checkcase
102 def _checklink(self):
102 elif name == 'normalize':
103 return util.checklink(self._root)
103 if self._checkcase:
104
104 self.normalize = self._normalize
105 @propertycache
105 else:
106 def _checkexec(self):
106 self.normalize = lambda x, y=False: x
107 return util.checkexec(self._root)
107 return self.normalize
108
108 else:
109 @propertycache
109 raise AttributeError(name)
110 def _checkcase(self):
111 return not util.checkcase(self._join('.hg'))
112
113 @propertycache
114 def normalize(self):
115 if self._checkcase:
116 return self._normalize
117 return lambda x, y=False: x
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