[PATCH] dirstate: avoid invalidating every entries when list is empty

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Jun 5 00:19:41 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1433481032 25200
#      Thu Jun 04 22:10:32 2015 -0700
# Node ID 88a6501758d2779176b47f23a0bca33f563881d8
# Parent  51e7acc34b0ab0e540dffdb22127914f2353d5e2
dirstate: avoid invalidating every entries when list is empty

Default value was not tested with 'is None', this made empty list seen as
default value and result the invalidation of every single entry in the
dirstate. On repos with hundred of thousand of files, this results in minutes
of lookup time instead nothing.

This is a text book example of why we should test 'is None' if this is what we
mean.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -570,11 +570,12 @@ class dirstate(object):
         self._pl = [nullid, nullid]
         self._lastnormaltime = 0
         self._dirty = True
 
     def rebuild(self, parent, allfiles, changedfiles=None):
-        changedfiles = changedfiles or allfiles
+        if changedfiles is None:
+            changedfiles = allfiles
         oldmap = self._map
         self.clear()
         for f in allfiles:
             if f not in changedfiles:
                 self._map[f] = oldmap[f]


More information about the Mercurial-devel mailing list