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.
--- 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