changeset 8260:54a4b520bd7d

localrepo: use propertycache
author Matt Mackall <mpm@selenic.com>
date Wed, 29 Apr 2009 20:47:15 -0500
parents 98acfd1d2b08
children 0fe1f57ac2bd
files mercurial/bundlerepo.py mercurial/localrepo.py
diffstat 2 files changed, 40 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundlerepo.py	Thu Apr 30 10:15:32 2009 -0500
+++ b/mercurial/bundlerepo.py	Wed Apr 29 20:47:15 2009 -0500
@@ -209,25 +209,28 @@
         # 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
--- a/mercurial/localrepo.py	Thu Apr 30 10:15:32 2009 -0500
+++ b/mercurial/localrepo.py	Wed Apr 29 20:47:15 2009 -0500
@@ -15,6 +15,7 @@
 import merge as merge_
 
 from lock import release
+propertycache = util.propertycache
 
 class localrepository(repo.repository):
     capabilities = set(('lookup', 'changegroupsubset'))
@@ -88,24 +89,23 @@
         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: