Mercurial > hg
comparison mercurial/dirstate.py @ 4906:30847b8af7ca
dirstate: add __contains__ and make __getitem__ more useful
dirstate.state(f) == '?' -> f not in dirstate
dirstate.state(f) -> dirstate[f]
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 21 Jul 2007 16:02:09 -0500 |
parents | fc61495ea9cf |
children | 6a7659a0c07c |
comparison
equal
deleted
inserted
replaced
4905:fc61495ea9cf | 4906:30847b8af7ca |
---|---|
86 path = util.pathto(self._root, cwd, f) | 86 path = util.pathto(self._root, cwd, f) |
87 if self._slash: | 87 if self._slash: |
88 return path.replace(os.sep, '/') | 88 return path.replace(os.sep, '/') |
89 return path | 89 return path |
90 | 90 |
91 def __del__(self): | |
92 self.write() | |
93 | |
94 def __getitem__(self, key): | 91 def __getitem__(self, key): |
95 return self._map[key] | 92 ''' current states: |
93 n normal | |
94 m needs merging | |
95 r marked for removal | |
96 a marked for addition | |
97 ? not tracked''' | |
98 return self._map.get(key, ("?",))[0] | |
96 | 99 |
97 def __contains__(self, key): | 100 def __contains__(self, key): |
98 return key in self._map | 101 return key in self._map |
99 | 102 |
100 def __iter__(self): | 103 def __iter__(self): |
114 self._pl = p1, p2 | 117 self._pl = p1, p2 |
115 | 118 |
116 def setbranch(self, branch): | 119 def setbranch(self, branch): |
117 self._branch = branch | 120 self._branch = branch |
118 self._opener("branch", "w").write(branch + '\n') | 121 self._opener("branch", "w").write(branch + '\n') |
119 | |
120 def state(self, key): | |
121 ''' current states: | |
122 n normal | |
123 m needs merging | |
124 r marked for removal | |
125 a marked for addition''' | |
126 return self._map.get(key, ("?",))[0] | |
127 | 122 |
128 def _read(self): | 123 def _read(self): |
129 self._map = {} | 124 self._map = {} |
130 self._copymap = {} | 125 self._copymap = {} |
131 self._pl = [nullid, nullid] | 126 self._pl = [nullid, nullid] |
458 lookup, modified, added, unknown, ignored = [], [], [], [], [] | 453 lookup, modified, added, unknown, ignored = [], [], [], [], [] |
459 removed, deleted, clean = [], [], [] | 454 removed, deleted, clean = [], [], [] |
460 | 455 |
461 for src, fn, st in self.statwalk(files, match, ignored=list_ignored): | 456 for src, fn, st in self.statwalk(files, match, ignored=list_ignored): |
462 try: | 457 try: |
463 type_, mode, size, time = self[fn] | 458 type_, mode, size, time = self._map[fn] |
464 except KeyError: | 459 except KeyError: |
465 if list_ignored and self._ignore(fn): | 460 if list_ignored and self._ignore(fn): |
466 ignored.append(fn) | 461 ignored.append(fn) |
467 else: | 462 else: |
468 unknown.append(fn) | 463 unknown.append(fn) |