changeset 13754:ae157ca56cd5

dirstate: check mtime when adding to _lastnormal - consistently use mtime as mapped to dirstate granularity (needed for filesystems like NTFS, which have sub-second resolution) - no need to add files with mtime < _lastnormaltime - improve comments
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 24 Mar 2011 18:39:54 +0100
parents 78a0a815fd41
children e45780ac8292
files mercurial/dirstate.py
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Thu Mar 24 18:17:49 2011 +0100
+++ b/mercurial/dirstate.py	Thu Mar 24 18:39:54 2011 +0100
@@ -285,18 +285,28 @@
         self._dirty = True
         self._addpath(f)
         s = os.lstat(self._join(f))
-        self._map[f] = ('n', s.st_mode, s.st_size, int(s.st_mtime))
+        mtime = int(s.st_mtime)
+        self._map[f] = ('n', s.st_mode, s.st_size, mtime)
         if f in self._copymap:
             del self._copymap[f]
 
-        # Right now, this file is clean: but if some code in this
-        # process modifies it without changing its size before the clock
-        # ticks over to the next second, then it won't be clean anymore.
-        # So make sure that status() will look harder at it.
-        if self._lastnormaltime < s.st_mtime:
-            self._lastnormaltime = s.st_mtime
-            self._lastnormal = set()
-        self._lastnormal.add(f)
+        if mtime < self._lastnormaltime:
+            # We have already seen files with modification times from newer
+            # filesystem timeslots, so this timeslot is old and harmless.
+            # Comparing file times will work just fine for detecting modified
+            # files in status(). No special treatment is needed for f.
+            pass
+        else:
+            # f was modified most recently.
+            if mtime > self._lastnormaltime:
+                # A new timeslot, which we've never seen before.
+                # We can drop the filenames of an older timeslot.
+                self._lastnormaltime = mtime
+                self._lastnormal = set()
+            # Remember f in _lastnormal for closer inspection on status(),
+            # to make sure we won't miss future size-preserving file content
+            # modifications that happen within the same timeslot.
+            self._lastnormal.add(f)
 
     def normallookup(self, f):
         '''Mark a file normal, but possibly dirty.'''