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

login
register
mail settings
Submitter Durham Goode
Date May 6, 2013, 7:36 p.m.
Message ID <08caf62362c7a41064d5.1367869015@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1561/
State Accepted, archived
Commit 921b64e1f7b900cc58ffcc9b3fae4457bcb4d72b
Headers show

Comments

Durham Goode - May 6, 2013, 7:36 p.m.
# HG changeset patch
# User Durham Goode <durham@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.
Matt Mackall - May 6, 2013, 8:10 p.m.
On Mon, 2013-05-06 at 12:36 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@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

I've queued 4 and 5 for default, thanks.

Patch

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