[PATCH 3 of 7] context.status: move manifest caching trick to _buildstatus()

Martin von Zweigbergk martinvonz at google.com
Sun Nov 2 16:13:47 CST 2014


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at gmail.com>
# Date 1413097213 25200
#      Sun Oct 12 00:00:13 2014 -0700
# Branch stable
# Node ID ada8ab4086be7814622374c04aa5ab6c94deacb2
# Parent  3776f277e512ecdc5b2da73f3f3264af3e173640
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.

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


More information about the Mercurial-devel mailing list