Commits

Yuya Nishihara committed b486b65

repowatcher: port dirstate and branch changes to table-based detector

This also fixes missing workingBranchChanged notification when dirstate is
not modified.

  • Participants
  • Parent commits 8eb328f

Comments (0)

Files changed (2)

tests/qt_repoagent_test.py

                           | 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
-                          | thgrepo.WorkingStateChanged)
+        self.agent.runCommand(['branch', 'foo'])
+        self.wait_changed(thgrepo.WorkingBranchChanged)
 
     def test_branch_and_parent_changed(self):
         self.agent.runCommandSequence([['update', '0'],

tortoisehg/hgqt/thgrepo.py

             self._ui.debug('change found (flags = 0x%x)\n' % changeflags)
             self.repositoryChanged.emit(changeflags)  # may update repo paths
             self._fixState()
-            return
+            if changeflags == WorkingStateChanged:
+                # no return because in this case it's still necessary to check
+                # repo mtime in order to emit repositoryChanged appropriately
+                pass
+            else:
+                return
         try:
-            if self._checkdirstate():
-                self._ui.debug('dirstate changed, exiting\n')
-                return
             self._checkrepotime()
             self._checkuimtime()
         except _LockStillHeld:
 
     def recordState(self):
         try:
-            self._parentnodes = self._getrawparents()
             self._repomtime = self._getrepomtime()
-            self._dirstatemtime = os.path.getmtime(self.repo.join('dirstate'))
-            self._branchmtime = os.path.getmtime(self.repo.join('branch'))
-            self._rawbranch = self.repo.opener('branch').read()
         except EnvironmentError:
-            self._dirstatemtime = None
-            self._branchmtime = None
-            self._rawbranch = None
+            pass
 
     def _fixState(self):
         """Update paths to be checked and record state of new paths"""
+        repo = self.repo
         newfilesmap = {
+            repo.join('branch'): (0, False),
+            repo.join('dirstate'): (WorkingStateChanged, False),
             }
         newpaths = set(newfilesmap) - set(self._filesmap)
         if not newpaths:
             return
         self._filesmap = newfilesmap
         self._datamap = {
+            RepoWatcher._readbranch: (WorkingBranchChanged,
+                                      repo.join('branch')),
+            RepoWatcher._readparents: (WorkingParentChanged,
+                                       repo.join('dirstate')),
             }
         newmtimes, newdata = self._readState(newpaths)
         self._lastmtimes.update(newmtimes)
         return [path for path, (_flag, watched) in self._filesmap.iteritems()
                 if watched]
 
-    def _getrawparents(self):
-        try:
-            return self.repo.opener('dirstate').read(40)
-        except EnvironmentError:
-            return None
+    def _readparents(self):
+        return self.repo.opener('dirstate').read(40)
 
     def _getwatchedfiles(self):
         'Repository files which may be modified without locking'
             self.recordState()
             self.repositoryChanged.emit(LogChanged)
 
-    def _checkdirstate(self):
-        'Check for new dirstate mtime, then working parent changes'
-        try:
-            mtime = os.path.getmtime(self.repo.join('dirstate'))
-        except EnvironmentError:
-            return False
-        if mtime <= self._dirstatemtime:
-            return False
-        changed = self._checkparentchanges() or self._checkbranch()
-        if not changed:
-            # 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.repositoryChanged.emit(WorkingStateChanged)
-        self._dirstatemtime = mtime
-        return changed
-
-    def _checkparentchanges(self):
-        nodes = self._getrawparents()
-        if nodes != self._parentnodes:
-            self._ui.debug('dirstate change found\n')
-            if self.locked():
-                raise _LockStillHeld
-            self.recordState()
-            self.repositoryChanged.emit(WorkingParentChanged
-                                        | WorkingStateChanged)
-            return True
-        return False
-
-    def _checkbranch(self):
-        try:
-            mtime = os.path.getmtime(self.repo.join('branch'))
-        except EnvironmentError:
-            return False
-        if mtime <= self._branchmtime:
-            return False
-        changed = self._checkbranchcontent()
-        self._branchmtime = mtime
-        return changed
-
-    def _checkbranchcontent(self):
-        try:
-            newbranch = self.repo.opener('branch').read()
-        except EnvironmentError:
-            return False
-        if newbranch != self._rawbranch:
-            self._ui.debug('branch time change\n')
-            if self.locked():
-                raise _LockStillHeld
-            self._rawbranch = newbranch
-            self.repositoryChanged.emit(WorkingBranchChanged
-                                        | WorkingStateChanged)
-            return True
-        return False
+    def _readbranch(self):
+        return self.repo.opener('branch').read()
 
     def _checkuimtime(self):
         'Check for modified config files, or a new .hg/hgrc file'