context.status: move manifest caching trick to _buildstatus()
authorMartin von Zweigbergk <martinvonz@gmail.com>
Sun, 12 Oct 2014 00:00:13 -0700
changeset 23238 39eb9f78f968
parent 23237 98f41a2f8fba
child 23239 9fbb50444d55
context.status: move manifest caching trick to _buildstatus() In basectx._buildstatus(), we read the manifests for the two revisions being compared. For "caching reasons" unknown to me, it is better to read the earlier manifest first, which basectx._prestatus() takes care of. However, if the 'self' context is a committablectx and the 'other' context is the parent of the working directory (as in the very common case of plain "hg status"), there is no need to read any manifests at all -- all that's needed is the dirstate status. To avoid reading the manifests, _prestatus() is overridden in committablectx and avoids calling its super method, and _buildstatus() calls its super method only if the 'other' context is not the parent of the working directory. It seems easier to follow what's happening if we move the pre-fetching to _buildstatus() just before the place where the manifests are fetched. We just need to add an extra check that the revision is not None to handle the case that was previously handled by subclass overriding. That also makes it safe for committablectx._prestatus() to call its parent, although the latter now becomes empty, so we won't bother.
mercurial/context.py
--- a/mercurial/context.py	Sat Oct 11 23:18:53 2014 -0700
+++ b/mercurial/context.py	Sun Oct 12 00:00:13 2014 -0700
@@ -99,9 +99,6 @@
         For example, this allows other contexts, such as workingctx, to query
         the dirstate before comparing the manifests.
         """
-        # load earliest manifest first for caching reasons
-        if self.rev() < other.rev():
-            self.manifest()
         return s
 
     def _poststatus(self, other, s, match, listignored, listclean, listunknown):
@@ -115,6 +112,9 @@
     def _buildstatus(self, other, s, match, listignored, listclean,
                      listunknown):
         """build a status with respect to another context"""
+        # load earliest manifest first for caching reasons
+        if self.rev() is not None and self.rev() < other.rev():
+            self.manifest()
         mf1 = other._manifestmatches(match, s)
         mf2 = self._manifestmatches(match, s)
 
@@ -1416,9 +1416,7 @@
         We use this _prestatus hook to populate the status with information from
         the dirstate.
         """
-        # doesn't need to call super; if that changes, be aware that super
-        # calls self.manifest which would slow down the common case of calling
-        # status against a workingctx's parent
+        # doesn't need to call super
         return self._dirstatestatus(match, listignored, listclean, listunknown)
 
     def _poststatus(self, other, s, match, listignored, listclean, listunknown):