Show More
@@ -272,7 +272,7 b' def debugbuilddag(' | |||||
272 | x[fn].data() for x in (pa, p1, p2) |
|
272 | x[fn].data() for x in (pa, p1, p2) | |
273 | ] |
|
273 | ] | |
274 | m3 = simplemerge.Merge3Text(base, local, other) |
|
274 | m3 = simplemerge.Merge3Text(base, local, other) | |
275 |
ml = [l.strip() for l in |
|
275 | ml = [l.strip() for l in simplemerge.merge_lines(m3)[0]] | |
276 | ml.append(b"") |
|
276 | ml.append(b"") | |
277 | elif at > 0: |
|
277 | elif at > 0: | |
278 | ml = p1[fn].data().split(b"\n") |
|
278 | ml = p1[fn].data().split(b"\n") |
@@ -87,54 +87,6 b' class Merge3Text(object):' | |||||
87 | self.a = a |
|
87 | self.a = a | |
88 | self.b = b |
|
88 | self.b = b | |
89 |
|
89 | |||
90 | def merge_lines( |
|
|||
91 | self, |
|
|||
92 | name_a=None, |
|
|||
93 | name_b=None, |
|
|||
94 | name_base=None, |
|
|||
95 | start_marker=b'<<<<<<<', |
|
|||
96 | mid_marker=b'=======', |
|
|||
97 | end_marker=b'>>>>>>>', |
|
|||
98 | base_marker=None, |
|
|||
99 | minimize=False, |
|
|||
100 | ): |
|
|||
101 | """Return merge in cvs-like form.""" |
|
|||
102 | conflicts = False |
|
|||
103 | newline = b'\n' |
|
|||
104 | if len(self.a) > 0: |
|
|||
105 | if self.a[0].endswith(b'\r\n'): |
|
|||
106 | newline = b'\r\n' |
|
|||
107 | elif self.a[0].endswith(b'\r'): |
|
|||
108 | newline = b'\r' |
|
|||
109 | if name_a and start_marker: |
|
|||
110 | start_marker = start_marker + b' ' + name_a |
|
|||
111 | if name_b and end_marker: |
|
|||
112 | end_marker = end_marker + b' ' + name_b |
|
|||
113 | if name_base and base_marker: |
|
|||
114 | base_marker = base_marker + b' ' + name_base |
|
|||
115 | merge_groups = self.merge_groups() |
|
|||
116 | if minimize: |
|
|||
117 | merge_groups = self.minimize(merge_groups) |
|
|||
118 | lines = [] |
|
|||
119 | for what, group_lines in merge_groups: |
|
|||
120 | if what == b'conflict': |
|
|||
121 | base_lines, a_lines, b_lines = group_lines |
|
|||
122 | conflicts = True |
|
|||
123 | if start_marker is not None: |
|
|||
124 | lines.append(start_marker + newline) |
|
|||
125 | lines.extend(a_lines) |
|
|||
126 | if base_marker is not None: |
|
|||
127 | lines.append(base_marker + newline) |
|
|||
128 | lines.extend(base_lines) |
|
|||
129 | if mid_marker is not None: |
|
|||
130 | lines.append(mid_marker + newline) |
|
|||
131 | lines.extend(b_lines) |
|
|||
132 | if end_marker is not None: |
|
|||
133 | lines.append(end_marker + newline) |
|
|||
134 | else: |
|
|||
135 | lines.extend(group_lines) |
|
|||
136 | return lines, conflicts |
|
|||
137 |
|
||||
138 | def merge_groups(self): |
|
90 | def merge_groups(self): | |
139 | """Yield sequence of line groups. Each one is a tuple: |
|
91 | """Yield sequence of line groups. Each one is a tuple: | |
140 |
|
92 | |||
@@ -389,6 +341,55 b' def _picklabels(defaults, overrides):' | |||||
389 | return result |
|
341 | return result | |
390 |
|
342 | |||
391 |
|
343 | |||
|
344 | def merge_lines( | |||
|
345 | m3, | |||
|
346 | name_a=None, | |||
|
347 | name_b=None, | |||
|
348 | name_base=None, | |||
|
349 | start_marker=b'<<<<<<<', | |||
|
350 | mid_marker=b'=======', | |||
|
351 | end_marker=b'>>>>>>>', | |||
|
352 | base_marker=None, | |||
|
353 | minimize=False, | |||
|
354 | ): | |||
|
355 | """Return merge in cvs-like form.""" | |||
|
356 | conflicts = False | |||
|
357 | newline = b'\n' | |||
|
358 | if len(m3.a) > 0: | |||
|
359 | if m3.a[0].endswith(b'\r\n'): | |||
|
360 | newline = b'\r\n' | |||
|
361 | elif m3.a[0].endswith(b'\r'): | |||
|
362 | newline = b'\r' | |||
|
363 | if name_a and start_marker: | |||
|
364 | start_marker = start_marker + b' ' + name_a | |||
|
365 | if name_b and end_marker: | |||
|
366 | end_marker = end_marker + b' ' + name_b | |||
|
367 | if name_base and base_marker: | |||
|
368 | base_marker = base_marker + b' ' + name_base | |||
|
369 | merge_groups = m3.merge_groups() | |||
|
370 | if minimize: | |||
|
371 | merge_groups = m3.minimize(merge_groups) | |||
|
372 | lines = [] | |||
|
373 | for what, group_lines in merge_groups: | |||
|
374 | if what == b'conflict': | |||
|
375 | base_lines, a_lines, b_lines = group_lines | |||
|
376 | conflicts = True | |||
|
377 | if start_marker is not None: | |||
|
378 | lines.append(start_marker + newline) | |||
|
379 | lines.extend(a_lines) | |||
|
380 | if base_marker is not None: | |||
|
381 | lines.append(base_marker + newline) | |||
|
382 | lines.extend(base_lines) | |||
|
383 | if mid_marker is not None: | |||
|
384 | lines.append(mid_marker + newline) | |||
|
385 | lines.extend(b_lines) | |||
|
386 | if end_marker is not None: | |||
|
387 | lines.append(end_marker + newline) | |||
|
388 | else: | |||
|
389 | lines.extend(group_lines) | |||
|
390 | return lines, conflicts | |||
|
391 | ||||
|
392 | ||||
392 | def _mergediff(m3, name_a, name_b, name_base): |
|
393 | def _mergediff(m3, name_a, name_b, name_base): | |
393 | lines = [] |
|
394 | lines = [] | |
394 | conflicts = False |
|
395 | conflicts = False | |
@@ -508,8 +509,8 b' def simplemerge(ui, localctx, basectx, o' | |||||
508 | extrakwargs['base_marker'] = b'|||||||' |
|
509 | extrakwargs['base_marker'] = b'|||||||' | |
509 | extrakwargs['name_base'] = name_base |
|
510 | extrakwargs['name_base'] = name_base | |
510 | extrakwargs['minimize'] = False |
|
511 | extrakwargs['minimize'] = False | |
511 |
lines, conflicts = |
|
512 | lines, conflicts = merge_lines( | |
512 | name_a=name_a, name_b=name_b, **extrakwargs |
|
513 | m3, name_a=name_a, name_b=name_b, **extrakwargs | |
513 | ) |
|
514 | ) | |
514 |
|
515 | |||
515 | mergedtext = b''.join(lines) |
|
516 | mergedtext = b''.join(lines) |
@@ -179,7 +179,7 b' class TestMerge3(TestCase):' | |||||
179 |
|
179 | |||
180 | self.assertEqual(list(m3.merge_regions()), [(b'a', 0, 2)]) |
|
180 | self.assertEqual(list(m3.merge_regions()), [(b'a', 0, 2)]) | |
181 |
|
181 | |||
182 |
self.assertEqual( |
|
182 | self.assertEqual(simplemerge.merge_lines(m3), ([b'aaa', b'bbb'], False)) | |
183 |
|
183 | |||
184 | def test_no_conflicts(self): |
|
184 | def test_no_conflicts(self): | |
185 | """No conflicts because only one side changed""" |
|
185 | """No conflicts because only one side changed""" | |
@@ -204,7 +204,9 b' class TestMerge3(TestCase):' | |||||
204 | [b'aaa\n', b'bbb\n'], |
|
204 | [b'aaa\n', b'bbb\n'], | |
205 | ) |
|
205 | ) | |
206 |
|
206 | |||
207 | self.assertEqual(b''.join(m3.merge_lines()[0]), b'aaa\nbbb\n222\n') |
|
207 | self.assertEqual( | |
|
208 | b''.join(simplemerge.merge_lines(m3)[0]), b'aaa\nbbb\n222\n' | |||
|
209 | ) | |||
208 |
|
210 | |||
209 | def test_append_b(self): |
|
211 | def test_append_b(self): | |
210 | m3 = Merge3( |
|
212 | m3 = Merge3( | |
@@ -213,7 +215,9 b' class TestMerge3(TestCase):' | |||||
213 | [b'aaa\n', b'bbb\n', b'222\n'], |
|
215 | [b'aaa\n', b'bbb\n', b'222\n'], | |
214 | ) |
|
216 | ) | |
215 |
|
217 | |||
216 | self.assertEqual(b''.join(m3.merge_lines()[0]), b'aaa\nbbb\n222\n') |
|
218 | self.assertEqual( | |
|
219 | b''.join(simplemerge.merge_lines(m3)[0]), b'aaa\nbbb\n222\n' | |||
|
220 | ) | |||
217 |
|
221 | |||
218 | def test_append_agreement(self): |
|
222 | def test_append_agreement(self): | |
219 | m3 = Merge3( |
|
223 | m3 = Merge3( | |
@@ -222,7 +226,9 b' class TestMerge3(TestCase):' | |||||
222 | [b'aaa\n', b'bbb\n', b'222\n'], |
|
226 | [b'aaa\n', b'bbb\n', b'222\n'], | |
223 | ) |
|
227 | ) | |
224 |
|
228 | |||
225 | self.assertEqual(b''.join(m3.merge_lines()[0]), b'aaa\nbbb\n222\n') |
|
229 | self.assertEqual( | |
|
230 | b''.join(simplemerge.merge_lines(m3)[0]), b'aaa\nbbb\n222\n' | |||
|
231 | ) | |||
226 |
|
232 | |||
227 | def test_append_clash(self): |
|
233 | def test_append_clash(self): | |
228 | m3 = Merge3( |
|
234 | m3 = Merge3( | |
@@ -231,7 +237,8 b' class TestMerge3(TestCase):' | |||||
231 | [b'aaa\n', b'bbb\n', b'333\n'], |
|
237 | [b'aaa\n', b'bbb\n', b'333\n'], | |
232 | ) |
|
238 | ) | |
233 |
|
239 | |||
234 |
ml, conflicts = |
|
240 | ml, conflicts = simplemerge.merge_lines( | |
|
241 | m3, | |||
235 | name_a=b'a', |
|
242 | name_a=b'a', | |
236 | name_b=b'b', |
|
243 | name_b=b'b', | |
237 | start_marker=b'<<', |
|
244 | start_marker=b'<<', | |
@@ -250,7 +257,8 b' class TestMerge3(TestCase):' | |||||
250 | [b'aaa\n', b'222\n', b'bbb\n'], |
|
257 | [b'aaa\n', b'222\n', b'bbb\n'], | |
251 | ) |
|
258 | ) | |
252 |
|
259 | |||
253 |
ml, conflicts = |
|
260 | ml, conflicts = simplemerge.merge_lines( | |
|
261 | m3, | |||
254 | name_a=b'a', |
|
262 | name_a=b'a', | |
255 | name_b=b'b', |
|
263 | name_b=b'b', | |
256 | start_marker=b'<<', |
|
264 | start_marker=b'<<', | |
@@ -290,7 +298,8 b' class TestMerge3(TestCase):' | |||||
290 | ], |
|
298 | ], | |
291 | ) |
|
299 | ) | |
292 |
|
300 | |||
293 |
ml, conflicts = |
|
301 | ml, conflicts = simplemerge.merge_lines( | |
|
302 | m3, | |||
294 | name_a=b'a', |
|
303 | name_a=b'a', | |
295 | name_b=b'b', |
|
304 | name_b=b'b', | |
296 | start_marker=b'<<', |
|
305 | start_marker=b'<<', | |
@@ -338,7 +347,7 b' bbb' | |||||
338 | def test_merge_poem(self): |
|
347 | def test_merge_poem(self): | |
339 | """Test case from diff3 manual""" |
|
348 | """Test case from diff3 manual""" | |
340 | m3 = Merge3(TZU, LAO, TAO) |
|
349 | m3 = Merge3(TZU, LAO, TAO) | |
341 |
ml, conflicts = |
|
350 | ml, conflicts = simplemerge.merge_lines(m3, b'LAO', b'TAO') | |
342 | self.log(b'merge result:') |
|
351 | self.log(b'merge result:') | |
343 | self.log(b''.join(ml)) |
|
352 | self.log(b''.join(ml)) | |
344 | self.assertEqual(ml, MERGED_RESULT) |
|
353 | self.assertEqual(ml, MERGED_RESULT) | |
@@ -356,7 +365,7 b' bbb' | |||||
356 | other_text.splitlines(True), |
|
365 | other_text.splitlines(True), | |
357 | this_text.splitlines(True), |
|
366 | this_text.splitlines(True), | |
358 | ) |
|
367 | ) | |
359 |
m_lines, conflicts = |
|
368 | m_lines, conflicts = simplemerge.merge_lines(m3, b'OTHER', b'THIS') | |
360 | self.assertEqual( |
|
369 | self.assertEqual( | |
361 | b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n' |
|
370 | b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n' | |
362 | b'>>>>>>> THIS\r\n'.splitlines(True), |
|
371 | b'>>>>>>> THIS\r\n'.splitlines(True), | |
@@ -372,7 +381,7 b' bbb' | |||||
372 | other_text.splitlines(True), |
|
381 | other_text.splitlines(True), | |
373 | this_text.splitlines(True), |
|
382 | this_text.splitlines(True), | |
374 | ) |
|
383 | ) | |
375 |
m_lines, conflicts = |
|
384 | m_lines, conflicts = simplemerge.merge_lines(m3, b'OTHER', b'THIS') | |
376 | self.assertEqual( |
|
385 | self.assertEqual( | |
377 | b'<<<<<<< OTHER\rc\r=======\rb\r' |
|
386 | b'<<<<<<< OTHER\rc\r=======\rb\r' | |
378 | b'>>>>>>> THIS\r'.splitlines(True), |
|
387 | b'>>>>>>> THIS\r'.splitlines(True), |
General Comments 0
You need to be logged in to leave comments.
Login now