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

branch
eric7
changeset 10438
4cd7e5a8b3cf
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10437:2f70ca07f0af 10438:4cd7e5a8b3cf
20 20
21 def __init__(self, diff): 21 def __init__(self, diff):
22 """ 22 """
23 Constructor 23 Constructor
24 24
25 @param diff output of the diff command (list of string) 25 @param diff output of the diff command
26 @type list of str
26 """ 27 """
27 self.__diff = diff[:] 28 self.__diff = diff[:]
28 29
29 self.__headerLines = [] 30 self.__headerLines = []
30 self.__hunks = [] 31 self.__hunks = []
33 34
34 def __initHunk(self): 35 def __initHunk(self):
35 """ 36 """
36 Private method to initialize a hunk data structure. 37 Private method to initialize a hunk data structure.
37 38
38 @return hunk data structure (dictionary) 39 @return hunk data structure
40 @rtype dict
39 """ 41 """
40 hunk = { 42 hunk = {
41 "start": -1, 43 "start": -1,
42 "end": -1, 44 "end": -1,
43 "lines": [], 45 "lines": [],
51 53
52 def __parseRange(self, headerRange): 54 def __parseRange(self, headerRange):
53 """ 55 """
54 Private method to parse the hunk header range part. 56 Private method to parse the hunk header range part.
55 57
56 @param headerRange hunk header range (string) 58 @param headerRange hunk header range
57 @return tuple of hunk start and hunk length (integer, integer) 59 @type str
60 @return tuple of hunk start and hunk length
61 @rtype tuple of (int, int)
58 """ 62 """
59 if "," in headerRange: 63 if "," in headerRange:
60 begin, end = headerRange.split(",", 1) 64 begin, end = headerRange.split(",", 1)
61 return int(begin), int(end) 65 return int(begin), int(end)
62 else: 66 else:
102 106
103 def __generateRange(self, start, count): 107 def __generateRange(self, start, count):
104 """ 108 """
105 Private method to generate a hunk header range. 109 Private method to generate a hunk header range.
106 110
107 @param start start line (integer) 111 @param start start line
108 @param count line count (integer) 112 @type int
109 @return hunk header range (string) 113 @param count line count
114 @type int
115 @return hunk header range
116 @rtype str
110 """ 117 """
111 if count == 1: 118 if count == 1:
112 return "{0}".format(start) 119 return "{0}".format(start)
113 else: 120 else:
114 return "{0},{1}".format(start, count) 121 return "{0},{1}".format(start, count)
117 self, oldStart, oldCount, newStart, newCount, heading=os.linesep 124 self, oldStart, oldCount, newStart, newCount, heading=os.linesep
118 ): 125 ):
119 """ 126 """
120 Private method to generate a hunk header line. 127 Private method to generate a hunk header line.
121 128
122 @param oldStart start line of the old part (integer) 129 @param oldStart start line of the old part
123 @param oldCount line count of the old part (integer) 130 @type int
124 @param newStart start line of the new part (integer) 131 @param oldCount line count of the old part
125 @param newCount line count of the new part (integer) 132 @type int
126 @param heading hunk heading (string) 133 @param newStart start line of the new part
127 @return hunk header (string) 134 @type int
135 @param newCount line count of the new part
136 @type int
137 @param heading hunk heading
138 @type str
139 @return hunk header
140 @rtype str
128 """ 141 """
129 return "@@ -{0} +{1} @@{2}".format( 142 return "@@ -{0} +{1} @@{2}".format(
130 self.__generateRange(oldStart, oldCount), 143 self.__generateRange(oldStart, oldCount),
131 self.__generateRange(newStart, newCount), 144 self.__generateRange(newStart, newCount),
132 heading, 145 heading,
134 147
135 def headerLength(self): 148 def headerLength(self):
136 """ 149 """
137 Public method to get the header length. 150 Public method to get the header length.
138 151
139 @return length of the header (integer) 152 @return length of the header
153 @rtype int
140 """ 154 """
141 self.__parseDiff() 155 self.__parseDiff()
142 return len(self.__headerLines) 156 return len(self.__headerLines)
143 157
144 def createHunkPatch(self, lineIndex): 158 def createHunkPatch(self, lineIndex):
145 """ 159 """
146 Public method to create a hunk based patch. 160 Public method to create a hunk based patch.
147 161
148 @param lineIndex line number of the hunk (integer) 162 @param lineIndex line number of the hunk
149 @return diff lines of the patch (string) 163 @type int
164 @return diff lines of the patch
165 @rtype str
150 """ 166 """
151 self.__parseDiff() 167 self.__parseDiff()
152 168
153 patch = self.__headerLines[:] 169 patch = self.__headerLines[:]
154 for hunk in self.__hunks: 170 for hunk in self.__hunks:
160 176
161 def createLinesPatch(self, startIndex, endIndex, reverse=False): 177 def createLinesPatch(self, startIndex, endIndex, reverse=False):
162 """ 178 """
163 Public method to create a selected lines based patch. 179 Public method to create a selected lines based patch.
164 180
165 @param startIndex start line number (integer) 181 @param startIndex start line number
166 @param endIndex end line number (integer) 182 @type int
167 @param reverse flag indicating a reverse patch (boolean) 183 @param endIndex end line number
168 @return diff lines of the patch (string) 184 @type int
185 @param reverse flag indicating a reverse patch
186 @type bool
187 @return diff lines of the patch
188 @rtype str
169 """ 189 """
170 self.__parseDiff() 190 self.__parseDiff()
171 191
172 ADDITION = "+" 192 ADDITION = "+"
173 DELETION = "-" 193 DELETION = "-"

eric ide

mercurial