--- a/src/eric7/Plugins/VcsPlugins/vcsGit/GitPatchStatisticsDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Plugins/VcsPlugins/vcsGit/GitPatchStatisticsDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -23,54 +23,55 @@ """ Class implementing a dialog to show some patch file statistics. """ + def __init__(self, vcs, parent=None): """ Constructor - + @param vcs reference to the VCS object (Git) @param parent reference to the parent widget (QWidget) """ super().__init__(parent) self.setupUi(self) self.setWindowFlags(Qt.WindowType.Window) - + self.__vcs = vcs - + self.changesTreeWidget.headerItem().setText( - self.changesTreeWidget.columnCount(), "") - self.changesTreeWidget.header().setSortIndicator( - 2, Qt.SortOrder.AscendingOrder) - + self.changesTreeWidget.columnCount(), "" + ) + self.changesTreeWidget.header().setSortIndicator(2, Qt.SortOrder.AscendingOrder) + def start(self, projectDir, patchCheckData): """ Public method to start the statistics process. - + @param projectDir directory name of the project (string) @param patchCheckData tuple of data as returned by the GitPatchFilesDialog.getData() method """ self.__patchCheckData = patchCheckData - + self.changesTreeWidget.clear() self.summaryEdit.clear() - + # find the root of the repo repodir = projectDir while not os.path.isdir(os.path.join(repodir, self.__vcs.adminDir)): repodir = os.path.dirname(repodir) if os.path.splitdrive(repodir)[1] == os.sep: return - + from .GitPatchFilesDialog import GitPatchFilesDialog + dlg = GitPatchFilesDialog(repodir, patchCheckData) if dlg.exec() == QDialog.DialogCode.Accepted: patchFilesList, stripCount, inaccurateEof, recount = dlg.getData() - self.__patchCheckData = (patchFilesList, stripCount, - inaccurateEof, recount) + self.__patchCheckData = (patchFilesList, stripCount, inaccurateEof, recount) if patchFilesList: process = QProcess() process.setWorkingDirectory(repodir) - + # step 1: get the statistics args = self.__vcs.initCommand("apply") args.append("--numstat") @@ -80,27 +81,30 @@ args.append("--recount") args.append("-p{0}".format(stripCount)) args.extend(patchFilesList) - - process.start('git', args) + + process.start("git", args) procStarted = process.waitForStarted(5000) if not procStarted: EricMessageBox.critical( self, - self.tr('Process Generation Error'), + self.tr("Process Generation Error"), self.tr( - 'The process {0} could not be started. ' - 'Ensure, that it is in the search path.' - ).format('git')) + "The process {0} could not be started. " + "Ensure, that it is in the search path." + ).format("git"), + ) return else: finished = process.waitForFinished(30000) if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - Preferences.getSystem("IOEncoding"), - 'replace') + output = str( + process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + "replace", + ) for line in output.splitlines(): self.__createStatisticsItem(line) - + # step 2: get the summary args = self.__vcs.initCommand("apply") args.append("--summary") @@ -110,51 +114,54 @@ args.append("--recount") args.append("-p{0}".format(stripCount)) args.extend(patchFilesList) - - process.start('git', args) + + process.start("git", args) procStarted = process.waitForStarted(5000) if not procStarted: EricMessageBox.critical( self, - self.tr('Process Generation Error'), + self.tr("Process Generation Error"), self.tr( - 'The process {0} could not be started. ' - 'Ensure, that it is in the search path.' - ).format('git')) + "The process {0} could not be started. " + "Ensure, that it is in the search path." + ).format("git"), + ) return else: finished = process.waitForFinished(30000) if finished and process.exitCode() == 0: - output = str(process.readAllStandardOutput(), - Preferences.getSystem("IOEncoding"), - 'replace') + output = str( + process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + "replace", + ) for line in output.splitlines(): self.summaryEdit.appendPlainText(line.strip()) - + def __createStatisticsItem(self, line): """ Private method to create a file statistics entry. - + @param line string with file statistics data (string) """ insertions, deletions, filename = line.strip().split(None, 2) - itm = QTreeWidgetItem(self.changesTreeWidget, - [insertions, deletions, filename]) + itm = QTreeWidgetItem(self.changesTreeWidget, [insertions, deletions, filename]) itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight) itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) - + def __resizeColumns(self): """ Private method to resize the list columns. """ self.changesTreeWidget.header().resizeSections( - QHeaderView.ResizeMode.ResizeToContents) + QHeaderView.ResizeMode.ResizeToContents + ) self.changesTreeWidget.header().setStretchLastSection(True) - + def getData(self): """ Public method to get the data used to generate the statistics. - + @return tuple of list of patch files, strip count, flag indicating that the patch has inaccurate end-of-file marker and a flag indicating to not trust the line count information