Mercurial interface: deleted several calls to the hg executable in favour of the Mercurial server (aka. client).

Tue, 29 Sep 2020 18:58:05 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 29 Sep 2020 18:58:05 +0200
changeset 7719
a20dce3647ee
parent 7718
43e63381d916
child 7720
2a386a2100d7

Mercurial interface: deleted several calls to the hg executable in favour of the Mercurial server (aka. client).

eric6/Plugins/VcsPlugins/vcsMercurial/HgSummaryDialog.py file | annotate | diff | comparison | revisions
eric6/Plugins/VcsPlugins/vcsMercurial/hg.py file | annotate | diff | comparison | revisions
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/HgSummaryDialog.py	Sun Sep 27 14:17:38 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/HgSummaryDialog.py	Tue Sep 29 18:58:05 2020 +0200
@@ -8,16 +8,11 @@
 directory state.
 """
 
-
 import os
 
-from PyQt5.QtCore import pyqtSlot, QProcess, QTimer
+from PyQt5.QtCore import pyqtSlot
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
 
-from E5Gui import E5MessageBox
-
-from .HgUtilities import prepareProcess
-
 from .Ui_HgSummaryDialog import Ui_HgSummaryDialog
 
 
@@ -44,28 +39,6 @@
         
         self.vcs = vcs
         self.vcs.committed.connect(self.__committed)
-        
-        self.process = QProcess()
-        prepareProcess(self.process, language="C")
-        self.process.finished.connect(self.__procFinished)
-        self.process.readyReadStandardOutput.connect(self.__readStdout)
-        self.process.readyReadStandardError.connect(self.__readStderr)
-    
-    def closeEvent(self, e):
-        """
-        Protected slot implementing a close event handler.
-        
-        @param e close event (QCloseEvent)
-        """
-        if (
-            self.process is not None and
-            self.process.state() != QProcess.NotRunning
-        ):
-            self.process.terminate()
-            QTimer.singleShot(2000, self.process.kill)
-            self.process.waitForFinished(3000)
-        
-        e.accept()
     
     def start(self, path, mq=False, largefiles=False):
         """
@@ -99,36 +72,12 @@
             if os.path.splitdrive(repodir)[1] == os.sep:
                 return
         
-        if self.process:
-            self.process.kill()
-        
-        self.process.setWorkingDirectory(repodir)
-        
-        self.__buffer = []
-        
-        self.process.start('hg', args)
-        procStarted = self.process.waitForStarted(5000)
-        if not procStarted:
-            E5MessageBox.critical(
-                self,
-                self.tr('Process Generation Error'),
-                self.tr(
-                    'The process {0} could not be started. '
-                    'Ensure, that it is in the search path.'
-                ).format('hg'))
-    
-    def __finish(self):
-        """
-        Private slot called when the process finished or the user pressed
-        the button.
-        """
-        if (
-            self.process is not None and
-            self.process.state() != QProcess.NotRunning
-        ):
-            self.process.terminate()
-            QTimer.singleShot(2000, self.process.kill)
-            self.process.waitForFinished(3000)
+        client = self.vcs.getClient()
+        output, error = client.runcommand(args)
+        if error:
+            self.__showError(error)
+        else:
+            self.__processOutput(output.splitlines())
         
         self.refreshButton.setEnabled(True)
     
@@ -143,53 +92,6 @@
         elif button == self.refreshButton:
             self.on_refreshButton_clicked()
     
-    def __procFinished(self, exitCode, exitStatus):
-        """
-        Private slot connected to the finished signal.
-        
-        @param exitCode exit code of the process (integer)
-        @param exitStatus exit status of the process (QProcess.ExitStatus)
-        """
-        self.__processOutput(self.__buffer)
-        self.__finish()
-    
-    def __readStdout(self):
-        """
-        Private slot to handle the readyReadStandardOutput signal.
-        
-        It reads the output of the process, formats it and inserts it into
-        the contents pane.
-        """
-        if self.process is not None:
-            self.process.setReadChannel(QProcess.StandardOutput)
-            
-            while self.process.canReadLine():
-                line = str(self.process.readLine(), self.vcs.getEncoding(),
-                           'replace')
-                self.__buffer.append(line)
-    
-    def __readStderr(self):
-        """
-        Private slot to handle the readyReadStandardError signal.
-        
-        It reads the error output of the process and inserts it into the
-        error pane.
-        """
-        if self.process is not None:
-            s = str(self.process.readAllStandardError(),
-                    self.vcs.getEncoding(), 'replace')
-            self.__showError(s)
-    
-    def __showError(self, out):
-        """
-        Private slot to show some error.
-        
-        @param out error to be shown (string)
-        """
-        self.errorGroup.show()
-        self.errors.insertPlainText(out)
-        self.errors.ensureCursorVisible()
-    
     @pyqtSlot()
     def on_refreshButton_clicked(self):
         """
@@ -204,6 +106,16 @@
         if self.isVisible():
             self.on_refreshButton_clicked()
     
+    def __showError(self, out):
+        """
+        Private slot to show some error.
+        
+        @param out error to be shown (string)
+        """
+        self.errorGroup.show()
+        self.errors.insertPlainText(out)
+        self.errors.ensureCursorVisible()
+    
     def __processOutput(self, output):
         """
         Private method to process the output into nice readable text.
--- a/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py	Sun Sep 27 14:17:38 2020 +0200
+++ b/eric6/Plugins/VcsPlugins/vcsMercurial/hg.py	Tue Sep 29 18:58:05 2020 +0200
@@ -11,7 +11,7 @@
 import shutil
 
 from PyQt5.QtCore import (
-    QProcess, pyqtSignal, QFileInfo, QFileSystemWatcher, QCoreApplication
+    pyqtSignal, QFileInfo, QFileSystemWatcher, QCoreApplication
 )
 from PyQt5.QtWidgets import QApplication, QDialog, QInputDialog
 
@@ -3456,19 +3456,7 @@
         args = self.initCommand("bookmarks")
         
         client = self.getClient()
-        output = ""
-        if client:
-            output = client.runcommand(args)[0]
-        else:
-            process = QProcess()
-            process.setWorkingDirectory(repodir)
-            process.start('hg', args)
-            procStarted = process.waitForStarted(5000)
-            if procStarted:
-                finished = process.waitForFinished(30000)
-                if finished and process.exitCode() == 0:
-                    output = str(process.readAllStandardOutput(),
-                                 self.getEncoding(), 'replace')
+        output = client.runcommand(args)[0]
         
         self.bookmarksList = []
         for line in output.splitlines():
@@ -3673,19 +3661,7 @@
         args.append('--bookmarks')
         
         client = self.getClient()
-        output = ""
-        if client:
-            output = client.runcommand(args)[0]
-        else:
-            process = QProcess()
-            process.setWorkingDirectory(repodir)
-            process.start('hg', args)
-            procStarted = process.waitForStarted(5000)
-            if procStarted:
-                finished = process.waitForFinished(30000)
-                if finished and process.exitCode() == 0:
-                    output = str(process.readAllStandardOutput(),
-                                 self.getEncoding(), 'replace')
+        output = client.runcommand(args)[0]
         
         for line in output.splitlines():
             if line.startswith(" "):

eric ide

mercurial