Mercurial > hg
comparison mercurial/dirstate.py @ 9518:bc19a0b04e83
dirstate: add/improve method docstrings.
- add doc to __init__(), _map(), status()
- enhance for __getitem__()
- fix inaccurate doc for walk() (described wrong return type)
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Thu, 01 Oct 2009 15:36:45 -0400 |
parents | e4ca8c258d9b |
children | d78fe60f6bda |
comparison
equal
deleted
inserted
replaced
9517:4368f582c806 | 9518:bc19a0b04e83 |
---|---|
36 del dirs[base] | 36 del dirs[base] |
37 | 37 |
38 class dirstate(object): | 38 class dirstate(object): |
39 | 39 |
40 def __init__(self, opener, ui, root): | 40 def __init__(self, opener, ui, root): |
41 '''Create a new dirstate object. opener is an open()-like callable | |
42 that can be used to open the dirstate file; root is the root of the | |
43 directory tracked by the dirstate.''' | |
41 self._opener = opener | 44 self._opener = opener |
42 self._root = root | 45 self._root = root |
43 self._rootdir = os.path.join(root, '') | 46 self._rootdir = os.path.join(root, '') |
44 self._dirty = False | 47 self._dirty = False |
45 self._dirtypl = False | 48 self._dirtypl = False |
46 self._ui = ui | 49 self._ui = ui |
47 | 50 |
48 @propertycache | 51 @propertycache |
49 def _map(self): | 52 def _map(self): |
53 '''Return the dirstate contents as a map from filename to | |
54 (state, mode, size, time).''' | |
50 self._read() | 55 self._read() |
51 return self._map | 56 return self._map |
52 | 57 |
53 @propertycache | 58 @propertycache |
54 def _copymap(self): | 59 def _copymap(self): |
167 if self._slash: | 172 if self._slash: |
168 return util.normpath(path) | 173 return util.normpath(path) |
169 return path | 174 return path |
170 | 175 |
171 def __getitem__(self, key): | 176 def __getitem__(self, key): |
172 ''' current states: | 177 '''Return the current state of key (a filename) in the dirstate. |
173 n normal | 178 States are: |
174 m needs merging | 179 n normal |
175 r marked for removal | 180 m needs merging |
176 a marked for addition | 181 r marked for removal |
177 ? not tracked''' | 182 a marked for addition |
183 ? not tracked | |
184 ''' | |
178 return self._map.get(key, ("?",))[0] | 185 return self._map.get(key, ("?",))[0] |
179 | 186 |
180 def __contains__(self, key): | 187 def __contains__(self, key): |
181 return key in self._map | 188 return key in self._map |
182 | 189 |
415 return True | 422 return True |
416 return False | 423 return False |
417 | 424 |
418 def walk(self, match, unknown, ignored): | 425 def walk(self, match, unknown, ignored): |
419 ''' | 426 ''' |
420 walk recursively through the directory tree, finding all files | 427 Walk recursively through the directory tree, finding all files |
421 matched by the match function | 428 matched by match. |
422 | 429 |
423 results are yielded in a tuple (filename, stat), where stat | 430 Return a dict mapping filename to stat-like object (either |
424 and st is the stat result if the file was found in the directory. | 431 mercurial.osutil.stat instance or return value of os.stat()). |
425 ''' | 432 ''' |
426 | 433 |
427 def fwarn(f, msg): | 434 def fwarn(f, msg): |
428 self._ui.warn('%s: %s\n' % (self.pathto(f), msg)) | 435 self._ui.warn('%s: %s\n' % (self.pathto(f), msg)) |
429 return False | 436 return False |
557 | 564 |
558 del results['.hg'] | 565 del results['.hg'] |
559 return results | 566 return results |
560 | 567 |
561 def status(self, match, ignored, clean, unknown): | 568 def status(self, match, ignored, clean, unknown): |
569 '''Determine the status of the working copy relative to the | |
570 dirstate and return a tuple of lists (unsure, modified, added, | |
571 removed, deleted, unknown, ignored, clean), where: | |
572 | |
573 unsure: | |
574 files that might have been modified since the dirstate was | |
575 written, but need to be read to be sure (size is the same | |
576 but mtime differs) | |
577 modified: | |
578 files that have definitely been modified since the dirstate | |
579 was written (different size or mode) | |
580 added: | |
581 files that have been explicitly added with hg add | |
582 removed: | |
583 files that have been explicitly removed with hg remove | |
584 deleted: | |
585 files that have been deleted through other means ("missing") | |
586 unknown: | |
587 files not in the dirstate that are not ignored | |
588 ignored: | |
589 files not in the dirstate that are ignored | |
590 (by _dirignore()) | |
591 clean: | |
592 files that have definitely not been modified since the | |
593 dirstate was written | |
594 ''' | |
562 listignored, listclean, listunknown = ignored, clean, unknown | 595 listignored, listclean, listunknown = ignored, clean, unknown |
563 lookup, modified, added, unknown, ignored = [], [], [], [], [] | 596 lookup, modified, added, unknown, ignored = [], [], [], [], [] |
564 removed, deleted, clean = [], [], [] | 597 removed, deleted, clean = [], [], [] |
565 | 598 |
566 dmap = self._map | 599 dmap = self._map |
567 ladd = lookup.append | 600 ladd = lookup.append # aka "unsure" |
568 madd = modified.append | 601 madd = modified.append |
569 aadd = added.append | 602 aadd = added.append |
570 uadd = unknown.append | 603 uadd = unknown.append |
571 iadd = ignored.append | 604 iadd = ignored.append |
572 radd = removed.append | 605 radd = removed.append |