# HG changeset patch # User Matt Mackall # Date 1182191073 18000 # Node ID 9da7a4da650ff857da53d1e0233365f4421cf96c # Parent c867c11426ad3ea766d9411ecabaa362b4b4bd52 dirstate: lazify initdirs diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -20,7 +20,6 @@ class dirstate(object): self.root = root self.dirty = 0 self.ui = ui - self.dirs = None self.ignorefunc = None self._slash = None @@ -47,6 +46,11 @@ class dirstate(object): except IOError, err: if err.errno != errno.ENOENT: raise return self.pl + elif name == 'dirs': + self.dirs = {} + for f in self.map: + self.updatedirs(f, 1) + return self.dirs else: raise AttributeError, name @@ -256,24 +260,16 @@ class dirstate(object): def copies(self): return self.copymap - def initdirs(self): - if self.dirs is None: - self.dirs = {} - for f in self.map: - self.updatedirs(f, 1) - def updatedirs(self, path, delta): - if self.dirs is not None: - for c in strutil.findall(path, '/'): - pc = path[:c] - self.dirs.setdefault(pc, 0) - self.dirs[pc] += delta + for c in strutil.findall(path, '/'): + pc = path[:c] + self.dirs.setdefault(pc, 0) + self.dirs[pc] += delta def checkinterfering(self, files): def prefixes(f): for c in strutil.rfindall(f, '/'): yield f[:c] - self.initdirs() seendirs = {} for f in files: # shadows @@ -301,7 +297,6 @@ class dirstate(object): if not files: return self.markdirty() if state == "a": - self.initdirs() self.checkinterfering(files) for f in files: if state == "r": @@ -320,7 +315,6 @@ class dirstate(object): def forget(self, files): if not files: return self.markdirty() - self.initdirs() for f in files: try: del self.map[f]