# HG changeset patch # User Durham Goode # Date 1367430123 25200 # Node ID 921b64e1f7b900cc58ffcc9b3fae4457bcb4d72b # Parent 3bda242bf244e59ae1c3616b5f2d6f3a47cc8561 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 -r 3bda242bf244 -r 921b64e1f7b9 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