eric6/Plugins/VcsPlugins/vcsPySvn/subversion.py

changeset 7774
9eed155411f0
parent 7759
51aa6c6b66f7
child 7775
4a1db75550bd
--- a/eric6/Plugins/VcsPlugins/vcsPySvn/subversion.py	Sat Oct 10 15:17:29 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsPySvn/subversion.py	Sat Oct 10 16:03:53 2020 +0200
@@ -14,13 +14,15 @@
 from urllib.parse import quote
 
 from PyQt5.QtCore import (
-    Qt, QMutexLocker, pyqtSignal, QRegExp, QDateTime, QCoreApplication
+    pyqtSignal, Qt, QRegExp, QDateTime, QCoreApplication
 )
 from PyQt5.QtWidgets import QLineEdit, QDialog, QInputDialog, QApplication
 
 from E5Gui.E5Application import e5App
 from E5Gui import E5MessageBox
 
+from E5Utilities.E5MutexLocker import E5MutexLocker
+
 from VCS.VersionControl import VersionControl
 
 import pysvn
@@ -301,7 +303,6 @@
                 shutil.rmtree(tmpDir, True)
             return False, False
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(os.path.join(tmpDir, project))
         opts = self.options['global']
@@ -316,14 +317,14 @@
                 client)
             QApplication.processEvents()
         try:
-            rev = client.import_(".", url, msg, recurse, ignore=True)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                rev = client.import_(".", url, msg, recurse, ignore=True)
             status = True
         except pysvn.ClientError as e:
             status = False
             rev = None
             if not noDialog:
                 dlg.showError(e.args[0])
-        locker.unlock()
         if not noDialog:
             rev and dlg.showMessage(self.tr("Imported revision {0}.\n")
                                     .format(rev.number))
@@ -391,15 +392,14 @@
                     url, projectDir),
                 client)
             QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            client.checkout(url, projectDir, recurse)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.checkout(url, projectDir, recurse)
             status = True
         except pysvn.ClientError as e:
             status = False
             if not noDialog:
                 dlg.showError(e.args[0])
-        locker.unlock()
         if not noDialog:
             dlg.finish()
             dlg.exec()
@@ -457,14 +457,13 @@
                 url, projectDir),
             client)
         QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            client.export(url, projectDir, force=True, recurse=recurse)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.export(url, projectDir, force=True, recurse=recurse)
             status = True
         except pysvn.ClientError as e:
             status = False
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         return status
@@ -567,7 +566,6 @@
         ):
             noDialog = False
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         opts = self.options['global'] + self.options['commit']
@@ -587,19 +585,19 @@
                 client)
             QApplication.processEvents()
         try:
-            if changelists:
-                rev = client.checkin(fnames, msg,
-                                     recurse=recurse, keep_locks=keeplocks,
-                                     keep_changelist=keepChangelists,
-                                     changelists=changelists)
-            else:
-                rev = client.checkin(fnames, msg,
-                                     recurse=recurse, keep_locks=keeplocks)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                if changelists:
+                    rev = client.checkin(fnames, msg,
+                                         recurse=recurse, keep_locks=keeplocks,
+                                         keep_changelist=keepChangelists,
+                                         changelists=changelists)
+                else:
+                    rev = client.checkin(fnames, msg,
+                                         recurse=recurse, keep_locks=keeplocks)
         except pysvn.ClientError as e:
             rev = None
             if not noDialog:
                 dlg.showError(e.args[0])
-        locker.unlock()
         if not noDialog:
             rev and dlg.showMessage(self.tr("Committed revision {0}.")
                                     .format(rev.number))
@@ -626,7 +624,6 @@
             dname, fname = self.splitPath(name)
             fnames = [fname]
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         opts = self.options['global'] + self.options['update']
@@ -641,10 +638,10 @@
                 client)
         QApplication.processEvents()
         try:
-            client.update(fnames, recurse)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.update(fnames, recurse)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         if not noDialog:
             dlg.finish()
             dlg.exec()
