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

branch
eric7
changeset 9421
989ee2535d59
parent 9413
80c06d472826
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9420:92810aebc909 9421:989ee2535d59
10 import re 10 import re
11 11
12 from PyQt6.QtCore import Qt, QCoreApplication 12 from PyQt6.QtCore import Qt, QCoreApplication
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem 13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem
14 14
15 from eric7 import Preferences
16 from eric7.EricWidgets import EricMessageBox
17
15 from .Ui_HgAnnotateDialog import Ui_HgAnnotateDialog 18 from .Ui_HgAnnotateDialog import Ui_HgAnnotateDialog
16
17 from eric7 import Preferences
18 19
19 20
20 class HgAnnotateDialog(QDialog, Ui_HgAnnotateDialog): 21 class HgAnnotateDialog(QDialog, Ui_HgAnnotateDialog):
21 """ 22 """
22 Class implementing a dialog to show the output of the hg annotate command. 23 Class implementing a dialog to show the output of the hg annotate command.
38 39
39 self.vcs = vcs 40 self.vcs = vcs
40 self.__hgClient = vcs.getClient() 41 self.__hgClient = vcs.getClient()
41 42
42 self.__annotateRe = re.compile( 43 self.__annotateRe = re.compile(
43 r"""(.+)\s+(\d+)\s+([0-9a-fA-F]+)\s+([0-9-]+)\s+(.+)""" 44 r"""(.+)\s+(\d+)\s+([0-9a-fA-F]+)\s+([0-9-]+)\s+(.+?)([:*])(.*)"""
44 ) 45 )
45 46
46 self.annotateList.headerItem().setText(self.annotateList.columnCount(), "") 47 self.annotateList.headerItem().setText(self.annotateList.columnCount(), "")
47 font = Preferences.getEditorOtherFonts("MonospacedFont") 48 font = Preferences.getEditorOtherFonts("MonospacedFont")
48 self.annotateList.setFont(font) 49 self.annotateList.setFont(font)
59 if self.__hgClient.isExecuting(): 60 if self.__hgClient.isExecuting():
60 self.__hgClient.cancel() 61 self.__hgClient.cancel()
61 62
62 e.accept() 63 e.accept()
63 64
64 def start(self, fn): 65 def start(self, fn, skiplist=""):
65 """ 66 """
66 Public slot to start the annotate command. 67 Public slot to start the annotate command.
67 68
68 @param fn filename to show the annotation for (string) 69 @param fn filename to show the annotation for
70 @type str
71 @param skiplist name of a skip list file
72 @type str
69 """ 73 """
70 self.annotateList.clear() 74 self.annotateList.clear()
71 self.errorGroup.hide() 75 self.errorGroup.hide()
72 self.intercept = False 76 self.intercept = False
73 self.activateWindow() 77 self.activateWindow()
78 args.append("--user") 82 args.append("--user")
79 args.append("--date") 83 args.append("--date")
80 args.append("--number") 84 args.append("--number")
81 args.append("--changeset") 85 args.append("--changeset")
82 args.append("--quiet") 86 args.append("--quiet")
87 if skiplist:
88 args.extend(self.__buildSkipList(skiplist))
83 args.append(fn) 89 args.append(fn)
84 90
85 out, err = self.__hgClient.runcommand(args) 91 out, err = self.__hgClient.runcommand(args)
86 if err: 92 if err:
87 self.__showError(err) 93 self.__showError(err)
90 self.__processOutputLine(line) 96 self.__processOutputLine(line)
91 if self.__hgClient.wasCanceled(): 97 if self.__hgClient.wasCanceled():
92 break 98 break
93 self.__finish() 99 self.__finish()
94 100
101 def __buildSkipList(self, skiplist):
102 """
103 Private method to build a program arguments list of changesets to be skipped.
104
105 @param skiplist name of a skip list file
106 @type str
107 @return list of arguments
108 @rtype list of str
109 """
110 skipArgs = []
111
112 try:
113 with open(skiplist, "r") as f:
114 for line in f.readlines():
115 line = line.strip()
116 if line and not line.startswith("#"):
117 skipArgs.extend(["--skip", line])
118 except OSError as err:
119 EricMessageBox.information(
120 None,
121 self.tr("Mercurial Annotate"),
122 self.tr(
123 "<p>The skip list file <b>{0}</b> could not be read. The skip list"
124 " will be ignored.</p><p>Reason: {1}</p>"
125 ).format(skiplist, str(err)),
126 )
127 skipArgs = []
128
129 return skipArgs
130
95 def __finish(self): 131 def __finish(self):
96 """ 132 """
97 Private slot called when the process finished or the user pressed 133 Private slot called when the process finished or the user pressed
98 the button. 134 the button.
99 """ 135 """
126 """ 162 """
127 self.annotateList.header().resizeSections( 163 self.annotateList.header().resizeSections(
128 QHeaderView.ResizeMode.ResizeToContents 164 QHeaderView.ResizeMode.ResizeToContents
129 ) 165 )
130 166
131 def __generateItem(self, revision, changeset, author, date, text): 167 def __generateItem(self, marker, revision, changeset, author, date, text):
132 """ 168 """
133 Private method to generate an annotate item in the annotation list. 169 Private method to generate an annotate item in the annotation list.
134 170
171 @param marker marker character for skipped revisions (string)
135 @param revision revision string (string) 172 @param revision revision string (string)
136 @param changeset changeset string (string) 173 @param changeset changeset string (string)
137 @param author author of the change (string) 174 @param author author of the change (string)
138 @param date date of the change (string) 175 @param date date of the change (string)
139 @param text text of the change (string) 176 @param text text of the change (string)
140 """ 177 """
141 itm = QTreeWidgetItem( 178 itm = QTreeWidgetItem(
142 self.annotateList, 179 self.annotateList,
143 [revision, changeset, author, date, "{0:d}".format(self.lineno), text], 180 [
144 ) 181 marker,
182 revision,
183 changeset,
184 author,
185 date,
186 "{0:d}".format(self.lineno),
187 text,
188 ],
189 )
190 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignHCenter)
191 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
192 itm.setTextAlignment(5, Qt.AlignmentFlag.AlignRight)
193
194 if marker == "*":
195 itm.setToolTip(0, self.tr("Changed by skipped commit"))
196
145 self.lineno += 1 197 self.lineno += 1
146 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
147 itm.setTextAlignment(4, Qt.AlignmentFlag.AlignRight)
148 198
149 def __processOutputLine(self, line): 199 def __processOutputLine(self, line):
150 """ 200 """
151 Private method to process the lines of output. 201 Private method to process the lines of output.
152 202
153 @param line output line to be processed (string) 203 @param line output line to be processed (string)
154 """ 204 """
155 try: 205 match = self.__annotateRe.match(line)
156 info, text = line.split(": ", 1) 206 author, rev, changeset, date, file, marker, text = match.groups()
157 except ValueError: 207 if marker == ":":
158 info = line[:-2] 208 marker = ""
159 text = ""
160 match = self.__annotateRe.match(info)
161 author, rev, changeset, date, file = match.groups()
162 self.__generateItem( 209 self.__generateItem(
163 rev.strip(), changeset.strip(), author.strip(), date.strip(), text 210 marker, rev.strip(), changeset.strip(), author.strip(), date.strip(), text
164 ) 211 )
165 212
166 def __showError(self, out): 213 def __showError(self, out):
167 """ 214 """
168 Private slot to show some error. 215 Private slot to show some error.

eric ide

mercurial