diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -209,25 +209,28 @@ class bundlerepository(localrepo.localre # dict with the mapping 'filename' -> position in the bundle self.bundlefilespos = {} - def __getattr__(self, name): - if name == 'changelog': - self.changelog = bundlechangelog(self.sopener, self.bundlefile) - self.manstart = self.bundlefile.tell() - return self.changelog - elif name == 'manifest': - self.bundlefile.seek(self.manstart) - self.manifest = bundlemanifest(self.sopener, self.bundlefile, - self.changelog.rev) - self.filestart = self.bundlefile.tell() - return self.manifest - elif name == 'manstart': - self.changelog - return self.manstart - elif name == 'filestart': - self.manifest - return self.filestart - else: - return localrepo.localrepository.__getattr__(self, name) + @util.propertycache + def changelog(self): + c = bundlechangelog(self.sopener, self.bundlefile) + self.manstart = self.bundlefile.tell() + return c + + @util.propertycache + def manifest(self): + self.bundlefile.seek(self.manstart) + m = bundlemanifest(self.sopener, self.bundlefile, self.changelog.rev) + self.filestart = self.bundlefile.tell() + return m + + @util.propertycache + def manstart(self): + self.changelog + return self.manstart + + @util.propertycache + def filestart(self): + self.manifest + return self.filestart def url(self): return self._url diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -15,6 +15,7 @@ import match as match_ import merge as merge_ from lock import release +propertycache = util.propertycache class localrepository(repo.repository): capabilities = set(('lookup', 'changegroupsubset')) @@ -88,24 +89,23 @@ class localrepository(repo.repository): self._datafilters = {} self._transref = self._lockref = self._wlockref = None - def __getattr__(self, name): - if name == 'changelog': - self.changelog = changelog.changelog(self.sopener) - if 'HG_PENDING' in os.environ: - p = os.environ['HG_PENDING'] - if p.startswith(self.root): - self.changelog.readpending('00changelog.i.a') - self.sopener.defversion = self.changelog.version - return self.changelog - if name == 'manifest': - self.changelog - self.manifest = manifest.manifest(self.sopener) - return self.manifest - if name == 'dirstate': - self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root) - return self.dirstate - else: - raise AttributeError(name) + @propertycache + def changelog(self): + c = changelog.changelog(self.sopener) + if 'HG_PENDING' in os.environ: + p = os.environ['HG_PENDING'] + if p.startswith(self.root): + c.readpending('00changelog.i.a') + self.sopener.defversion = c.version + return c + + @propertycache + def manifest(self): + return manifest.manifest(self.sopener) + + @propertycache + def dirstate(self): + return dirstate.dirstate(self.opener, self.ui, self.root) def __getitem__(self, changeid): if changeid == None: