Show More
@@ -112,38 +112,30 b' class Merge3Text(object):' | |||
|
112 | 112 | end_marker = end_marker + b' ' + name_b |
|
113 | 113 | if name_base and base_marker: |
|
114 | 114 | base_marker = base_marker + b' ' + name_base |
|
115 |
merge_ |
|
|
115 | merge_groups = self.merge_groups() | |
|
116 | 116 | if minimize: |
|
117 |
merge_ |
|
|
118 |
for t in merge_ |
|
|
119 |
what = |
|
|
120 | if what == b'unchanged': | |
|
121 | for i in range(t[1], t[2]): | |
|
122 | yield self.base[i] | |
|
123 | elif what == b'a' or what == b'same': | |
|
124 | for i in range(t[1], t[2]): | |
|
125 | yield self.a[i] | |
|
126 | elif what == b'b': | |
|
127 | for i in range(t[1], t[2]): | |
|
128 | yield self.b[i] | |
|
129 | elif what == b'conflict': | |
|
117 | merge_groups = self.minimize(merge_groups) | |
|
118 | for what, lines in merge_groups: | |
|
119 | if what == b'conflict': | |
|
120 | base_lines, a_lines, b_lines = lines | |
|
130 | 121 | self.conflicts = True |
|
131 | 122 | if start_marker is not None: |
|
132 | 123 | yield start_marker + newline |
|
133 |
for i in |
|
|
134 |
yield |
|
|
124 | for line in a_lines: | |
|
125 | yield line | |
|
135 | 126 | if base_marker is not None: |
|
136 | 127 | yield base_marker + newline |
|
137 |
for i in |
|
|
138 |
yield |
|
|
128 | for line in base_lines: | |
|
129 | yield line | |
|
139 | 130 | if mid_marker is not None: |
|
140 | 131 | yield mid_marker + newline |
|
141 |
for i in |
|
|
142 |
yield |
|
|
132 | for line in b_lines: | |
|
133 | yield line | |
|
143 | 134 | if end_marker is not None: |
|
144 | 135 | yield end_marker + newline |
|
145 | 136 | else: |
|
146 |
r |
|
|
137 | for line in lines: | |
|
138 | yield line | |
|
147 | 139 | |
|
148 | 140 | def merge_groups(self): |
|
149 | 141 | """Yield sequence of line groups. Each one is a tuple: |
@@ -272,66 +264,49 b' class Merge3Text(object):' | |||
|
272 | 264 | ia = aend |
|
273 | 265 | ib = bend |
|
274 | 266 | |
|
275 |
def minimize(self, merge_ |
|
|
267 | def minimize(self, merge_groups): | |
|
276 | 268 | """Trim conflict regions of lines where A and B sides match. |
|
277 | 269 | |
|
278 | 270 | Lines where both A and B have made the same changes at the beginning |
|
279 | 271 | or the end of each merge region are eliminated from the conflict |
|
280 | 272 | region and are instead considered the same. |
|
281 | 273 | """ |
|
282 |
for |
|
|
283 |
if |
|
|
284 |
yield |
|
|
274 | for what, lines in merge_groups: | |
|
275 | if what != b"conflict": | |
|
276 | yield what, lines | |
|
285 | 277 | continue |
|
286 | # pytype thinks this tuple contains only 3 things, but | |
|
287 | # that's clearly not true because this code successfully | |
|
288 | # executes. It might be wise to rework merge_regions to be | |
|
289 | # some kind of attrs type. | |
|
290 | ( | |
|
291 | issue, | |
|
292 | z1, | |
|
293 | z2, | |
|
294 | a1, | |
|
295 | a2, | |
|
296 | b1, | |
|
297 | b2, | |
|
298 | ) = region # pytype: disable=bad-unpacking | |
|
299 | alen = a2 - a1 | |
|
300 | blen = b2 - b1 | |
|
278 | base_lines, a_lines, b_lines = lines | |
|
279 | alen = len(a_lines) | |
|
280 | blen = len(b_lines) | |
|
301 | 281 | |
|
302 | 282 | # find matches at the front |
|
303 | 283 | ii = 0 |
|
304 | while ( | |
|
305 | ii < alen and ii < blen and self.a[a1 + ii] == self.b[b1 + ii] | |
|
306 | ): | |
|
284 | while ii < alen and ii < blen and a_lines[ii] == b_lines[ii]: | |
|
307 | 285 | ii += 1 |
|
308 | 286 | startmatches = ii |
|
309 | 287 | |
|
310 | 288 | # find matches at the end |
|
311 | 289 | ii = 0 |
|
312 | 290 | while ( |
|
313 | ii < alen | |
|
314 | and ii < blen | |
|
315 | and self.a[a2 - ii - 1] == self.b[b2 - ii - 1] | |
|
291 | ii < alen and ii < blen and a_lines[-ii - 1] == b_lines[-ii - 1] | |
|
316 | 292 | ): |
|
317 | 293 | ii += 1 |
|
318 | 294 | endmatches = ii |
|
319 | 295 | |
|
320 | 296 | if startmatches > 0: |
|
321 |
yield b'same', a |
|
|
297 | yield b'same', a_lines[:startmatches] | |
|
322 | 298 | |
|
323 | 299 | yield ( |
|
324 | 300 | b'conflict', |
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 | b2 - endmatches, | |
|
301 | ( | |
|
302 | base_lines, | |
|
303 | a_lines[startmatches : alen - endmatches], | |
|
304 | b_lines[startmatches : blen - endmatches], | |
|
305 | ), | |
|
331 | 306 | ) |
|
332 | 307 | |
|
333 | 308 | if endmatches > 0: |
|
334 |
yield b'same', a |
|
|
309 | yield b'same', a_lines[alen - endmatches :] | |
|
335 | 310 | |
|
336 | 311 | def find_sync_regions(self): |
|
337 | 312 | """Return a list of sync regions, where both descendants match the base. |
General Comments 0
You need to be logged in to leave comments.
Login now