[PATCH 5 of 8] filecontext: use 'is not None' to check for filelog existence

Durham Goode durham at fb.com
Mon May 6 14:36:55 CDT 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1367430123 25200
#      Wed May 01 10:42:03 2013 -0700
# Node ID 08caf62362c7a41064d528ff6bf308d9a1414634
# Parent  73881f8307e167690b55cba8f9163f70ca176418
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.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -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


More information about the Mercurial-devel mailing list