@@ -735,7 +732,6 @@
         else:
             names.append(name)
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(wdir)
         opts = self.options['global'] + self.options['add']
@@ -754,12 +750,12 @@
                 client)
             QApplication.processEvents()
         try:
-            client.add(names, recurse=recurse, force=force,
-                       ignore=not noignore)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.add(names, recurse=recurse, force=force,
+                           ignore=not noignore)
         except pysvn.ClientError as e:
             if not noDialog:
                 dlg.showError(e.args[0])
-        locker.unlock()
         if not noDialog:
             dlg.finish()
             dlg.exec()
@@ -846,7 +842,6 @@
         else:
             names.append(path)
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         opts = self.options['global'] + self.options['add']
@@ -863,10 +858,10 @@
             client)
         QApplication.processEvents()
         try:
-            client.add(names, recurse=recurse, force=force, ignore=ignore)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.add(names, recurse=recurse, force=force, ignore=ignore)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         os.chdir(cwd)
@@ -899,15 +894,14 @@
                     " ".join(name)),
                 client)
             QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            client.remove(name, force=force)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.remove(name, force=force)
             res = True
         except pysvn.ClientError as e:
             res = False
             if not noDialog:
                 dlg.showError(e.args[0])
-        locker.unlock()
         if not noDialog:
             dlg.finish()
             dlg.exec()
@@ -964,15 +958,14 @@
                         name, target),
                     client, log=log)
                 QApplication.processEvents()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                client.move(name, target, force=force)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    client.move(name, target, force=force)
                 res = True
             except pysvn.ClientError as e:
                 res = False
                 if not noDialog:
                     dlg.showError(e.args[0])
-            locker.unlock()
             if not noDialog:
                 dlg.finish()
                 dlg.exec()
@@ -1104,12 +1097,11 @@
                 "copy --message {0} {1} {2}".format(log, reposURL, url),
                 client, log=log)
             QApplication.processEvents()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                rev = client.copy(reposURL, url)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    rev = client.copy(reposURL, url)
             except pysvn.ClientError as e:
                 dlg.showError(e.args[0])
-            locker.unlock()
         else:
             log = 'Deleted tag <{0}>'.format(self.tagName)
             dlg = SvnDialog(
@@ -1118,12 +1110,11 @@
                 "remove --message {0} {1}".format(log, url),
                 client, log=log)
             QApplication.processEvents()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                rev = client.remove(url)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    rev = client.remove(url)
             except pysvn.ClientError as e:
                 dlg.showError(e.args[0])
-            locker.unlock()
         rev and dlg.showMessage(
             self.tr("Revision {0}.\n").format(rev.number))
         dlg.finish()
@@ -1170,12 +1161,11 @@
                     " ".join(name)),
                 client)
             QApplication.processEvents()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                client.revert(name, recurse)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    client.revert(name, recurse)
             except pysvn.ClientError as e:
                 dlg.showError(e.args[0])
-            locker.unlock()
             dlg.finish()
             dlg.exec()
             self.checkVCSStatus()
@@ -1246,13 +1236,12 @@
                         "switch {0} {1}".format(url, name),
                         client)
         QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            rev = client.switch(name, url)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                rev = client.switch(name, url)
             dlg.showMessage(self.tr("Revision {0}.\n").format(rev.number))
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         res = dlg.hasAddOrDelete()
@@ -1286,7 +1275,6 @@
         
         rx_rev = QRegExp('\\d+|HEAD|head')
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         recurse = "--non-recursive" not in opts
@@ -1355,11 +1343,11 @@
             client)
         QApplication.processEvents()
         try:
-            client.merge(url1, revision1, url2, revision2, fname,
-                         recurse=recurse, force=force)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.merge(url1, revision1, url2, revision2, fname,
+                             recurse=recurse, force=force)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         os.chdir(cwd)
@@ -1496,10 +1484,9 @@
             )
             
             try:
