Mercurial > hg
comparison mercurial/simplemerge.py @ 48559:b5e1283c0475
simplemerge: use same newline detection for :mergediff as for :merge[3]
The `:merge` and `:merge3` markers used the newline style detected
from the base input. The `:mergediff` style always used LF as newline
character. This patch teaches `:mergediff` to use the same detection
as the others did.
Differential Revision: https://phab.mercurial-scm.org/D11976
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 07 Jan 2022 22:23:44 -0800 |
parents | 2dbee604a4f0 |
children | 6ad70879d2bd |
comparison
equal
deleted
inserted
replaced
48558:2dbee604a4f0 | 48559:b5e1283c0475 |
---|---|
339 for i, override in enumerate(overrides): | 339 for i, override in enumerate(overrides): |
340 result[i] = override | 340 result[i] = override |
341 return result | 341 return result |
342 | 342 |
343 | 343 |
344 def _detect_newline(m3): | |
345 if len(m3.a) > 0: | |
346 if m3.a[0].endswith(b'\r\n'): | |
347 return b'\r\n' | |
348 elif m3.a[0].endswith(b'\r'): | |
349 return b'\r' | |
350 return b'\n' | |
351 | |
352 | |
344 def render_markers( | 353 def render_markers( |
345 m3, | 354 m3, |
346 name_a=None, | 355 name_a=None, |
347 name_b=None, | 356 name_b=None, |
348 name_base=None, | 357 name_base=None, |
351 end_marker=b'>>>>>>>', | 360 end_marker=b'>>>>>>>', |
352 base_marker=None, | 361 base_marker=None, |
353 minimize=False, | 362 minimize=False, |
354 ): | 363 ): |
355 """Return merge in cvs-like form.""" | 364 """Return merge in cvs-like form.""" |
365 newline = _detect_newline(m3) | |
356 conflicts = False | 366 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: | 367 if name_a and start_marker: |
364 start_marker = start_marker + b' ' + name_a | 368 start_marker = start_marker + b' ' + name_a |
365 if name_b and end_marker: | 369 if name_b and end_marker: |
366 end_marker = end_marker + b' ' + name_b | 370 end_marker = end_marker + b' ' + name_b |
367 if name_base and base_marker: | 371 if name_base and base_marker: |
389 lines.extend(group_lines) | 393 lines.extend(group_lines) |
390 return lines, conflicts | 394 return lines, conflicts |
391 | 395 |
392 | 396 |
393 def render_mergediff(m3, name_a, name_b, name_base): | 397 def render_mergediff(m3, name_a, name_b, name_base): |
398 newline = _detect_newline(m3) | |
394 lines = [] | 399 lines = [] |
395 conflicts = False | 400 conflicts = False |
396 for what, group_lines in m3.merge_groups(): | 401 for what, group_lines in m3.merge_groups(): |
397 if what == b'conflict': | 402 if what == b'conflict': |
398 base_lines, a_lines, b_lines = group_lines | 403 base_lines, a_lines, b_lines = group_lines |
430 for line in lines1[block[0] : block[1]]: | 435 for line in lines1[block[0] : block[1]]: |
431 yield b'-' + line | 436 yield b'-' + line |
432 for line in lines2[block[2] : block[3]]: | 437 for line in lines2[block[2] : block[3]]: |
433 yield b'+' + line | 438 yield b'+' + line |
434 | 439 |
435 lines.append(b"<<<<<<<\n") | 440 lines.append(b"<<<<<<<" + newline) |
436 if matching_lines(a_blocks) < matching_lines(b_blocks): | 441 if matching_lines(a_blocks) < matching_lines(b_blocks): |
437 lines.append(b"======= %s\n" % name_a) | 442 lines.append(b"======= " + name_a + newline) |
438 lines.extend(a_lines) | 443 lines.extend(a_lines) |
439 lines.append(b"------- %s\n" % name_base) | 444 lines.append(b"------- " + name_base + newline) |
440 lines.append(b"+++++++ %s\n" % name_b) | 445 lines.append(b"+++++++ " + name_b + newline) |
441 lines.extend(diff_lines(b_blocks, base_lines, b_lines)) | 446 lines.extend(diff_lines(b_blocks, base_lines, b_lines)) |
442 else: | 447 else: |
443 lines.append(b"------- %s\n" % name_base) | 448 lines.append(b"------- " + name_base + newline) |
444 lines.append(b"+++++++ %s\n" % name_a) | 449 lines.append(b"+++++++ " + name_a + newline) |
445 lines.extend(diff_lines(a_blocks, base_lines, a_lines)) | 450 lines.extend(diff_lines(a_blocks, base_lines, a_lines)) |
446 lines.append(b"======= %s\n" % name_b) | 451 lines.append(b"======= " + name_b + newline) |
447 lines.extend(b_lines) | 452 lines.extend(b_lines) |
448 lines.append(b">>>>>>>\n") | 453 lines.append(b">>>>>>>" + newline) |
449 conflicts = True | 454 conflicts = True |
450 else: | 455 else: |
451 lines.extend(group_lines) | 456 lines.extend(group_lines) |
452 return lines, conflicts | 457 return lines, conflicts |
453 | 458 |