Commits

Yuya Nishihara committed e18d09e

add extension to test polling issue on Windows

Comments (0)

Files changed (1)

hgext/thgrepodamper.py

+# thgrepodamper.py - insert slight delay before checking repository change
+
+import sys
+from mercurial import extensions, util
+
+DELAY = 100  # [msec]
+
+def extsetup(ui):
+    if 'tortoisehg.hgqt.run' not in sys.modules:
+        return  # not a TortoiseHg
+
+    from PyQt4.QtCore import QTimer
+    from tortoisehg.hgqt import thgrepo
+
+    def injectdamper(target, signalname, slotname):
+        signal = getattr(target.watcher, signalname)
+        slot = getattr(target, slotname)
+        signal.disconnect(slot)
+        damper = QTimer(target, singleShot=True, interval=DELAY)
+        signal.connect(damper.start)
+        damper.timeout.connect(lambda: slot(''))  # '': dummy file/directory
+
+    def repository(orig, ui=None, path='', create=False, bundle=None):
+        newrepo = create or path in thgrepo._repocache
+        repo = orig(ui, path, create, bundle)
+        if newrepo and util.safehasattr(repo._pyqtobj, 'watcher'):
+            injectdamper(repo._pyqtobj, 'directoryChanged', 'onDirChange')
+            injectdamper(repo._pyqtobj, 'fileChanged', 'onFileChange')
+            # disable pollStatus() by busy count, which may have side effect
+            repo.incrementBusyCount = lambda: None
+            repo.decrementBusyCount = repo.thginvalidate
+        return repo
+
+    extensions.wrapfunction(thgrepo, 'repository', repository)