-                locker = QMutexLocker(self.vcsExecutionMutex)
-                allFiles = client.status(dname, recurse=True, get_all=True,
-                                         ignore=True, update=False)
-                locker.unlock()
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    allFiles = client.status(dname, recurse=True, get_all=True,
+                                             ignore=True, update=False)
                 dirs = [x for x in names.keys() if os.path.isdir(x)]
                 for file in allFiles:
                     name = os.path.normcase(file.path)
@@ -1530,7 +1517,8 @@
                     else:
                         self.statusCache[name] = self.canBeAdded
             except pysvn.ClientError:
-                locker.unlock()    # ignore pysvn errors
+                # ignore pysvn errors
+                pass
         
         return names
         
@@ -1576,10 +1564,9 @@
             )
             
             try:
-                locker = QMutexLocker(self.vcsExecutionMutex)
-                allFiles = client.status(dname, recurse=True, get_all=True,
-                                         ignore=True, update=False)
-                locker.unlock()
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    allFiles = client.status(dname, recurse=True, get_all=True,
+                                             ignore=True, update=False)
                 for file in allFiles:
                     name = os.path.normcase(file.path)
                     if self.__isVersioned(file):
@@ -1589,7 +1576,8 @@
                     else:
                         self.statusCache[name] = self.canBeAdded
             except pysvn.ClientError:
-                locker.unlock()    # ignore pysvn errors
+                # ignore pysvn errors
+                pass
         
         return names
         
@@ -1652,12 +1640,11 @@
                         "cleanup {0}".format(name),
                         client)
         QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            client.cleanup(name)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.cleanup(name)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
     
