Commits

Yuya Nishihara committed 5388a79

thgrepo: split filesystem monitor from ThgRepoWrapper

This prepares for the redesign of ThgRepoWrapper.

Comments (0)

Files changed (2)

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 = e._pyqtobj._watcher.watcher
                 w.removePaths(w.directories())
                 w.removePaths(w.files())
 

tortoisehg/hgqt/thgrepo.py

 class _LockStillHeld(Exception):
     'Raised to abort status check due to lock existence'
 
-class ThgRepoWrapper(QObject):
+class RepoWatcher(QObject):
+    """Notify changes of repository by optionally monitoring filesystem"""
 
     configChanged = pyqtSignal()
     repositoryChanged = pyqtSignal()
     workingDirectoryChanged = pyqtSignal()
     workingBranchChanged = pyqtSignal()
 
-    def __init__(self, repo):
-        QObject.__init__(self)
+    def __init__(self, repo, parent=None):
+        super(RepoWatcher, self).__init__(parent)
         self.repo = repo
-        self.busycount = 0
-        repo.configChanged = self.configChanged
-        repo.repositoryChanged = self.repositoryChanged
-        repo.repositoryDestroyed = self.repositoryDestroyed
-        repo.workingDirectoryChanged = self.workingDirectoryChanged
-        repo.workingBranchChanged = self.workingBranchChanged
         self.recordState()
         self._uimtime = time.time()
 
         except (EnvironmentError, ValueError):
             pass
 
+
+class ThgRepoWrapper(QObject):
+
+    configChanged = pyqtSignal()
+    repositoryChanged = pyqtSignal()
+    repositoryDestroyed = pyqtSignal()
+    workingDirectoryChanged = pyqtSignal()
+    workingBranchChanged = pyqtSignal()
+
+    def __init__(self, repo):
+        QObject.__init__(self)
+        self.busycount = 0
+        repo.configChanged = self.configChanged
+        repo.repositoryChanged = self.repositoryChanged
+        repo.repositoryDestroyed = self.repositoryDestroyed
+        repo.workingDirectoryChanged = self.workingDirectoryChanged
+        repo.workingBranchChanged = self.workingBranchChanged
+
+        # TODO: make RepoWatcher not depends on repo internals too much;
+        # i.e. move repo.invalidate(), etc. to this class.
+        self._watcher = watcher = RepoWatcher(repo, self)
+        watcher.configChanged.connect(self.configChanged)
+        watcher.repositoryChanged.connect(self.repositoryChanged)
+        watcher.repositoryDestroyed.connect(self.repositoryDestroyed)
+        watcher.workingDirectoryChanged.connect(self.workingDirectoryChanged)
+        watcher.workingBranchChanged.connect(self.workingBranchChanged)
+
+    def pollStatus(self):
+        """Force checking changes to emit corresponding signals"""
+        self._watcher.pollStatus()
+
+
 _uiprops = '''_uifiles postpull tabwidth maxdiff
               deadbranches _exts _thghiddentags displayname summarylen
               shortname mergetools namedbranches'''.split()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.