##// END OF EJS Templates
simplemerge: simplify and rename `render_markers()`...
Martin von Zweigbergk -
r49411:12ac4401 default
parent child Browse files
Show More
@@ -273,7 +273,8 b' def debugbuilddag('
273 ]
273 ]
274 m3 = simplemerge.Merge3Text(base, local, other)
274 m3 = simplemerge.Merge3Text(base, local, other)
275 ml = [
275 ml = [
276 l.strip() for l in simplemerge.render_markers(m3)[0]
276 l.strip()
277 for l in simplemerge.render_minimized(m3)[0]
277 ]
278 ]
278 ml.append(b"")
279 ml.append(b"")
279 elif at > 0:
280 elif at > 0:
@@ -350,37 +350,32 b' def _detect_newline(m3):'
350 return b'\n'
350 return b'\n'
351
351
352
352
353 def render_markers(
353 def render_minimized(
354 m3,
354 m3,
355 name_a=None,
355 name_a=None,
356 name_b=None,
356 name_b=None,
357 start_marker=b'<<<<<<<',
357 start_marker=b'<<<<<<<',
358 mid_marker=b'=======',
358 mid_marker=b'=======',
359 end_marker=b'>>>>>>>',
359 end_marker=b'>>>>>>>',
360 minimize=False,
361 ):
360 ):
362 """Return merge in cvs-like form."""
361 """Return merge in cvs-like form."""
363 newline = _detect_newline(m3)
362 newline = _detect_newline(m3)
364 conflicts = False
363 conflicts = False
365 if name_a and start_marker:
364 if name_a:
366 start_marker = start_marker + b' ' + name_a
365 start_marker = start_marker + b' ' + name_a
367 if name_b and end_marker:
366 if name_b:
368 end_marker = end_marker + b' ' + name_b
367 end_marker = end_marker + b' ' + name_b
369 merge_groups = m3.merge_groups()
368 merge_groups = m3.merge_groups()
370 if minimize:
371 merge_groups = m3.minimize(merge_groups)
369 merge_groups = m3.minimize(merge_groups)
372 lines = []
370 lines = []
373 for what, group_lines in merge_groups:
371 for what, group_lines in merge_groups:
374 if what == b'conflict':
372 if what == b'conflict':
375 base_lines, a_lines, b_lines = group_lines
373 base_lines, a_lines, b_lines = group_lines
376 conflicts = True
374 conflicts = True
377 if start_marker is not None:
378 lines.append(start_marker + newline)
375 lines.append(start_marker + newline)
379 lines.extend(a_lines)
376 lines.extend(a_lines)
380 if mid_marker is not None:
381 lines.append(mid_marker + newline)
377 lines.append(mid_marker + newline)
382 lines.extend(b_lines)
378 lines.extend(b_lines)
383 if end_marker is not None:
384 lines.append(end_marker + newline)
379 lines.append(end_marker + newline)
385 else:
380 else:
386 lines.extend(group_lines)
381 lines.extend(group_lines)
@@ -522,12 +517,7 b' def simplemerge(ui, localctx, basectx, o'
522 elif mode == b'merge3':
517 elif mode == b'merge3':
523 lines, conflicts = render_merge3(m3, name_a, name_b, name_base)
518 lines, conflicts = render_merge3(m3, name_a, name_b, name_base)
524 else:
519 else:
525 extrakwargs = {
520 lines, conflicts = render_minimized(m3, name_a, name_b)
526 'minimize': True,
527 }
528 lines, conflicts = render_markers(
529 m3, name_a=name_a, name_b=name_b, **extrakwargs
530 )
531
521
532 mergedtext = b''.join(lines)
522 mergedtext = b''.join(lines)
533 if opts.get('print'):
523 if opts.get('print'):
@@ -180,7 +180,7 b' class TestMerge3(TestCase):'
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(
183 simplemerge.render_markers(m3), ([b'aaa', b'bbb'], False)
183 simplemerge.render_minimized(m3), ([b'aaa', b'bbb'], False)
184 )
184 )
185
185
186 def test_no_conflicts(self):
186 def test_no_conflicts(self):
@@ -207,7 +207,7 b' class TestMerge3(TestCase):'
207 )
207 )
208
208
209 self.assertEqual(
209 self.assertEqual(
210 b''.join(simplemerge.render_markers(m3)[0]), b'aaa\nbbb\n222\n'
210 b''.join(simplemerge.render_minimized(m3)[0]), b'aaa\nbbb\n222\n'
211 )
211 )
212
212
213 def test_append_b(self):
213 def test_append_b(self):
@@ -218,7 +218,7 b' class TestMerge3(TestCase):'
218 )
218 )
219
219
220 self.assertEqual(
220 self.assertEqual(
221 b''.join(simplemerge.render_markers(m3)[0]), b'aaa\nbbb\n222\n'
221 b''.join(simplemerge.render_minimized(m3)[0]), b'aaa\nbbb\n222\n'
222 )
222 )
223
223
224 def test_append_agreement(self):
224 def test_append_agreement(self):
@@ -229,7 +229,7 b' class TestMerge3(TestCase):'
229 )
229 )
230
230
231 self.assertEqual(
231 self.assertEqual(
232 b''.join(simplemerge.render_markers(m3)[0]), b'aaa\nbbb\n222\n'
232 b''.join(simplemerge.render_minimized(m3)[0]), b'aaa\nbbb\n222\n'
233 )
233 )
234
234
235 def test_append_clash(self):
235 def test_append_clash(self):
@@ -239,7 +239,7 b' class TestMerge3(TestCase):'
239 [b'aaa\n', b'bbb\n', b'333\n'],
239 [b'aaa\n', b'bbb\n', b'333\n'],
240 )
240 )
241
241
242 ml, conflicts = simplemerge.render_markers(
242 ml, conflicts = simplemerge.render_minimized(
243 m3,
243 m3,
244 name_a=b'a',
244 name_a=b'a',
245 name_b=b'b',
245 name_b=b'b',
@@ -259,7 +259,7 b' class TestMerge3(TestCase):'
259 [b'aaa\n', b'222\n', b'bbb\n'],
259 [b'aaa\n', b'222\n', b'bbb\n'],
260 )
260 )
261
261
262 ml, conflicts = simplemerge.render_markers(
262 ml, conflicts = simplemerge.render_minimized(
263 m3,
263 m3,
264 name_a=b'a',
264 name_a=b'a',
265 name_b=b'b',
265 name_b=b'b',
@@ -300,7 +300,7 b' class TestMerge3(TestCase):'
300 ],
300 ],
301 )
301 )
302
302
303 ml, conflicts = simplemerge.render_markers(
303 ml, conflicts = simplemerge.render_minimized(
304 m3,
304 m3,
305 name_a=b'a',
305 name_a=b'a',
306 name_b=b'b',
306 name_b=b'b',
@@ -349,7 +349,7 b' bbb'
349 def test_merge_poem(self):
349 def test_merge_poem(self):
350 """Test case from diff3 manual"""
350 """Test case from diff3 manual"""
351 m3 = Merge3(TZU, LAO, TAO)
351 m3 = Merge3(TZU, LAO, TAO)
352 ml, conflicts = simplemerge.render_markers(m3, b'LAO', b'TAO')
352 ml, conflicts = simplemerge.render_minimized(m3, b'LAO', b'TAO')
353 self.log(b'merge result:')
353 self.log(b'merge result:')
354 self.log(b''.join(ml))
354 self.log(b''.join(ml))
355 self.assertEqual(ml, MERGED_RESULT)
355 self.assertEqual(ml, MERGED_RESULT)
@@ -367,7 +367,7 b' bbb'
367 other_text.splitlines(True),
367 other_text.splitlines(True),
368 this_text.splitlines(True),
368 this_text.splitlines(True),
369 )
369 )
370 m_lines, conflicts = simplemerge.render_markers(m3, b'OTHER', b'THIS')
370 m_lines, conflicts = simplemerge.render_minimized(m3, b'OTHER', b'THIS')
371 self.assertEqual(
371 self.assertEqual(
372 b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
372 b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
373 b'>>>>>>> THIS\r\n'.splitlines(True),
373 b'>>>>>>> THIS\r\n'.splitlines(True),
@@ -383,7 +383,7 b' bbb'
383 other_text.splitlines(True),
383 other_text.splitlines(True),
384 this_text.splitlines(True),
384 this_text.splitlines(True),
385 )
385 )
386 m_lines, conflicts = simplemerge.render_markers(m3, b'OTHER', b'THIS')
386 m_lines, conflicts = simplemerge.render_minimized(m3, b'OTHER', b'THIS')
387 self.assertEqual(
387 self.assertEqual(
388 b'<<<<<<< OTHER\rc\r=======\rb\r'
388 b'<<<<<<< OTHER\rc\r=======\rb\r'
389 b'>>>>>>> THIS\r'.splitlines(True),
389 b'>>>>>>> THIS\r'.splitlines(True),
General Comments 0
You need to be logged in to leave comments. Login now