Commits

Yuya Nishihara committed d22b9a3

repowatcher: unify internal signals of change notification

RepoAgent still provides repositoryChanged and workingBranchChanged separately,
but they will be merged into repositoryChanged(flags).

  • Participants
  • Parent commits 9892f74

Comments (0)

Files changed (2)

File tests/qt_repoagent_test.py

 
     def test_filesystem_watcher(self):
         self.hg.update('0')
-        self.wait_changed(thgrepo.WorkingParentChanged)
+        self.wait_changed(thgrepo.WorkingParentChanged
+                          | thgrepo.WorkingStateChanged)
 
     def test_poll_on_command_finished(self):
         self.agent.runCommandSequence([['update', '0'], ['root']])
-        self.wait_changed(thgrepo.WorkingParentChanged)
+        self.wait_changed(thgrepo.WorkingParentChanged
+                          | thgrepo.WorkingStateChanged)
 
     def test_branch_changed(self):
         # TODO: it should be notified without dirstate change, "udpate -C"
         self.agent.runCommandSequence([['update', '-C'],
                                        ['branch', 'foo']])
-        self.wait_changed(thgrepo.WorkingBranchChanged)
+        self.wait_changed(thgrepo.WorkingBranchChanged
+                          | thgrepo.WorkingStateChanged)
 
     def test_branch_and_parent_changed(self):
         self.agent.runCommandSequence([['update', '0'],
                                        ['branch', 'foo']])
         # TODO: WorkingBranchChanged should be included
-        self.wait_changed(thgrepo.WorkingParentChanged)
+        self.wait_changed(thgrepo.WorkingParentChanged
+                          | thgrepo.WorkingStateChanged)
 
     def test_listen_to_new_queue_changes(self):
         self.agent.runCommand(['qqueue', '-c', 'foo'])

File tortoisehg/hgqt/thgrepo.py

 LogChanged = 0x1
 WorkingParentChanged = 0x2
 WorkingBranchChanged = 0x4
+WorkingStateChanged = 0x8  # internal flag to invalidate dirstate cache
 
 
 class _LockStillHeld(Exception):
     """Notify changes of repository by optionally monitoring filesystem"""
 
     configChanged = pyqtSignal()
-    repositoryChanged = pyqtSignal()
+    repositoryChanged = pyqtSignal(int)
     repositoryDestroyed = pyqtSignal()
-    workingBranchChanged = pyqtSignal()
-    workingStateChanged = pyqtSignal()
-
-    # Maybe repositoryChanged, workingBranchChanged and workingStateChanged
-    # should be merged into repositoryChanged(flags), so that client widgets
-    # and models can tune their reloader.
-    # For example, flags=WorkingParent will redraw graph but not for other
-    # columns, flags=WorkingState will trigger refreshWctx, etc.
 
     def __init__(self, repo, parent=None):
         super(RepoWatcher, self).__init__(parent)
             if self.locked():
                 raise _LockStillHeld
             self.recordState()
-            self.repositoryChanged.emit()
+            self.repositoryChanged.emit(LogChanged)
 
     def _checkdirstate(self):
         'Check for new dirstate mtime, then working parent changes'
             # returns False because in this case it's still necessary to check
             # repo mtime in order to emit repositoryChanged appropriately
             self._ui.debug('working directory status may be changed\n')
-            self.workingStateChanged.emit()
+            self.repositoryChanged.emit(WorkingStateChanged)
         self._dirstatemtime = mtime
         return changed
 
             if self.locked():
                 raise _LockStillHeld
             self.recordState()
-            self.repositoryChanged.emit()
+            self.repositoryChanged.emit(WorkingParentChanged
+                                        | WorkingStateChanged)
             return True
         return False
 
             if self.locked():
                 raise _LockStillHeld
             self._rawbranch = newbranch
-            self.workingBranchChanged.emit()
+            self.repositoryChanged.emit(WorkingBranchChanged
+                                        | WorkingStateChanged)
             return True
         return False
 
         watcher.configChanged.connect(self._onConfigChanged)
         watcher.repositoryChanged.connect(self._onRepositoryChanged)
         watcher.repositoryDestroyed.connect(self._onRepositoryDestroyed)
-        watcher.workingBranchChanged.connect(self._onWorkingBranchChanged)
-        watcher.workingStateChanged.connect(self._onWorkingStateChanged)
 
         self._cmdagent = cmdagent = cmdcore.CmdAgent(repo.ui, self,
                                                      cwd=self.rootPath())
         self._cmdagent.stopService()  # to reload config
         self.configChanged.emit()
 
-    @pyqtSlot()
-    def _onRepositoryChanged(self):
+    @pyqtSlot(int)
+    def _onRepositoryChanged(self, flags):
         self._repo.thginvalidate()
-        self._emitRepositoryChanged()
+        # mimic precedence in watcher.pollStatus()
+        if flags & WorkingParentChanged:
+            self._emitRepositoryChanged()
+        elif flags & WorkingBranchChanged:
+            self.workingBranchChanged.emit()
+        elif flags & LogChanged:
+            self._emitRepositoryChanged()
 
     @pyqtSlot()
     def _onRepositoryDestroyed(self):
         self._watcher.stopMonitoring()
         self.repositoryDestroyed.emit()
 
-    @pyqtSlot()
-    def _onWorkingBranchChanged(self):
-        self._repo.thginvalidate()
-        self.workingBranchChanged.emit()
-
-    @pyqtSlot()
-    def _onWorkingStateChanged(self):
-        self._repo.thginvalidate()
-
     def isBusy(self):
         return self._cmdagent.isBusy()