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

Fri, 04 Nov 2022 13:52:26 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Nov 2022 13:52:26 +0100
branch
eric7
changeset 9473
3f23dbf37dbe
parent 9413
80c06d472826
child 9653
e67609152c5e
permissions
-rw-r--r--

Resorted the import statements using isort.

4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
3 # Copyright (c) 2015 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class to generate the output of the hg diff command.
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
12 from PyQt6.QtCore import QObject, pyqtSignal
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
14 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
15
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class HgDiffGenerator(QObject):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing the generation of output of the hg diff command.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
20
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @signal finished() emitted when all processes have finished
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
23
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 finished = pyqtSignal()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
25
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def __init__(self, vcs, parent=None):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param vcs reference to the vcs object
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param parent parent widget (QWidget)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8108
diff changeset
33 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.vcs = vcs
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__hgClient = self.vcs.getClient()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def stopProcess(self):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Public slot to stop the diff process.
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
7370
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
43 if self.__hgClient.isExecuting():
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
44 self.__hgClient.cancel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 def __getVersionArg(self, version):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Private method to get a hg revision argument for the given revision.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @param version revision (integer or string)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 @return version argument (string)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 if version == "WORKING":
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 return None
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 else:
8108
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
56 return str(version).strip()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 def start(self, fn, versions=None, bundle=None, qdiff=False):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 Public slot to start the hg diff command.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
61
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 @param fn filename to be diffed (string)
7900
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7779
diff changeset
63 @param versions list of versions to be diffed (list of up to
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 2 strings or None)
7900
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7779
diff changeset
65 @param bundle name of a bundle file (string)
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7779
diff changeset
66 @param qdiff flag indicating qdiff command shall be used (boolean)
4212
530b953eb623 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4130
diff changeset
67 @return flag indicating a successful start of the diff command
530b953eb623 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4130
diff changeset
68 (boolean)
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
70 if qdiff:
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
71 args = self.vcs.initCommand("qdiff")
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
72 else:
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
73 args = self.vcs.initCommand("diff")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
75 if self.vcs.hasSubrepositories():
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
76 args.append("--subrepos")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
78 if bundle:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79 args.append("--repository")
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
80 args.append(bundle)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81 elif self.vcs.bundleFile and os.path.exists(self.vcs.bundleFile):
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82 args.append("--repository")
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
83 args.append(self.vcs.bundleFile)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
85 if versions is not None:
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
86 rev1 = self.__getVersionArg(versions[0])
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
87 rev2 = None
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
88 if len(versions) == 2:
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
89 rev2 = self.__getVersionArg(versions[1])
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
90
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
91 if rev1 is not None or rev2 is not None:
8108
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
92 if self.vcs.version >= (5, 7, 0):
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
93 if rev1 is not None:
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
94 args += ["--from", rev1]
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
95 if rev2 is not None:
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
96 args += ["--to", rev2]
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
97 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
98 args.append("-r")
8108
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
99 if rev1 is not None and rev2 is not None:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100 args.append("{0}:{1}".format(rev1, rev2))
8108
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
101 elif rev2 is None:
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
102 args.append(rev1)
a42ae6be4cc3 Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7971
diff changeset
103 elif rev1 is None:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104 args.append(":{0}".format(rev2))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105
7971
ff2971513d6d Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
106 if fn:
ff2971513d6d Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
107 if isinstance(fn, list):
ff2971513d6d Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
108 self.vcs.addArguments(args, fn)
ff2971513d6d Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
109 else:
ff2971513d6d Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
110 args.append(fn)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
111
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
112 self.__oldFile = ""
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
113 self.__oldFileLine = -1
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
114 self.__fileSeparators = []
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
115 self.__output = []
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
116 self.__errors = []
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
118 with EricOverrideCursor():
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
119 out, err = self.__hgClient.runcommand(args)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
120
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
121 if err:
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
122 self.__errors = err.splitlines(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
123
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
124 if out:
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
125 self.__output = out.splitlines(True)
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
126 for lineno, line in enumerate(self.__output):
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
127 if line.startswith(("--- ", "+++ ")):
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
128 self.__processFileLine(lineno, line)
7771
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
129 if self.__hgClient.wasCanceled():
787a6b3f8c9f Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
130 break
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131
7370
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
132 self.__finish()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
135
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 def __finish(self):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 Private slot called when the process finished or the user pressed
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 the button.
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.finished.emit()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
142
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 def getResult(self):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 Public method to return the result data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 @return tuple of lists of string containing lines of the diff, the
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 list of errors and a list of tuples of filenames and the line
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 into the diff output.
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 return (self.__output, self.__errors, self.__fileSeparators)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
152
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 def __extractFileName(self, line):
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Private method to extract the file name out of a file separator line.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
156
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @param line line to be processed (string)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 @return extracted file name (string)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 f = line.split(None, 1)[1]
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 f = f.rsplit(None, 6)[0]
8234
fcb6b4b96274 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
162 f = "__NULL__" if f == "/dev/null" else f.split("/", 1)[1]
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 return f
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
165 def __processFileLine(self, lineno, line):
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 Private slot to process a line giving the old/new file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
168
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
169 @param lineno line number of line to be processed
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
170 @type int
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
171 @param line line to be processed
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
172 @type str
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174 if line.startswith("---"):
7779
757334671130 Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7775
diff changeset
175 self.__oldFileLine = lineno
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.__oldFile = self.__extractFileName(line)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 else:
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 newFile = self.__extractFileName(line)
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 if self.__oldFile == "__NULL__":
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 self.__fileSeparators.append((newFile, newFile, self.__oldFileLine))
4130
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 else:
c5af9f10a061 Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 self.__fileSeparators.append(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
183 (self.__oldFile, newFile, self.__oldFileLine)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184 )

eric ide

mercurial