src/eric7/Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py

branch
eric7
changeset 9421
989ee2535d59
parent 9413
80c06d472826
child 9473
3f23dbf37dbe
--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py	Tue Oct 18 17:48:03 2022 +0200
+++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py	Wed Oct 19 13:39:16 2022 +0200
@@ -12,9 +12,10 @@
 from PyQt6.QtCore import Qt, QCoreApplication
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem
 
-from .Ui_HgAnnotateDialog import Ui_HgAnnotateDialog
+from eric7 import Preferences
+from eric7.EricWidgets import EricMessageBox
 
-from eric7 import Preferences
+from .Ui_HgAnnotateDialog import Ui_HgAnnotateDialog
 
 
 class HgAnnotateDialog(QDialog, Ui_HgAnnotateDialog):
@@ -40,7 +41,7 @@
         self.__hgClient = vcs.getClient()
 
         self.__annotateRe = re.compile(
-            r"""(.+)\s+(\d+)\s+([0-9a-fA-F]+)\s+([0-9-]+)\s+(.+)"""
+            r"""(.+)\s+(\d+)\s+([0-9a-fA-F]+)\s+([0-9-]+)\s+(.+?)([:*])(.*)"""
         )
 
         self.annotateList.headerItem().setText(self.annotateList.columnCount(), "")
@@ -61,11 +62,14 @@
 
         e.accept()
 
-    def start(self, fn):
+    def start(self, fn, skiplist=""):
         """
         Public slot to start the annotate command.
 
-        @param fn filename to show the annotation for (string)
+        @param fn filename to show the annotation for
+        @type str
+        @param skiplist name of a skip list file
+        @type str
         """
         self.annotateList.clear()
         self.errorGroup.hide()
@@ -80,6 +84,8 @@
         args.append("--number")
         args.append("--changeset")
         args.append("--quiet")
+        if skiplist:
+            args.extend(self.__buildSkipList(skiplist))
         args.append(fn)
 
         out, err = self.__hgClient.runcommand(args)
@@ -92,6 +98,36 @@
                     break
         self.__finish()
 
+    def __buildSkipList(self, skiplist):
+        """
+        Private method to build a program arguments list of changesets to be skipped.
+
+        @param skiplist name of a skip list file
+        @type str
+        @return list of arguments
+        @rtype list of str
+        """
+        skipArgs = []
+
+        try:
+            with open(skiplist, "r") as f:
+                for line in f.readlines():
+                    line = line.strip()
+                    if line and not line.startswith("#"):
+                        skipArgs.extend(["--skip", line])
+        except OSError as err:
+            EricMessageBox.information(
+                None,
+                self.tr("Mercurial Annotate"),
+                self.tr(
+                    "<p>The skip list file <b>{0}</b> could not be read. The skip list"
+                    " will be ignored.</p><p>Reason: {1}</p>"
+                ).format(skiplist, str(err)),
+            )
+            skipArgs = []
+
+        return skipArgs
+
     def __finish(self):
         """
         Private slot called when the process finished or the user pressed
@@ -128,10 +164,11 @@
             QHeaderView.ResizeMode.ResizeToContents
         )
 
-    def __generateItem(self, revision, changeset, author, date, text):
+    def __generateItem(self, marker, revision, changeset, author, date, text):
         """
         Private method to generate an annotate item in the annotation list.
 
+        @param marker marker character for skipped revisions (string)
         @param revision revision string (string)
         @param changeset changeset string (string)
         @param author author of the change (string)
@@ -140,11 +177,24 @@
         """
         itm = QTreeWidgetItem(
             self.annotateList,
-            [revision, changeset, author, date, "{0:d}".format(self.lineno), text],
+            [
+                marker,
+                revision,
+                changeset,
+                author,
+                date,
+                "{0:d}".format(self.lineno),
+                text,
+            ],
         )
+        itm.setTextAlignment(0, Qt.AlignmentFlag.AlignHCenter)
+        itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
+        itm.setTextAlignment(5, Qt.AlignmentFlag.AlignRight)
+
+        if marker == "*":
+            itm.setToolTip(0, self.tr("Changed by skipped commit"))
+
         self.lineno += 1
-        itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
-        itm.setTextAlignment(4, Qt.AlignmentFlag.AlignRight)
 
     def __processOutputLine(self, line):
         """
@@ -152,15 +202,12 @@
 
         @param line output line to be processed (string)
         """
-        try:
-            info, text = line.split(": ", 1)
-        except ValueError:
-            info = line[:-2]
-            text = ""
-        match = self.__annotateRe.match(info)
-        author, rev, changeset, date, file = match.groups()
+        match = self.__annotateRe.match(line)
+        author, rev, changeset, date, file, marker, text = match.groups()
+        if marker == ":":
+            marker = ""
         self.__generateItem(
-            rev.strip(), changeset.strip(), author.strip(), date.strip(), text
+            marker, rev.strip(), changeset.strip(), author.strip(), date.strip(), text
         )
 
     def __showError(self, out):

eric ide

mercurial