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