Commits

Yuya Nishihara  committed 5a8b460

better repo handling

  • Participants
  • Parent commits a884247

Comments (0)

Files changed (5)

File ra-ownbyagent.diff

+# HG changeset patch
+# Parent 52b89ef6073c47ce44ab89d8b23a52f161b5f5f2
+
+diff --git a/tortoisehg/hgqt/sync.py b/tortoisehg/hgqt/sync.py
+--- a/tortoisehg/hgqt/sync.py
++++ b/tortoisehg/hgqt/sync.py
+@@ -341,9 +341,9 @@ class SyncWidget(QWidget, qtlib.TaskWidg
+             if abs not in known:
+                 related[root] = shortname
+                 known.add(abs)
+-            if root in thgrepo._repocache:
++            if root in thgrepo._agentcache:
+                 # repositories already opened keep their ui instances in sync
+-                repo = thgrepo._repocache[root]
++                repo = thgrepo._agentcache[root].bareRepo()
+                 ui = repo.ui
+             elif paths.is_on_fixed_drive(root):
+                 # directly read the repository's configuration file
+diff --git a/tortoisehg/hgqt/thgrepo.py b/tortoisehg/hgqt/thgrepo.py
+--- a/tortoisehg/hgqt/thgrepo.py
++++ b/tortoisehg/hgqt/thgrepo.py
+@@ -24,7 +24,7 @@ from mercurial.util import propertycache
+ from tortoisehg.util import hglib, paths
+ from tortoisehg.util.patchctx import patchctx
+ 
+-_repocache = {}
++_agentcache = {}
+ _kbfregex = re.compile(r'^\.kbf/')
+ _lfregex = re.compile(r'^\.hglf/')
+ 
+@@ -44,9 +44,9 @@ def repository(_ui=None, path='', bundle
+             _ui = uimod.ui()
+         repo = bundlerepo.bundlerepository(_ui, path, bundle)
+         repo.__class__ = _extendrepo(repo)
+-        repo._pyqtobj = RepoAgent(repo)
+-        return repo
+-    if path not in _repocache:
++        agent = RepoAgent(repo)
++        return agent.bareRepo()
++    if path not in _agentcache:
+         if _ui is None:
+             _ui = uimod.ui()
+         try:
+@@ -54,16 +54,16 @@ def repository(_ui=None, path='', bundle
+             # get unfiltered repo in version safe manner
+             repo = getattr(repo, 'unfiltered', lambda: repo)()
+             repo.__class__ = _extendrepo(repo)
+-            repo._pyqtobj = RepoAgent(repo)
+-            _repocache[path] = repo
+-            return repo
++            agent = RepoAgent(repo)
++            _agentcache[path] = agent
++            return agent.bareRepo()
+         except EnvironmentError:
+             raise error.RepoError('Cannot open repository at %s' % path)
+     if not os.path.exists(os.path.join(path, '.hg/')):
+-        del _repocache[path]
++        del _agentcache[path]
+         # this error must be in local encoding
+         raise error.RepoError('%s is not a valid repository' % path)
+-    return _repocache[path]
++    return _agentcache[path].bareRepo()
+ 
+ class _LockStillHeld(Exception):
+     'Raised to abort status check due to lock existence'
+@@ -126,8 +126,8 @@ class RepoWatcher(QObject):
+             files = self.watcher.files()
+             if files:
+                 self.watcher.removePaths(files)
+-            if self.repo.root in _repocache:
+-                del _repocache[self.repo.root]
++            if self.repo.root in _agentcache:
++                del _agentcache[self.repo.root]
+             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):
+ 
+     def __init__(self, repo):
+         QObject.__init__(self)
++        self._repo = repo
+         self.busycount = 0
++        # TODO: remove repo-to-agent references later
++        repo._pyqtobj = self
+         repo.configChanged = self.configChanged
+         repo.repositoryChanged = self.repositoryChanged
+         repo.repositoryDestroyed = self.repositoryDestroyed
+@@ -283,6 +287,9 @@ class RepoAgent(QObject):
+         watcher.workingDirectoryChanged.connect(self.workingDirectoryChanged)
+         watcher.workingBranchChanged.connect(self.workingBranchChanged)
+ 
++    def bareRepo(self):
++        return self._repo
++
+     def pollStatus(self):
+         self._watcher.pollStatus()
+ 

File ra-rename.diff

+# HG changeset patch
+# Parent 351ac5784f81e0b576315b054613ac810e883a6b
+diff --git a/tortoisehg/hgqt/thgrepo.py b/tortoisehg/hgqt/thgrepo.py
+--- a/tortoisehg/hgqt/thgrepo.py
++++ b/tortoisehg/hgqt/thgrepo.py
+@@ -44,7 +44,7 @@ def repository(_ui=None, path='', bundle
+             _ui = uimod.ui()
+         repo = bundlerepo.bundlerepository(_ui, path, bundle)
+         repo.__class__ = _extendrepo(repo)
+-        repo._pyqtobj = ThgRepoWrapper(repo)
++        repo._pyqtobj = RepoAgent(repo)
+         return repo
+     if path not in _repocache:
+         if _ui is None:
+@@ -54,7 +54,7 @@ def repository(_ui=None, path='', bundle
+             # get unfiltered repo in version safe manner
+             repo = getattr(repo, 'unfiltered', lambda: repo)()
+             repo.__class__ = _extendrepo(repo)
+-            repo._pyqtobj = ThgRepoWrapper(repo)
++            repo._pyqtobj = RepoAgent(repo)
+             _repocache[path] = repo
+             return repo
+         except EnvironmentError:
+@@ -259,7 +259,7 @@ class RepoWatcher(QObject):
+         except (EnvironmentError, ValueError):
+             pass
+ 
+-class ThgRepoWrapper(QObject):
++class RepoAgent(QObject):
+ 
+     configChanged = pyqtSignal()
+     repositoryChanged = pyqtSignal()

File ra-splitwatcher.diff

+# HG changeset patch
+# Parent e7c74cc3189f7134a3e91980da7350f7bb5d5416
+
+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
+ 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()
+@@ -76,15 +77,9 @@ class ThgRepoWrapper(QObject):
+     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()
+ 
+         monitorrepo = repo.ui.config('tortoisehg', 'monitorrepo', 'always')
+@@ -264,6 +259,33 @@ class ThgRepoWrapper(QObject):
+         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
++
++        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):
++        self._watcher.pollStatus()
++
+ _uiprops = '''_uifiles _uimtime postpull tabwidth maxdiff
+               deadbranches _exts _thghiddentags displayname summarylen
+               shortname mergetools namedbranches'''.split()
+ra-splitwatcher.diff
+thgrepo-nocreate.diff
+ra-rename.diff
+ra-ownbyagent.diff
 refst-move.diff
 refst-logic-simple.diff
 linkify-nocapture.diff

File thgrepo-nocreate.diff

+# HG changeset patch
+# Parent 505f5e87e10632bbb0c41dc281d2ade7297f9f6d
+diff --git a/tortoisehg/hgqt/thgrepo.py b/tortoisehg/hgqt/thgrepo.py
+--- a/tortoisehg/hgqt/thgrepo.py
++++ b/tortoisehg/hgqt/thgrepo.py
+@@ -35,7 +35,7 @@ else:
+     def dbgoutput(*args):
+         pass
+ 
+-def repository(_ui=None, path='', create=False, bundle=None):
++def repository(_ui=None, path='', bundle=None):
+     '''Returns a subclassed Mercurial repository to which new
+     THG-specific methods have been added. The repository object
+     is obtained using mercurial.hg.repository()'''
+@@ -46,11 +46,11 @@ def repository(_ui=None, path='', create
+         repo.__class__ = _extendrepo(repo)
+         repo._pyqtobj = ThgRepoWrapper(repo)
+         return repo
+-    if create or path not in _repocache:
++    if path not in _repocache:
+         if _ui is None:
+             _ui = uimod.ui()
+         try:
+-            repo = hg.repository(_ui, path, create)
++            repo = hg.repository(_ui, path)
+             # get unfiltered repo in version safe manner
+             repo = getattr(repo, 'unfiltered', lambda: repo)()
+             repo.__class__ = _extendrepo(repo)