filecontext: use 'is not None' to check for filelog existence
authorDurham Goode <durham@fb.com>
Wed, 01 May 2013 10:42:03 -0700
changeset 19149 921b64e1f7b9
parent 19148 3bda242bf244
child 19150 7a4eab2456de
filecontext: use 'is not None' to check for filelog existence Previously we used 'if filelog:' to check if the filelog existed. If the instance did exist, this pattern then calls len() on the filelog to see if it is empty. I'm developing a filelog replacement that doesn't have len() implemented, so it's better to do an explicit 'is not None' check here instead. Also change _changeid() to return the _changeid attribute if it has it. Previously it would try to obtain it from the _changectx(), and if that did not exist it would construct the _changectx() using the linkrev. In the extension I'm working on, filectx's don't have easy access to linkrevs so avoiding this when possible is better.
mercurial/context.py
--- a/mercurial/context.py	Wed May 01 10:39:37 2013 -0700
+++ b/mercurial/context.py	Wed May 01 10:42:03 2013 -0700
@@ -398,7 +398,7 @@
                 ("bad args: changeid=%r, fileid=%r, changectx=%r"
                  % (changeid, fileid, changectx))
 
-        if filelog:
+        if filelog is not None:
             self._filelog = filelog
 
         if changeid is not None:
@@ -437,7 +437,9 @@
 
     @propertycache
     def _changeid(self):
-        if '_changectx' in self.__dict__:
+        if '_changeid' in self.__dict__:
+            return self._changeid
+        elif '_changectx' in self.__dict__:
             return self._changectx.rev()
         else:
             return self._filelog.linkrev(self._filerev)
@@ -1167,7 +1169,7 @@
         self._changeid = None
         self._filerev = self._filenode = None
 
-        if filelog:
+        if filelog is not None:
             self._filelog = filelog
         if workingctx:
             self._changectx = workingctx