Tue, 13 Apr 2021 18:02:59 +0200
Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 2).
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1  # * coding: utf8 * 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

2  
7923
91e843545d9a
Updated copyright for 2021.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7900
diff
changeset

3  # Copyright (c) 2015  2021 Detlev Offenbach <detlev@dieoffenbachs.de> 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.de>
parents:
diff
changeset

11  
7370
5fb53279f2df
Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7360
diff
changeset

12  from PyQt5.QtCore import pyqtSignal, QObject 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

13  
7771
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

14  from E5Gui.E5OverrideCursor import E5OverrideCursor 
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.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@dieoffenbachs.de>
parents:
diff
changeset

19  Class implementing the generation of 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@dieoffenbachs.de>
parents:
diff
changeset

20  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.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@dieoffenbachs.de>
parents:
diff
changeset

22  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

23  finished = pyqtSignal() 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

24  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

25  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@dieoffenbachs.de>
parents:
diff
changeset

26  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

27  Constructor 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

28  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

29  @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@dieoffenbachs.de>
parents:
diff
changeset

30  @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@dieoffenbachs.de>
parents:
diff
changeset

31  """ 
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
8108
diff
changeset

32  super().__init__(parent) 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

33  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

34  self.vcs = vcs 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

35  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

36  self.__hgClient = self.vcs.getClient() 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

37  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

38  def stopProcess(self): 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

39  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

40  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@dieoffenbachs.de>
parents:
diff
changeset

41  """ 
7370
5fb53279f2df
Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7360
diff
changeset

42  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@dieoffenbachs.de>
parents:
7360
diff
changeset

43  self.__hgClient.cancel() 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

44  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

45  def __getVersionArg(self, version): 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

46  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

47  Private method to get a hg revision argument for the given revision. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

48  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

49  @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@dieoffenbachs.de>
parents:
diff
changeset

50  @return version argument (string) 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

51  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

52  if version == "WORKING": 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

53  return None 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

54  else: 
8108
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

55  return str(version).strip() 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

56  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

57  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@dieoffenbachs.de>
parents:
diff
changeset

58  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

59  Public slot to start the hg diff command. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

60  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

61  @param fn filename to be diffed (string) 
7900
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7779
diff
changeset

62  @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@dieoffenbachs.de>
parents:
diff
changeset

63  2 strings or None) 
7900
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7779
diff
changeset

64  @param bundle name of a bundle file (string) 
72b88fb20261
Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7779
diff
changeset

65  @param qdiff flag indicating qdiff command shall be used (boolean) 
4212
530b953eb623
Corrected some code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4130
diff
changeset

66  @return flag indicating a successful start of the diff command 
530b953eb623
Corrected some code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4130
diff
changeset

67  (boolean) 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