@@ -1779,13 +1766,12 @@
         @return string with the repository path URL
         """
         client = pysvn.Client()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            entry = client.info(path)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                entry = client.info(path)
             url = entry.url
         except pysvn.ClientError:
             url = ""
-        locker.unlock()
         return url
 
     def svnResolve(self, name):
@@ -1800,7 +1786,6 @@
             dname, fname = self.splitPath(name)
             fnames = [fname]
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         opts = self.options['global']
@@ -1813,11 +1798,11 @@
                         client)
         QApplication.processEvents()
         try:
-            for name in fnames:
-                client.resolved(name, recurse=recurse)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                for name in fnames:
+                    client.resolved(name, recurse=recurse)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         os.chdir(cwd)
@@ -1852,14 +1837,13 @@
                     name, target),
                 client, log=log)
             QApplication.processEvents()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                client.copy(name, target)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    client.copy(name, target)
                 res = True
             except pysvn.ClientError as e:
                 res = False
                 dlg.showError(e.args[0])
-            locker.unlock()
             dlg.finish()
             dlg.exec()
             if (
@@ -1913,7 +1897,6 @@
                 dname, fname = self.splitPath(name)
                 fnames = [fname]
             
-            locker = QMutexLocker(self.vcsExecutionMutex)
             cwd = os.getcwd()
             os.chdir(dname)
             opts = self.options['global']
@@ -1929,12 +1912,12 @@
                 client)
             QApplication.processEvents()
             try:
-                for name in fnames:
-                    client.propset(propName, propValue, name,
-                                   recurse=recurse, skip_checks=skipchecks)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    for name in fnames:
+                        client.propset(propName, propValue, name,
+                                       recurse=recurse, skip_checks=skipchecks)
             except pysvn.ClientError as e:
                 dlg.showError(e.args[0])
-            locker.unlock()
             dlg.showMessage(self.tr("Property set."))
             dlg.finish()
             dlg.exec()
@@ -1966,7 +1949,6 @@
                 dname, fname = self.splitPath(name)
                 fnames = [fname]
             
-            locker = QMutexLocker(self.vcsExecutionMutex)
             cwd = os.getcwd()
             os.chdir(dname)
             opts = self.options['global']
@@ -1981,12 +1963,12 @@
                 client)
             QApplication.processEvents()
             try:
-                for name in fnames:
-                    client.propdel(propName, name,
-                                   recurse=recurse, skip_checks=skipchecks)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    for name in fnames:
+                        client.propdel(propName, name,
+                                       recurse=recurse, skip_checks=skipchecks)
             except pysvn.ClientError as e:
                 dlg.showError(e.args[0])
-            locker.unlock()
             dlg.showMessage(self.tr("Property deleted."))
             dlg.finish()
             dlg.exec()
@@ -2274,7 +2256,6 @@
             dname, fname = self.splitPath(name)
             fnames = [fname]
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         client = self.getClient()
@@ -2287,12 +2268,12 @@
             client, parent=parent)
         QApplication.processEvents()
         try:
-            client.lock(fnames, comment, force=stealIt)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.lock(fnames, comment, force=stealIt)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
         except AttributeError as e:
             dlg.showError(str(e))
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         os.chdir(cwd)
@@ -2313,7 +2294,6 @@
             dname, fname = self.splitPath(name)
             fnames = [fname]
         
-        locker = QMutexLocker(self.vcsExecutionMutex)
         cwd = os.getcwd()
         os.chdir(dname)
         client = self.getClient()
@@ -2324,12 +2304,12 @@
             client, parent=parent)
         QApplication.processEvents()
         try:
-            client.unlock(fnames, force=breakIt)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.unlock(fnames, force=breakIt)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
         except AttributeError as e:
             dlg.showError(str(e))
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         os.chdir(cwd)
@@ -2365,15 +2345,15 @@
             client = self.getClient()
             dlg = SvnDialog(self.tr('Relocating'), msg, client)
             QApplication.processEvents()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                if inside:
-                    client.switch(projectPath, newUrl)
-                else:
-                    client.relocate(currUrl, newUrl, projectPath, recurse=True)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    if inside:
+                        client.switch(projectPath, newUrl)
+                    else:
+                        client.relocate(currUrl, newUrl, projectPath,
+                                        recurse=True)
             except pysvn.ClientError as e:
                 dlg.showError(e.args[0])
-            locker.unlock()
             dlg.finish()
             dlg.exec()
         
@@ -2421,13 +2401,12 @@
             "changelist --remove {0}".format(" ".join(names)),
             client)
         QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            for name in names:
-                client.remove_from_changelists(name)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                for name in names:
+                    client.remove_from_changelists(name)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
         
@@ -2458,14 +2437,13 @@
             "changelist {0}".format(" ".join(names)),
             client)
         QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            for name in names:
-                client.add_to_changelist(name, clname,
-                                         depth=pysvn.depth.infinity)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                for name in names:
+                    client.add_to_changelist(
+                        name, clname, depth=pysvn.depth.infinity)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
     
@@ -2491,17 +2469,16 @@
         client = self.getClient()
         if hasattr(client, 'get_changelist'):
             ppath = e5App().getObject("Project").getProjectPath()
-            locker = QMutexLocker(self.vcsExecutionMutex)
             try:
-                entries = client.get_changelist(ppath,
-                                                depth=pysvn.depth.infinity)
+                with E5MutexLocker(self.vcsExecutionMutex):
+                    entries = client.get_changelist(
+                        ppath, depth=pysvn.depth.infinity)
                 for entry in entries:
                     changelist = entry[1]
                     if changelist not in changelists:
                         changelists.append(changelist)
             except pysvn.ClientError:
                 pass
-            locker.unlock()
         
         return changelists
         
@@ -2517,12 +2494,11 @@
             "upgrade {0}".format(path),
             client)
         QApplication.processEvents()
-        locker = QMutexLocker(self.vcsExecutionMutex)
         try:
-            client.upgrade(path)
+            with E5MutexLocker(self.vcsExecutionMutex):
+                client.upgrade(path)
         except pysvn.ClientError as e:
             dlg.showError(e.args[0])
-        locker.unlock()
         dlg.finish()
         dlg.exec()
 

eric ide

mercurial