src/eric7/Plugins/VcsPlugins/vcsGit/GitPatchStatisticsDialog.py

Wed, 04 Oct 2023 17:50:59 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 04 Oct 2023 17:50:59 +0200
branch
eric7
changeset 10217
7888177e7463
parent 9653
e67609152c5e
child 10438
4cd7e5a8b3cf
permissions
-rw-r--r--

Fixed in issue with several editable combo box selectors, that the value could not be changed if the edited text differed by case only. This was caused by the standard QComboBox completer.

# -*- coding: utf-8 -*-

# Copyright (c) 2015 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to show some patch file statistics.
"""

from PyQt6.QtCore import QProcess, Qt
from PyQt6.QtWidgets import QDialog, QHeaderView, QTreeWidgetItem

from eric7 import Preferences
from eric7.EricWidgets import EricMessageBox

from .Ui_GitPatchStatisticsDialog import Ui_GitPatchStatisticsDialog


class GitPatchStatisticsDialog(QDialog, Ui_GitPatchStatisticsDialog):
    """
    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)

    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
        """
        from .GitPatchFilesDialog import GitPatchFilesDialog

        self.__patchCheckData = patchCheckData

        self.changesTreeWidget.clear()
        self.summaryEdit.clear()

        # find the root of the repo
        repodir = self.__vcs.findRepoRoot(projectDir)
        if not repodir:
            return

        dlg = GitPatchFilesDialog(repodir, patchCheckData)
        if dlg.exec() == QDialog.DialogCode.Accepted:
            patchFilesList, stripCount, inaccurateEof, recount = dlg.getData()
            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")
                if inaccurateEof:
                    args.append("--inaccurate-eof")
                if recount:
                    args.append("--recount")
                args.append("-p{0}".format(stripCount))
                args.extend(patchFilesList)

                process.start("git", args)
                procStarted = process.waitForStarted(5000)
                if not procStarted:
                    EricMessageBox.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("git"),
                    )
                    return
                else:
                    finished = process.waitForFinished(30000)
                    if finished and process.exitCode() == 0:
                        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")
                if inaccurateEof:
                    args.append("--inaccurate-eof")
                if recount:
                    args.append("--recount")
                args.append("-p{0}".format(stripCount))
                args.extend(patchFilesList)

                process.start("git", args)
                procStarted = process.waitForStarted(5000)
                if not procStarted:
                    EricMessageBox.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("git"),
                    )
                    return
                else:
                    finished = process.waitForFinished(30000)
                    if finished and process.exitCode() == 0:
                        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.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
        )
        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
            (list of string, integer, boolean, boolean)
        """
        return self.__patchCheckData

eric ide

mercurial