68  """ 
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

69  if qdiff: 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

70  args = self.vcs.initCommand("qdiff") 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

71  else: 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

72  args = self.vcs.initCommand("diff") 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

73  
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

74  if self.vcs.hasSubrepositories(): 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

75  args.append("subrepos") 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

76  
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

77  if bundle: 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

78  args.append('repository') 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

79  args.append(bundle) 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

80  elif ( 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

81  self.vcs.bundleFile and 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

82  os.path.exists(self.vcs.bundleFile) 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

83  ): 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

84  args.append('repository') 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

85  args.append(self.vcs.bundleFile) 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

86  
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

87  if versions is not None: 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

88  rev1 = self.__getVersionArg(versions[0]) 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

89  rev2 = None 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

90  if len(versions) == 2: 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

91  rev2 = self.__getVersionArg(versions[1]) 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

92  
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

93  if rev1 is not None or rev2 is not None: 
8108
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

94  if self.vcs.version >= (5, 7, 0): 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

95  if rev1 is not None: 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

96  args += ["from", rev1] 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

97  if rev2 is not None: 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

98  args += ["to", rev2] 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

99  else: 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

100  args.append('r') 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

101  if rev1 is not None and rev2 is not None: 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

102  args.append('{0}:{1}'.format(rev1, rev2)) 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

103  elif rev2 is None: 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

104  args.append(rev1) 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

105  elif rev1 is None: 
a42ae6be4cc3
Mercurial: added support for Mercurial 5.7.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7971
diff
changeset

106  args.append(':{0}'.format(rev2)) 
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

107  
7971
ff2971513d6d
Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7923
diff
changeset

108  if fn: 
ff2971513d6d
Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7923
diff
changeset

109  if isinstance(fn, list): 
ff2971513d6d
Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7923
diff
changeset

110  self.vcs.addArguments(args, fn) 
ff2971513d6d
Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7923
diff
changeset

111  else: 
ff2971513d6d
Mercurial: completed more code cleanup.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7923
diff
changeset

112  args.append(fn) 
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

113  
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

114  self.__oldFile = "" 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

115  self.__oldFileLine = 1 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

116  self.__fileSeparators = [] 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

117  self.__output = [] 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

118  self.__errors = [] 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

119  
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

120  with E5OverrideCursor(): 
7771
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

121  out, err = self.__hgClient.runcommand(args) 
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

122  
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

123  if err: 
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

124  self.__errors = err.splitlines(True) 
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

125  
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

126  if out: 
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

127  self.__output = out.splitlines(True) 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

128  for lineno, line in enumerate(self.__output): 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

129  if line.startswith((" ", "+++ ")): 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

130  self.__processFileLine(lineno, line) 
7771
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

131  if self.__hgClient.wasCanceled(): 
787a6b3f8c9f
Optimized the use of Waiting Cursors by using a specialized context manager class.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7370
diff
changeset

132  break 
7370
5fb53279f2df
Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7360
diff
changeset

133  
5fb53279f2df
Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7360
diff
changeset

134  self.__finish() 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

135  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

136  return True 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.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@dieoffenbachs.de>
parents:
diff
changeset

138  def __finish(self): 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

139  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

140  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@dieoffenbachs.de>
parents:
diff
changeset

141  the button. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

142  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

143  self.finished.emit() 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.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@dieoffenbachs.de>
parents:
diff
changeset

145  def getResult(self): 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

146  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

147  Public method to return the result data. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

148  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

149  @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@dieoffenbachs.de>
parents:
diff
changeset

150  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@dieoffenbachs.de>
parents:
diff
changeset

151  into the diff output. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

152  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

153  return (self.__output, self.__errors, self.__fileSeparators) 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.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@dieoffenbachs.de>
parents:
diff
changeset

155  def __extractFileName(self, line): 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

156  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

157  Private method to extract the file name out of a file separator line. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

158  
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

159  @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@dieoffenbachs.de>
parents:
diff
changeset

160  @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@dieoffenbachs.de>
parents:
diff
changeset

161  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

162  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@dieoffenbachs.de>
parents:
diff
changeset

163  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@dieoffenbachs.de>
parents:
8218
diff
changeset

164  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@dieoffenbachs.de>
parents:
diff
changeset

165  return f 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

166  
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

167  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@dieoffenbachs.de>
parents:
diff
changeset

168  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

169  Private slot to process a line giving the old/new file. 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

170  
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

171  @param lineno line number of line to be processed 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

172  @type int 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

173  @param line line to be processed 
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

174  @type str 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

175  """ 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

176  if line.startswith(''): 
7779
757334671130
Optimized the various diff panes by using QPlainTextEdit.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
7775
diff
changeset

177  self.__oldFileLine = lineno 
4130
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

178  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@dieoffenbachs.de>
parents:
diff
changeset

179  else: 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

180  newFile = self.__extractFileName(line) 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

181  if self.__oldFile == "__NULL__": 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

182  self.__fileSeparators.append( 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

183  (newFile, newFile, self.__oldFileLine)) 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

184  else: 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

185  self.__fileSeparators.append( 
c5af9f10a061
Moved logic to generate a Mercurial diff to a separate module in order to reuse it.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

186  (self.__oldFile, newFile, self.__oldFileLine)) 