inotify: do not rely on stat(.hg/dirstate) to invalidate our dirstate
authorNicolas Dumazet <nicdumz.commits@gmail.com>
Fri, 11 Dec 2009 15:58:09 +0900
changeset 10090 a3ad96ead8f0
parent 10089 8fab31727037
child 10091 0ce645cc3f20
inotify: do not rely on stat(.hg/dirstate) to invalidate our dirstate stat() is not reliable when several events happen quickly. Which means that if two hg actions occur in the same second, stat() result will not reflect the second change. And only _one_ invalidate() call was done. Also ignore the events that occur when wlock is held, since wlock release will trigger a full rescan anyway. Fixes 17 run-tests.py --inotify tests.
hgext/inotify/linuxserver.py
hgext/inotify/server.py
--- a/hgext/inotify/linuxserver.py	Fri Nov 27 09:23:10 2009 +0900
+++ b/hgext/inotify/linuxserver.py	Fri Dec 11 15:58:09 2009 +0900
@@ -170,6 +170,7 @@
         server.repowatcher.__init__(self, ui, dirstate, root)
 
         self.lastevent = {}
+        self.dirty = False
         try:
             self.watcher = watcher.watcher()
         except OSError, err:
@@ -214,7 +215,6 @@
     def setup(self):
         self.ui.note(_('watching directories under %r\n') % self.wprefix)
         self.add_watch(self.wprefix + '.hg', inotify.IN_DELETE)
-        self.check_dirstate()
 
     def scan(self, topdir=''):
         ds = self.dirstate._map.copy()
@@ -272,8 +272,6 @@
         if wpath == '.hgignore':
             self.update_hgignore()
         elif wpath.startswith('.hg/'):
-            if wpath == '.hg/wlock':
-                self.check_dirstate()
             return
 
         self.deletefile(wpath, self.dirstate[wpath])
@@ -343,16 +341,26 @@
             if wpath.startswith('.hg/') and evt.mask & inotify.IN_ISDIR:
                 # ignore subdirectories of .hg/ (merge, patches...)
                 continue
+            if wpath == ".hg/wlock":
+                if evt.mask & inotify.IN_DELETE:
+                    self.dirstate.invalidate()
+                    self.dirty = False
+                    self.scan()
+                elif evt.mask & inotify.IN_CREATE:
+                    self.dirty = True
+            else:
+                if self.dirty:
+                    continue
 
-            if evt.mask & inotify.IN_UNMOUNT:
-                self.process_unmount(wpath, evt)
-            elif evt.mask & (inotify.IN_MODIFY | inotify.IN_ATTRIB):
-                self.process_modify(wpath, evt)
-            elif evt.mask & (inotify.IN_DELETE | inotify.IN_DELETE_SELF |
-                             inotify.IN_MOVED_FROM):
-                self.process_delete(wpath, evt)
-            elif evt.mask & (inotify.IN_CREATE | inotify.IN_MOVED_TO):
-                self.process_create(wpath, evt)
+                if evt.mask & inotify.IN_UNMOUNT:
+                    self.process_unmount(wpath, evt)
+                elif evt.mask & (inotify.IN_MODIFY | inotify.IN_ATTRIB):
+                    self.process_modify(wpath, evt)
+                elif evt.mask & (inotify.IN_DELETE | inotify.IN_DELETE_SELF |
+                                 inotify.IN_MOVED_FROM):
+                    self.process_delete(wpath, evt)
+                elif evt.mask & (inotify.IN_CREATE | inotify.IN_MOVED_TO):
+                    self.process_create(wpath, evt)
 
         self.lastevent.clear()
 
--- a/hgext/inotify/server.py	Fri Nov 27 09:23:10 2009 +0900
+++ b/hgext/inotify/server.py	Fri Dec 11 15:58:09 2009 +0900
@@ -281,17 +281,6 @@
             del self.statustrees[key].dir(root).files[fn]
             del self.tree.dir(root).files[fn]
 
-    def check_dirstate(self):
-        ds_info = self.dirstate_info()
-        if ds_info == self.ds_info:
-            return
-        self.ds_info = ds_info
-        if not self.ui.debugflag:
-            self.last_event = None
-        self.dirstate.invalidate()
-        self.handle_timeout()
-        self.scan()
-
     def update_hgignore(self):
         # An update of the ignore file can potentially change the
         # states of all unknown and ignored files.