Commits

Yuya Nishihara committed 9c88ccf

thgrepo: start/stop filesystem monitor by open state of repo (fixes #1783)

With this change, QFileSystemWatcher will release OS handles when repo tab is
closed. So the repository can be deleted or ejected.

  • Participants
  • Parent commits 065c0b1

Comments (0)

Files changed (2)

File tests/nosehgenv.py

             # https://bitbucket.org/tortoisehg/thg/issue/1783/
             from tortoisehg.hgqt import thgrepo
             for e in thgrepo._repocache.itervalues():
-                w = e._pyqtobj._watcher
-                w.stopMonitoring()
+                repoagent = e._pyqtobj
+                repoagent.stopMonitoring()
 
             shutil.rmtree(self.tmpdir)

File tortoisehg/hgqt/thgrepo.py

         if not os.path.exists(self.repo.path):
             dbgoutput('Repository destroyed', self.repo.root)
             self.repositoryDestroyed.emit()
-            self.stopMonitoring()
             if self.repo.root in _repocache:
                 del _repocache[self.repo.root]
             return
         watcher.repositoryDestroyed.connect(self.repositoryDestroyed)
         watcher.workingDirectoryChanged.connect(self.workingDirectoryChanged)
         watcher.workingBranchChanged.connect(self.workingBranchChanged)
-        self.startMonitoringIfEnabled()
 
     def startMonitoringIfEnabled(self):
         """Start filesystem monitoring on repository open by RepoManager or
         else:
             self._watcher.startMonitoring()
 
+    def stopMonitoring(self):
+        """Stop filesystem monitoring on repository closed by RepoManager or
+        command about to run"""
+        self._watcher.stopMonitoring()
+
     def rawRepo(self):
         return self._repo
 
         agent.setParent(self)
         for sig, slot in self._mappedSignals(agent):
             sig.connect(slot)
+        agent.startMonitoringIfEnabled()
 
         assert agent.rootPath() == path
         self._openagents[path] = (agent, 1)
 
         self._ui.debug('closing repo: %s\n' % hglib.fromunicode(path))
         agent, _refcount = self._openagents.pop(path)
-        # TODO: stop filesystem monitoring
+        agent.stopMonitoring()
         for sig, slot in self._mappedSignals(agent):
             sig.disconnect(slot)
         agent.setParent(None)
     #@pyqtSlot()
     def _mapRepositoryDestroyed(self):
         agent = self.sender()
-        # TODO: stop filesystem monitoring
+        agent.stopMonitoring()  # avoid further changed/destroyed signals
         self.repositoryDestroyed.emit(agent.rootPath())