Commits

Yuya Nishihara committed 419e5a3

rough implementation of agent

Comments (0)

Files changed (8)

cmdui-injectcore.diff

+# HG changeset patch
+# Parent c9be8ca5dff88e116d0da0c38a7f51ffd68480b0
+
+diff --git a/tortoisehg/hgqt/cmdui.py b/tortoisehg/hgqt/cmdui.py
+--- a/tortoisehg/hgqt/cmdui.py
++++ b/tortoisehg/hgqt/cmdui.py
+@@ -428,11 +428,7 @@ class Widget(QWidget):
+         super(Widget, self).__init__(parent)
+ 
+         self.core = Core(logWindow, self)
+-        self.core.commandStarted.connect(self.commandStarted)
+-        self.core.commandFinished.connect(self.onCommandFinished)
+-        self.core.commandCanceling.connect(self.commandCanceling)
+-        self.core.output.connect(self.output)
+-        self.core.progress.connect(self.progress)
++        self._connectCore()
+         if not logWindow:
+             return
+ 
+@@ -454,6 +450,19 @@ class Widget(QWidget):
+ 
+     ### Public Methods ###
+ 
++    def setCore(self, core):
++        if self.core.parent() is self:
++            self.core.setParent(None)  # will be deleted
++        self.core = core
++        self._connectCore()
++
++    def _connectCore(self):
++        self.core.commandStarted.connect(self.commandStarted)
++        self.core.commandFinished.connect(self.onCommandFinished)
++        self.core.commandCanceling.connect(self.commandCanceling)
++        self.core.output.connect(self.output)
++        self.core.progress.connect(self.progress)
++
+     def run(self, cmdline, *args, **opts):
+         self.core.run(cmdline, *args, **opts)
+ 

ra-ownbyagent.diff

 # HG changeset patch
-# Parent 52b89ef6073c47ce44ab89d8b23a52f161b5f5f2
+# Parent 342fe2db95a9fa9e466d8893db93f57389d03374
 
 diff --git a/tortoisehg/hgqt/sync.py b/tortoisehg/hgqt/sync.py
 --- a/tortoisehg/hgqt/sync.py
              return
          if self.locked():
              dbgoutput('locked, aborting')
-@@ -260,6 +260,7 @@ class RepoWatcher(QObject):
-             pass
- 
- class RepoAgent(QObject):
-+    """Proxy access to repository and keep its states up-to-date"""
- 
-     configChanged = pyqtSignal()
-     repositoryChanged = pyqtSignal()
-@@ -269,7 +270,10 @@ class RepoAgent(QObject):
+@@ -270,7 +270,11 @@ class RepoAgent(QObject):
  
      def __init__(self, repo):
          QObject.__init__(self)
 +        self._repo = repo
          self.busycount = 0
-+        # TODO: remove repo-to-agent references later
++        # TODO: remove repo-to-agent references later; all widgets should own
++        # RepoAgent instead of thgrepository.
 +        repo._pyqtobj = self
          repo.configChanged = self.configChanged
          repo.repositoryChanged = self.repositoryChanged
          repo.repositoryDestroyed = self.repositoryDestroyed
-@@ -283,6 +287,9 @@ class RepoAgent(QObject):
+@@ -286,6 +290,9 @@ class RepoAgent(QObject):
          watcher.workingDirectoryChanged.connect(self.workingDirectoryChanged)
          watcher.workingBranchChanged.connect(self.workingBranchChanged)
  
 +        return self._repo
 +
      def pollStatus(self):
+         """Force checking changes to emit corresponding signals"""
          self._watcher.pollStatus()
- 
 # HG changeset patch
-# Parent 351ac5784f81e0b576315b054613ac810e883a6b
+# Parent b74d25d84e143a7d578764f07068b998172476c5
+
 diff --git a/tortoisehg/hgqt/thgrepo.py b/tortoisehg/hgqt/thgrepo.py
 --- a/tortoisehg/hgqt/thgrepo.py
 +++ b/tortoisehg/hgqt/thgrepo.py
              _repocache[path] = repo
              return repo
          except EnvironmentError:
-@@ -259,7 +259,7 @@ class RepoWatcher(QObject):
+@@ -259,7 +259,8 @@ class RepoWatcher(QObject):
          except (EnvironmentError, ValueError):
              pass
  
 -class ThgRepoWrapper(QObject):
 +class RepoAgent(QObject):
++    """Proxy access to repository and keep its states up-to-date"""
  
      configChanged = pyqtSignal()
      repositoryChanged = pyqtSignal()
