Mercurial > hg
changeset 4604:c867c11426ad
dirstate: lazify copymap, _branch, and _pl
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 18 Jun 2007 13:24:33 -0500 |
parents | 0f6853c15606 |
children | 9da7a4da650f |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 21 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/dirstate.py Mon Jun 18 13:24:33 2007 -0500 +++ b/mercurial/dirstate.py Mon Jun 18 13:24:33 2007 -0500 @@ -20,18 +20,33 @@ self.root = root self.dirty = 0 self.ui = ui - self.fp = None - self.pl = None self.dirs = None - self.copymap = {} self.ignorefunc = None - self._branch = None self._slash = None def __getattr__(self, name): if name == 'map': self.read() return self.map + elif name == 'copymap': + self.read() + return self.copymap + elif name == '_branch': + try: + self._branch = self.opener("branch").read().strip()\ + or "default" + except IOError: + self._branch = "default" + return self._branch + elif name == 'pl': + self.pl = [nullid, nullid] + try: + st = self.opener("dirstate").read(40) + if len(st) == 40: + self.pl = st[:20], st[20:40] + except IOError, err: + if err.errno != errno.ENOENT: raise + return self.pl else: raise AttributeError, name @@ -162,24 +177,9 @@ return key in self.map def parents(self): - if self.pl is None: - self.pl = [nullid, nullid] - try: - self.fp = self.opener('dirstate') - st = self.fp.read(40) - if len(st) == 40: - self.pl = st[:20], st[20:40] - except IOError, err: - if err.errno != errno.ENOENT: raise return self.pl def branch(self): - if not self._branch: - try: - self._branch = self.opener("branch").read().strip()\ - or "default" - except IOError: - self._branch = "default" return self._branch def markdirty(self): @@ -227,14 +227,10 @@ def read(self): self.map = {} + self.copymap = {} self.pl = [nullid, nullid] try: - if self.fp: - self.fp.seek(0) - st = self.fp.read() - self.fp = None - else: - st = self.opener("dirstate").read() + st = self.opener("dirstate").read() if st: self.parse(st) except IOError, err: