##// END OF EJS Templates
dirstate: hide internal vars...
Matt Mackall -
r4614:a8be3c87 default
parent child Browse files
Show More
@@ -677,10 +677,7 b' def debugrebuildstate(ui, repo, rev=""):'
677 677 def debugcheckstate(ui, repo):
678 678 """validate the correctness of the current dirstate"""
679 679 parent1, parent2 = repo.dirstate.parents()
680 repo.dirstate.read()
681 dc = repo.dirstate.map
682 keys = dc.keys()
683 keys.sort()
680 dc = repo.dirstate
684 681 m1 = repo.changectx(parent1).manifest()
685 682 m2 = repo.changectx(parent2).manifest()
686 683 errors = 0
@@ -749,11 +746,8 b' def debugsetparents(ui, repo, rev1, rev2'
749 746
750 747 def debugstate(ui, repo):
751 748 """show the contents of the current dirstate"""
752 repo.dirstate.read()
753 dc = repo.dirstate.map
754 keys = dc.keys()
755 keys.sort()
756 for file_ in keys:
749 dc = repo.dirstate
750 for file_ in dc:
757 751 if dc[file_][3] == -1:
758 752 # Pad or slice to locale representation
759 753 locale_len = len(time.strftime("%x %X", time.localtime(0)))
@@ -18,57 +18,57 b' import cStringIO'
18 18 class dirstate(object):
19 19
20 20 def __init__(self, opener, ui, root):
21 self.opener = opener
22 self.root = root
21 self._opener = opener
22 self._root = root
23 23 self._dirty = 0
24 self.ui = ui
24 self._ui = ui
25 25
26 26 def __getattr__(self, name):
27 if name == 'map':
27 if name == '_map':
28 28 self.read()
29 return self.map
30 elif name == 'copymap':
29 return self._map
30 elif name == '_copymap':
31 31 self.read()
32 return self.copymap
32 return self._copymap
33 33 elif name == '_branch':
34 34 try:
35 self._branch = self.opener("branch").read().strip()\
35 self._branch = self._opener("branch").read().strip()\
36 36 or "default"
37 37 except IOError:
38 38 self._branch = "default"
39 39 return self._branch
40 elif name == 'pl':
41 self.pl = [nullid, nullid]
40 elif name == '_pl':
41 self._pl = [nullid, nullid]
42 42 try:
43 st = self.opener("dirstate").read(40)
43 st = self._opener("dirstate").read(40)
44 44 if len(st) == 40:
45 self.pl = st[:20], st[20:40]
45 self._pl = st[:20], st[20:40]
46 46 except IOError, err:
47 47 if err.errno != errno.ENOENT: raise
48 return self.pl
48 return self._pl
49 49 elif name == 'dirs':
50 50 self.dirs = {}
51 for f in self.map:
51 for f in self._map:
52 52 self.updatedirs(f, 1)
53 53 return self.dirs
54 54 elif name == '_ignore':
55 files = [self.wjoin('.hgignore')] + self.ui.hgignorefiles()
56 self._ignore = ignore.ignore(self.root, files, self.ui.warn)
55 files = [self.wjoin('.hgignore')] + self._ui.hgignorefiles()
56 self._ignore = ignore.ignore(self._root, files, self._ui.warn)
57 57 return self._ignore
58 58 elif name == '_slash':
59 self._slash = self.ui.configbool('ui', 'slash') and os.sep != '/'
59 self._slash = self._ui.configbool('ui', 'slash') and os.sep != '/'
60 60 return self._slash
61 61 else:
62 62 raise AttributeError, name
63 63
64 64 def wjoin(self, f):
65 return os.path.join(self.root, f)
65 return os.path.join(self._root, f)
66 66
67 67 def getcwd(self):
68 68 cwd = os.getcwd()
69 if cwd == self.root: return ''
70 # self.root ends with a path separator if self.root is '/' or 'C:\'
71 rootsep = self.root
69 if cwd == self._root: return ''
70 # self._root ends with a path separator if self._root is '/' or 'C:\'
71 rootsep = self._root
72 72 if not rootsep.endswith(os.sep):
73 73 rootsep += os.sep
74 74 if cwd.startswith(rootsep):
@@ -80,7 +80,7 b' class dirstate(object):'
80 80 def pathto(self, f, cwd=None):
81 81 if cwd is None:
82 82 cwd = self.getcwd()
83 path = util.pathto(self.root, cwd, f)
83 path = util.pathto(self._root, cwd, f)
84 84 if self._slash:
85 85 return path.replace(os.sep, '/')
86 86 return path
@@ -89,13 +89,19 b' class dirstate(object):'
89 89 self.write()
90 90
91 91 def __getitem__(self, key):
92 return self.map[key]
92 return self._map[key]
93 93
94 94 def __contains__(self, key):
95 return key in self.map
95 return key in self._map
96
97 def __iter__(self):
98 a = self._map.keys()
99 a.sort()
100 for x in a:
101 yield x
96 102
97 103 def parents(self):
98 return self.pl
104 return self._pl
99 105
100 106 def branch(self):
101 107 return self._branch
@@ -105,32 +111,32 b' class dirstate(object):'
105 111
106 112 def setparents(self, p1, p2=nullid):
107 113 self.markdirty()
108 self.pl = p1, p2
114 self._pl = p1, p2
109 115
110 116 def setbranch(self, branch):
111 117 self._branch = branch
112 self.opener("branch", "w").write(branch + '\n')
118 self._opener("branch", "w").write(branch + '\n')
113 119
114 120 def state(self, key):
115 return self.map.get(key, ("?",))[0]
121 return self._map.get(key, ("?",))[0]
116 122
117 123 def read(self):
118 self.map = {}
119 self.copymap = {}
120 self.pl = [nullid, nullid]
124 self._map = {}
125 self._copymap = {}
126 self._pl = [nullid, nullid]
121 127 try:
122 st = self.opener("dirstate").read()
128 st = self._opener("dirstate").read()
123 129 except IOError, err:
124 130 if err.errno != errno.ENOENT: raise
125 131 return
126 132 if not st:
127 133 return
128 134
129 self.pl = [st[:20], st[20: 40]]
135 self._pl = [st[:20], st[20: 40]]
130 136
131 137 # deref fields so they will be local in loop
132 dmap = self.map
133 copymap = self.copymap
138 dmap = self._map
139 copymap = self._copymap
134 140 unpack = struct.unpack
135 141
136 142 pos = 40
@@ -150,19 +156,19 b' class dirstate(object):'
150 156 pos = newpos
151 157
152 158 def invalidate(self):
153 for a in "map copymap _branch pl dirs _ignore".split():
159 for a in "_map _copymap _branch pl dirs _ignore".split():
154 160 if hasattr(self, a):
155 161 self.__delattr__(a)
156 162
157 163 def copy(self, source, dest):
158 164 self.markdirty()
159 self.copymap[dest] = source
165 self._copymap[dest] = source
160 166
161 167 def copied(self, file):
162 return self.copymap.get(file, None)
168 return self._copymap.get(file, None)
163 169
164 170 def copies(self):
165 return self.copymap
171 return self._copymap
166 172
167 173 def updatedirs(self, path, delta):
168 174 for c in strutil.findall(path, '/'):
@@ -183,7 +189,7 b' class dirstate(object):'
183 189 for d in prefixes(f):
184 190 if d in seendirs:
185 191 break
186 if d in self.map:
192 if d in self._map:
187 193 raise util.Abort(_('file named %r already in dirstate') %
188 194 d)
189 195 seendirs[d] = True
@@ -204,7 +210,7 b' class dirstate(object):'
204 210 self.checkinterfering(files)
205 211 for f in files:
206 212 if state == "r":
207 self.map[f] = ('r', 0, 0, 0)
213 self._map[f] = ('r', 0, 0, 0)
208 214 self.updatedirs(f, -1)
209 215 else:
210 216 if state == "a":
@@ -212,44 +218,44 b' class dirstate(object):'
212 218 s = os.lstat(self.wjoin(f))
213 219 st_size = kw.get('st_size', s.st_size)
214 220 st_mtime = kw.get('st_mtime', s.st_mtime)
215 self.map[f] = (state, s.st_mode, st_size, st_mtime)
216 if self.copymap.has_key(f):
217 del self.copymap[f]
221 self._map[f] = (state, s.st_mode, st_size, st_mtime)
222 if self._copymap.has_key(f):
223 del self._copymap[f]
218 224
219 225 def forget(self, files):
220 226 if not files: return
221 227 self.markdirty()
222 228 for f in files:
223 229 try:
224 del self.map[f]
230 del self._map[f]
225 231 self.updatedirs(f, -1)
226 232 except KeyError:
227 self.ui.warn(_("not in dirstate: %s!\n") % f)
233 self._ui.warn(_("not in dirstate: %s!\n") % f)
228 234 pass
229 235
230 236 def rebuild(self, parent, files):
231 237 self.invalidate()
232 238 for f in files:
233 239 if files.execf(f):
234 self.map[f] = ('n', 0777, -1, 0)
240 self._map[f] = ('n', 0777, -1, 0)
235 241 else:
236 self.map[f] = ('n', 0666, -1, 0)
237 self.pl = (parent, nullid)
242 self._map[f] = ('n', 0666, -1, 0)
243 self._pl = (parent, nullid)
238 244 self.markdirty()
239 245
240 246 def write(self):
241 247 if not self._dirty:
242 248 return
243 249 cs = cStringIO.StringIO()
244 cs.write("".join(self.pl))
245 for f, e in self.map.iteritems():
250 cs.write("".join(self._pl))
251 for f, e in self._map.iteritems():
246 252 c = self.copied(f)
247 253 if c:
248 254 f = f + "\0" + c
249 255 e = struct.pack(_format, e[0], e[1], e[2], e[3], len(f))
250 256 cs.write(e)
251 257 cs.write(f)
252 st = self.opener("dirstate", "w", atomictemp=True)
258 st = self._opener("dirstate", "w", atomictemp=True)
253 259 st.write(cs.getvalue())
254 260 st.rename()
255 261 self._dirty = 0
@@ -260,16 +266,16 b' class dirstate(object):'
260 266
261 267 for x in files:
262 268 if x == '.':
263 return self.map.copy()
264 if x not in self.map:
269 return self._map.copy()
270 if x not in self._map:
265 271 unknown.append(x)
266 272 else:
267 ret[x] = self.map[x]
273 ret[x] = self._map[x]
268 274
269 275 if not unknown:
270 276 return ret
271 277
272 b = self.map.keys()
278 b = self._map.keys()
273 279 b.sort()
274 280 blen = len(b)
275 281
@@ -278,7 +284,7 b' class dirstate(object):'
278 284 while bs < blen:
279 285 s = b[bs]
280 286 if len(s) > len(x) and s.startswith(x):
281 ret[s] = self.map[s]
287 ret[s] = self._map[s]
282 288 else:
283 289 break
284 290 bs += 1
@@ -294,7 +300,7 b' class dirstate(object):'
294 300 elif stat.S_ISFIFO(st.st_mode): kind = _('fifo')
295 301 elif stat.S_ISSOCK(st.st_mode): kind = _('socket')
296 302 elif stat.S_ISDIR(st.st_mode): kind = _('directory')
297 self.ui.warn(_('%s: unsupported file type (type is %s)\n')
303 self._ui.warn(_('%s: unsupported file type (type is %s)\n')
298 304 % (self.pathto(f), kind))
299 305 return False
300 306
@@ -322,7 +328,7 b' class dirstate(object):'
322 328 # walk all files by default
323 329 if not files:
324 330 files = ['.']
325 dc = self.map.copy()
331 dc = self._map.copy()
326 332 else:
327 333 files = util.unique(files)
328 334 dc = self.filterfiles(files)
@@ -337,9 +343,9 b' class dirstate(object):'
337 343 imatch = match
338 344 ignore = util.never
339 345
340 # self.root may end with a path separator when self.root == '/'
341 common_prefix_len = len(self.root)
342 if not self.root.endswith(os.sep):
346 # self._root may end with a path separator when self._root == '/'
347 common_prefix_len = len(self._root)
348 if not self._root.endswith(os.sep):
343 349 common_prefix_len += 1
344 350 # recursion free walker, faster than os.walk.
345 351 def findfiles(s):
@@ -402,7 +408,7 b' class dirstate(object):'
402 408 break
403 409 if not found:
404 410 if inst.errno != errno.ENOENT or not badmatch:
405 self.ui.warn('%s: %s\n' % (self.pathto(ff),
411 self._ui.warn('%s: %s\n' % (self.pathto(ff),
406 412 inst.strerror))
407 413 elif badmatch and badmatch(ff) and imatch(nf):
408 414 yield 'b', ff, None
General Comments 0
You need to be logged in to leave comments. Login now