+# HG changeset patch
+# Parent c3e18df0a4335981e1eac89ea47a714e2241ed1d
+
+diff --git a/tortoisehg/hgqt/thgrepo.py b/tortoisehg/hgqt/thgrepo.py
+--- a/tortoisehg/hgqt/thgrepo.py
++++ b/tortoisehg/hgqt/thgrepo.py
+@@ -21,6 +21,7 @@ from mercurial import merge, subrepo
+ from mercurial import ui as uimod
+ from mercurial.util import propertycache
+ 
++from tortoisehg.hgqt import cmdui
+ from tortoisehg.util import hglib, paths
+ from tortoisehg.util.patchctx import patchctx
+ 
+@@ -95,6 +96,11 @@ class RepoWatcher(QObject):
+             self.watcher.fileChanged.connect(self._pollChanges)
+             self.addMissingPaths()
+ 
++    def blockPolling(self, block):
++        # not sure which is better removing paths from watcher or blocking
++        # signals
++        self.watcher.blockSignals(block)
++
+     @pyqtSlot()
+     def _pollChanges(self):
+         '''Catch writes or deletions of files, or writes to .hg/ folder,
+@@ -293,6 +299,27 @@ class RepoAgent(QObject):
+     def rawRepository(self):
+         return self._repo
+ 
++    def newCommandRunner(self):
++        """Create session to execute Mercurial commands asynchronously"""
++        # TODO: instead of using cmdui.Core, RepoAgent should have a single
++        # command queue to serialize requests:
++        # runner.run(cmdline) -> agent.queue(cmdline, runner)
++        # -> queue.pop() -> connectSignals(agent, runner) -> agent.run(cmdline)
++        # TODO: this will supersede increment/decrementBusyCount() later.
++        runner = cmdui.Core(logWindow=False, parent=None)
++        runner.commandStarted.connect(self._disablePolling)
++        runner.commandFinished.connect(self._enablePolling)
++        return runner
++
++    @pyqtSlot()
++    def _disablePolling(self):
++        self._watcher.blockPolling(True)
++
++    @pyqtSlot()
++    def _enablePolling(self):
++        self._watcher.blockPolling(False)
++        self.pollStatus()
++
+     def pollStatus(self):
+         """Force checking changes to emit corresponding signals"""
+         self._watcher.pollStatus()

ra-splitwatcher.diff

 # HG changeset patch
-# Parent e7c74cc3189f7134a3e91980da7350f7bb5d5416
+# Parent 9a8ef22fbf5ec4008e45e817c1212d1e883962f2
 
 diff --git a/tortoisehg/hgqt/thgrepo.py b/tortoisehg/hgqt/thgrepo.py
 --- a/tortoisehg/hgqt/thgrepo.py
 +++ b/tortoisehg/hgqt/thgrepo.py
-@@ -68,7 +68,8 @@ def repository(_ui=None, path='', create
+@@ -68,7 +68,8 @@ def repository(_ui=None, path='', bundle
  class _LockStillHeld(Exception):
      'Raised to abort status check due to lock existence'
  
          self.recordState()
  
          monitorrepo = repo.ui.config('tortoisehg', 'monitorrepo', 'always')
-@@ -264,6 +259,33 @@ class ThgRepoWrapper(QObject):
+@@ -264,6 +259,36 @@ class ThgRepoWrapper(QObject):
          except (EnvironmentError, ValueError):
              pass
  
 +        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.workingBranchChanged.connect(self.workingBranchChanged)
 +
 +    def pollStatus(self):
++        """Force checking changes to emit corresponding signals"""
 +        self._watcher.pollStatus()
 +
  _uiprops = '''_uifiles _uimtime postpull tabwidth maxdiff

repow-change-trace.diff

+# HG changeset patch
+# Parent 0b384ef745e4d2111e010b8c816aabb07e87f8cd
+diff --git a/tortoisehg/hgqt/repowidget.py b/tortoisehg/hgqt/repowidget.py
+--- a/tortoisehg/hgqt/repowidget.py
++++ b/tortoisehg/hgqt/repowidget.py
+@@ -1086,6 +1086,7 @@ class RepoWidget(QWidget):
+     @pyqtSlot()
+     def repositoryChanged(self):
+         'Repository has detected a changelog / dirstate change'
++        print 'repository changed'
+         if self.isVisible():
+             try:
+                 self.rebuildGraph()
 ra-splitwatcher.diff
 ra-rename.diff
 ra-ownbyagent.diff
+ra-runner.diff
+cmdui-injectcore.diff
+repow-change-trace.diff
+sync-usera.diff
 caprevlog.diff
 curbra.diff
 wbtime.diff
+# HG changeset patch
+# Parent 499121063f29319f903e9906074deddd6103bdae
+
+diff --git a/tortoisehg/hgqt/sync.py b/tortoisehg/hgqt/sync.py
+--- a/tortoisehg/hgqt/sync.py
++++ b/tortoisehg/hgqt/sync.py
+@@ -244,6 +244,10 @@ class SyncWidget(QWidget, qtlib.TaskWidg
+         cmd.setVisible(False)
+         self.cmd = cmd
+ 
++        agent = repo._pyqtobj  # TODO: should own agent instead of repo
++        cmdrunner = agent.newCommandRunner()  # TODO: replace self.cmd
++        cmd.setCore(cmdrunner)
++
+         self.reload()
+         if 'default' in self.paths:
+             self.curalias = 'default'
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.