diff -r dbeeed55df08 -r 5fb53279f2df eric6/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py --- a/eric6/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py Wed Jan 08 19:13:57 2020 +0100 +++ b/eric6/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py Mon Jan 13 19:23:08 2020 +0100 @@ -7,14 +7,11 @@ Module implementing a dialog to browse the log history. """ - import os import re import collections -from PyQt5.QtCore import ( - pyqtSlot, Qt, QDate, QProcess, QTimer, QRegExp, QSize, QPoint, QFileInfo -) +from PyQt5.QtCore import pyqtSlot, Qt, QDate, QRegExp, QSize, QPoint, QFileInfo from PyQt5.QtGui import ( QCursor, QColor, QPixmap, QPainter, QPen, QBrush, QIcon, QTextCursor ) @@ -34,7 +31,6 @@ import UI.PixmapCache import Preferences import Utilities -from Globals import strToQByteArray COLORNAMES = ["blue", "darkgreen", "red", "green", "darkblue", "purple", "cyan", "olive", "magenta", "darkred", "darkmagenta", @@ -200,14 +196,6 @@ # roles used in the file tree self.__diffFileLineRole = Qt.UserRole - if self.__hgClient: - self.process = None - else: - self.process = QProcess() - self.process.finished.connect(self.__procFinished) - self.process.readyReadStandardOutput.connect(self.__readStdout) - self.process.readyReadStandardError.connect(self.__readStderr) - self.flags = { 'A': self.tr('Added'), 'D': self.tr('Deleted'), @@ -430,17 +418,8 @@ @param e close event (QCloseEvent) """ - if self.__hgClient: - if self.__hgClient.isExecuting(): - self.__hgClient.cancel() - else: - 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) + if self.__hgClient.isExecuting(): + self.__hgClient.cancel() self.vcs.getPlugin().setPreferences( "LogBrowserGeometry", self.saveGeometry()) @@ -756,31 +735,7 @@ if not self.projectMode: args.append(self.__filename) - output = "" - if self.__hgClient: - output, errMsg = self.__hgClient.runcommand(args) - else: - process = QProcess() - process.setWorkingDirectory(self.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.vcs.getEncoding(), 'replace') - else: - if not finished: - errMsg = self.tr( - "The hg process did not finish within 30s.") - else: - errMsg = self.tr("Could not start the hg executable.") - - if errMsg: - E5MessageBox.critical( - self, - self.tr("Mercurial Error"), - errMsg) + output, errMsg = self.__hgClient.runcommand(args) if output: parents = [int(p) for p in output.strip().splitlines()] @@ -796,25 +751,7 @@ args = self.vcs.initCommand("identify") args.append("-nb") - output = "" - if self.__hgClient: - output, errMsg = self.__hgClient.runcommand(args) - else: - process = QProcess() - process.setWorkingDirectory(self.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.vcs.getEncoding(), 'replace') - else: - if not finished: - errMsg = self.tr( - "The hg process did not finish within 30s.") - else: - errMsg = self.tr("Could not start the hg executable.") + output, errMsg = self.__hgClient.runcommand(args) if errMsg: E5MessageBox.critical( @@ -843,25 +780,7 @@ args = self.vcs.initCommand("branches") args.append("--closed") - output = "" - if self.__hgClient: - output, errMsg = self.__hgClient.runcommand(args) - else: - process = QProcess() - process.setWorkingDirectory(self.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.vcs.getEncoding(), 'replace') - else: - if not finished: - errMsg = self.tr( - "The hg process did not finish within 30s.") - else: - errMsg = self.tr("Could not start the hg executable.") + output, errMsg = self.__hgClient.runcommand(args) if errMsg: E5MessageBox.critical( @@ -888,25 +807,7 @@ args.append("--template") args.append("{rev}\n") - output = "" - if self.__hgClient: - output, errMsg = self.__hgClient.runcommand(args) - else: - process = QProcess() - process.setWorkingDirectory(self.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.vcs.getEncoding(), 'replace') - else: - if not finished: - errMsg = self.tr( - "The hg process did not finish within 30s.") - else: - errMsg = self.tr("Could not start the hg executable.") + output, errMsg = self.__hgClient.runcommand(args) if errMsg: E5MessageBox.critical( @@ -933,25 +834,7 @@ args = self.vcs.initCommand("tags") - output = "" - if self.__hgClient: - output, errMsg = self.__hgClient.runcommand(args) - else: - process = QProcess() - process.setWorkingDirectory(self.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.vcs.getEncoding(), 'replace') - else: - if not finished: - errMsg = self.tr( - "The hg process did not finish within 30s.") - else: - errMsg = self.tr("Could not start the hg executable.") + output, errMsg = self.__hgClient.runcommand(args) if errMsg: E5MessageBox.critical( @@ -1137,74 +1020,37 @@ if not self.projectMode: args.append(self.__filename) - if self.__hgClient: - self.inputGroup.setEnabled(False) - self.inputGroup.hide() - - if preargs: - out, err = self.__hgClient.runcommand(preargs) - else: - err = "" - if err: - if ( - self.commandMode == "incoming" and - self.initialCommandMode == "full_log" - ): - # ignore the error - self.commandMode = "log" - else: - self.__showError(err) - elif ( - self.commandMode != "incoming" or - (self.vcs.bundleFile and - os.path.exists(self.vcs.bundleFile)) or - self.__bundle - ): - out, err = self.__hgClient.runcommand(args) - self.buf = out.splitlines(True) - if err: - self.__showError(err) - self.__processBuffer() - elif ( + if preargs: + out, err = self.__hgClient.runcommand(preargs) + else: + err = "" + if err: + if ( self.commandMode == "incoming" and self.initialCommandMode == "full_log" ): - # no incoming changesets, just switch to log mode + # ignore the error self.commandMode = "log" - self.__finish() - else: - self.process.kill() - - self.process.setWorkingDirectory(self.repodir) - - if preargs: - process = QProcess() - process.setWorkingDirectory(self.repodir) - process.start('hg', args) - procStarted = process.waitForStarted(5000) - if procStarted: - process.waitForFinished(30000) - - if ( - self.commandMode != "incoming" or - (self.vcs.bundleFile and - os.path.exists(self.vcs.bundleFile)) or - self.__bundle - ): - self.process.start('hg', args) - procStarted = self.process.waitForStarted(5000) - if not procStarted: - self.inputGroup.setEnabled(False) - self.inputGroup.hide() - 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')) else: - self.__finish() + self.__showError(err) + elif ( + self.commandMode != "incoming" or + (self.vcs.bundleFile and + os.path.exists(self.vcs.bundleFile)) or + self.__bundle + ): + out, err = self.__hgClient.runcommand(args) + self.buf = out.splitlines(True) + if err: + self.__showError(err) + self.__processBuffer() + elif ( + self.commandMode == "incoming" and + self.initialCommandMode == "full_log" + ): + # no incoming changesets, just switch to log mode + self.commandMode = "log" + self.__finish() def start(self, fn, bundle=None, isFile=False, noEntries=0): """ @@ -1257,37 +1103,17 @@ self.__getHeads() self.__getLogEntries(noEntries=noEntries) - 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.__processBuffer() - self.__finish() - 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) - QApplication.restoreOverrideCursor() self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) - self.inputGroup.setEnabled(False) - self.inputGroup.hide() self.refreshButton.setEnabled(True) while self.__finishCallbacks: @@ -1496,31 +1322,6 @@ items[0].setSelected(True) self.__selectedRevisions = [] - def __readStdout(self): - """ - Private slot to handle the readyReadStandardOutput signal. - - It reads the output of the process and inserts it into a buffer. - """ - self.process.setReadChannel(QProcess.StandardOutput) - - while self.process.canReadLine(): - line = str(self.process.readLine(), self.vcs.getEncoding(), - 'replace') - self.buf.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. @@ -1530,11 +1331,6 @@ self.errorGroup.show() self.errors.insertPlainText(out) self.errors.ensureCursorVisible() - - if not self.__hgClient: - # show input in case the process asked for some input - self.inputGroup.setEnabled(True) - self.inputGroup.show() def on_buttonBox_clicked(self, button): """ @@ -1546,10 +1342,7 @@ self.close() elif button == self.buttonBox.button(QDialogButtonBox.Cancel): self.cancelled = True - if self.__hgClient: - self.__hgClient.cancel() - else: - self.__finish() + self.__hgClient.cancel() elif button == self.refreshButton: self.on_refreshButton_clicked() @@ -2158,56 +1951,6 @@ self.start(self.__filename, bundle=self.__bundle, isFile=self.__isFile, noEntries=self.logTree.topLevelItemCount()) - def on_passwordCheckBox_toggled(self, isOn): - """ - Private slot to handle the password checkbox toggled. - - @param isOn flag indicating the status of the check box (boolean) - """ - if isOn: - self.input.setEchoMode(QLineEdit.Password) - else: - self.input.setEchoMode(QLineEdit.Normal) - - @pyqtSlot() - def on_sendButton_clicked(self): - """ - Private slot to send the input to the mercurial process. - """ - inputTxt = self.input.text() - inputTxt += os.linesep - - if self.passwordCheckBox.isChecked(): - self.errors.insertPlainText(os.linesep) - self.errors.ensureCursorVisible() - else: - self.errors.insertPlainText(inputTxt) - self.errors.ensureCursorVisible() - - self.process.write(strToQByteArray(inputTxt)) - - self.passwordCheckBox.setChecked(False) - self.input.clear() - - def on_input_returnPressed(self): - """ - Private slot to handle the press of the return key in the input field. - """ - self.intercept = True - self.on_sendButton_clicked() - - def keyPressEvent(self, evt): - """ - Protected slot to handle a key press event. - - @param evt the key press event (QKeyEvent) - """ - if self.intercept: - self.intercept = False - evt.accept() - return - super(HgLogBrowserDialog, self).keyPressEvent(evt) - @pyqtSlot() def __phaseActTriggered(self): """