context: check self.__dict__ instead of using hasattr
authorBrendan Cully <brendan@kublai.com>
Wed, 11 Oct 2006 13:34:12 -0700
changeset 3334 e44eadc92ec4
parent 3333 9061613c1593
child 3335 b02e60097bbe
context: check self.__dict__ instead of using hasattr hasattr implicitly calls getattr, instantiating the field it is checking for.
mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -72,7 +72,7 @@ class changectx(object):
         return [ changectx(self._repo, x) for x in c ]
 
     def filenode(self, path):
-        if hasattr(self, "_manifest"):
+        if '_manifest' in self.__dict__:
             try:
                 return self._manifest[path]
             except KeyError:
@@ -140,7 +140,7 @@ class filectx(object):
             return self._changeid
         elif name == '_filenode':
             try:
-                if hasattr(self, "_fileid"):
+                if '_fileid' in self.__dict__:
                     self._filenode = self._filelog.lookup(self._fileid)
                 else:
                     self._filenode = self._changectx.filenode(self._path)
@@ -176,7 +176,7 @@ class filectx(object):
     def filelog(self): return self._filelog
 
     def rev(self):
-        if hasattr(self, "_changectx"):
+        if '_changectx' in self.__dict__:
             return self._changectx.rev()
         return self._filelog.linkrev(self._filenode)
 
@@ -439,7 +439,7 @@ class workingfilectx(filectx):
                        filelog=self._filelog)
 
     def rev(self):
-        if hasattr(self, "_changectx"):
+        if '_changectx' in self.__dict__:
             return self._changectx.rev()
         return self._filelog.linkrev(self._filenode)