Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 48505:40522aea2f27
filemerge: remove unused `orig` argument from tool functions
Differential Revision: https://phab.mercurial-scm.org/D11878
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 06 Dec 2021 13:43:00 -0800 |
parents | ba34141f8dbb |
children | 608a35db186c |
comparison
equal
deleted
inserted
replaced
48504:ba34141f8dbb | 48505:40522aea2f27 |
---|---|
304 if newdata != data: | 304 if newdata != data: |
305 util.writefile(file, newdata) | 305 util.writefile(file, newdata) |
306 | 306 |
307 | 307 |
308 @internaltool(b'prompt', nomerge) | 308 @internaltool(b'prompt', nomerge) |
309 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): | 309 def _iprompt(repo, mynode, fcd, fco, fca, toolconf, labels=None): |
310 """Asks the user which of the local `p1()` or the other `p2()` version to | 310 """Asks the user which of the local `p1()` or the other `p2()` version to |
311 keep as the merged version.""" | 311 keep as the merged version.""" |
312 ui = repo.ui | 312 ui = repo.ui |
313 fd = fcd.path() | 313 fd = fcd.path() |
314 uipathfn = scmutil.getuipathfn(repo) | 314 uipathfn = scmutil.getuipathfn(repo) |
345 2, | 345 2, |
346 ) | 346 ) |
347 choice = [b'local', b'other', b'unresolved'][index] | 347 choice = [b'local', b'other', b'unresolved'][index] |
348 | 348 |
349 if choice == b'other': | 349 if choice == b'other': |
350 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels) | 350 return _iother(repo, mynode, fcd, fco, fca, toolconf, labels) |
351 elif choice == b'local': | 351 elif choice == b'local': |
352 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf, labels) | 352 return _ilocal(repo, mynode, fcd, fco, fca, toolconf, labels) |
353 elif choice == b'unresolved': | 353 elif choice == b'unresolved': |
354 return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels) | 354 return _ifail(repo, mynode, fcd, fco, fca, toolconf, labels) |
355 except error.ResponseExpected: | 355 except error.ResponseExpected: |
356 ui.write(b"\n") | 356 ui.write(b"\n") |
357 return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels) | 357 return _ifail(repo, mynode, fcd, fco, fca, toolconf, labels) |
358 | 358 |
359 | 359 |
360 @internaltool(b'local', nomerge) | 360 @internaltool(b'local', nomerge) |
361 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): | 361 def _ilocal(repo, mynode, fcd, fco, fca, toolconf, labels=None): |
362 """Uses the local `p1()` version of files as the merged version.""" | 362 """Uses the local `p1()` version of files as the merged version.""" |
363 return 0, fcd.isabsent() | 363 return 0, fcd.isabsent() |
364 | 364 |
365 | 365 |
366 @internaltool(b'other', nomerge) | 366 @internaltool(b'other', nomerge) |
367 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): | 367 def _iother(repo, mynode, fcd, fco, fca, toolconf, labels=None): |
368 """Uses the other `p2()` version of files as the merged version.""" | 368 """Uses the other `p2()` version of files as the merged version.""" |
369 if fco.isabsent(): | 369 if fco.isabsent(): |
370 # local changed, remote deleted -- 'deleted' picked | 370 # local changed, remote deleted -- 'deleted' picked |
371 _underlyingfctxifabsent(fcd).remove() | 371 _underlyingfctxifabsent(fcd).remove() |
372 deleted = True | 372 deleted = True |
375 deleted = False | 375 deleted = False |
376 return 0, deleted | 376 return 0, deleted |
377 | 377 |
378 | 378 |
379 @internaltool(b'fail', nomerge) | 379 @internaltool(b'fail', nomerge) |
380 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): | 380 def _ifail(repo, mynode, fcd, fco, fca, toolconf, labels=None): |
381 """ | 381 """ |
382 Rather than attempting to merge files that were modified on both | 382 Rather than attempting to merge files that were modified on both |
383 branches, it marks them as unresolved. The resolve command must be | 383 branches, it marks them as unresolved. The resolve command must be |
384 used to resolve these conflicts.""" | 384 used to resolve these conflicts.""" |
385 # for change/delete conflicts write out the changed version, then fail | 385 # for change/delete conflicts write out the changed version, then fail |
439 # restore from backup and try again | 439 # restore from backup and try again |
440 _restorebackup(fcd, backup) | 440 _restorebackup(fcd, backup) |
441 return 1 # continue merging | 441 return 1 # continue merging |
442 | 442 |
443 | 443 |
444 def _mergecheck(repo, mynode, orig, fcd, fco, fca, toolconf): | 444 def _mergecheck(repo, mynode, fcd, fco, fca, toolconf): |
445 tool, toolpath, binary, symlink, scriptfn = toolconf | 445 tool, toolpath, binary, symlink, scriptfn = toolconf |
446 uipathfn = scmutil.getuipathfn(repo) | 446 uipathfn = scmutil.getuipathfn(repo) |
447 if symlink: | 447 if symlink: |
448 repo.ui.warn( | 448 repo.ui.warn( |
449 _(b'warning: internal %s cannot merge symlinks for %s\n') | 449 _(b'warning: internal %s cannot merge symlinks for %s\n') |
460 ) | 460 ) |
461 return False | 461 return False |
462 return True | 462 return True |
463 | 463 |
464 | 464 |
465 def _merge(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels, mode): | 465 def _merge(repo, mynode, fcd, fco, fca, toolconf, backup, labels, mode): |
466 """ | 466 """ |
467 Uses the internal non-interactive simple merge algorithm for merging | 467 Uses the internal non-interactive simple merge algorithm for merging |
468 files. It will fail if there are any conflicts and leave markers in | 468 files. It will fail if there are any conflicts and leave markers in |
469 the partially merged file. Markers will have two sections, one for each side | 469 the partially merged file. Markers will have two sections, one for each side |
470 of merge, unless mode equals 'union' which suppresses the markers.""" | 470 of merge, unless mode equals 'union' which suppresses the markers.""" |
481 b"warning: conflicts while merging %s! " | 481 b"warning: conflicts while merging %s! " |
482 b"(edit, then use 'hg resolve --mark')\n" | 482 b"(edit, then use 'hg resolve --mark')\n" |
483 ), | 483 ), |
484 precheck=_mergecheck, | 484 precheck=_mergecheck, |
485 ) | 485 ) |
486 def _iunion(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None): | 486 def _iunion(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
487 """ | 487 """ |
488 Uses the internal non-interactive simple merge algorithm for merging | 488 Uses the internal non-interactive simple merge algorithm for merging |
489 files. It will use both left and right sides for conflict regions. | 489 files. It will use both left and right sides for conflict regions. |
490 No markers are inserted.""" | 490 No markers are inserted.""" |
491 return _merge( | 491 return _merge( |
492 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels, b'union' | 492 repo, mynode, fcd, fco, fca, toolconf, backup, labels, b'union' |
493 ) | 493 ) |
494 | 494 |
495 | 495 |
496 @internaltool( | 496 @internaltool( |
497 b'merge', | 497 b'merge', |
500 b"warning: conflicts while merging %s! " | 500 b"warning: conflicts while merging %s! " |
501 b"(edit, then use 'hg resolve --mark')\n" | 501 b"(edit, then use 'hg resolve --mark')\n" |
502 ), | 502 ), |
503 precheck=_mergecheck, | 503 precheck=_mergecheck, |
504 ) | 504 ) |
505 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None): | 505 def _imerge(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
506 """ | 506 """ |
507 Uses the internal non-interactive simple merge algorithm for merging | 507 Uses the internal non-interactive simple merge algorithm for merging |
508 files. It will fail if there are any conflicts and leave markers in | 508 files. It will fail if there are any conflicts and leave markers in |
509 the partially merged file. Markers will have two sections, one for each side | 509 the partially merged file. Markers will have two sections, one for each side |
510 of merge.""" | 510 of merge.""" |
511 return _merge( | 511 return _merge( |
512 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels, b'merge' | 512 repo, mynode, fcd, fco, fca, toolconf, backup, labels, b'merge' |
513 ) | 513 ) |
514 | 514 |
515 | 515 |
516 @internaltool( | 516 @internaltool( |
517 b'merge3', | 517 b'merge3', |
520 b"warning: conflicts while merging %s! " | 520 b"warning: conflicts while merging %s! " |
521 b"(edit, then use 'hg resolve --mark')\n" | 521 b"(edit, then use 'hg resolve --mark')\n" |
522 ), | 522 ), |
523 precheck=_mergecheck, | 523 precheck=_mergecheck, |
524 ) | 524 ) |
525 def _imerge3(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None): | 525 def _imerge3(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
526 """ | 526 """ |
527 Uses the internal non-interactive simple merge algorithm for merging | 527 Uses the internal non-interactive simple merge algorithm for merging |
528 files. It will fail if there are any conflicts and leave markers in | 528 files. It will fail if there are any conflicts and leave markers in |
529 the partially merged file. Marker will have three sections, one from each | 529 the partially merged file. Marker will have three sections, one from each |
530 side of the merge and one for the base content.""" | 530 side of the merge and one for the base content.""" |
531 if not labels: | 531 if not labels: |
532 labels = _defaultconflictlabels | 532 labels = _defaultconflictlabels |
533 if len(labels) < 3: | 533 if len(labels) < 3: |
534 labels.append(b'base') | 534 labels.append(b'base') |
535 return _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels) | 535 return _imerge(repo, mynode, fcd, fco, fca, toolconf, backup, labels) |
536 | 536 |
537 | 537 |
538 @internaltool( | 538 @internaltool( |
539 b'merge3-lie-about-conflicts', | 539 b'merge3-lie-about-conflicts', |
540 fullmerge, | 540 fullmerge, |
561 b"warning: conflicts while merging %s! " | 561 b"warning: conflicts while merging %s! " |
562 b"(edit, then use 'hg resolve --mark')\n" | 562 b"(edit, then use 'hg resolve --mark')\n" |
563 ), | 563 ), |
564 precheck=_mergecheck, | 564 precheck=_mergecheck, |
565 ) | 565 ) |
566 def _imerge_diff( | 566 def _imerge_diff(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
567 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None | |
568 ): | |
569 """ | 567 """ |
570 Uses the internal non-interactive simple merge algorithm for merging | 568 Uses the internal non-interactive simple merge algorithm for merging |
571 files. It will fail if there are any conflicts and leave markers in | 569 files. It will fail if there are any conflicts and leave markers in |
572 the partially merged file. The marker will have two sections, one with the | 570 the partially merged file. The marker will have two sections, one with the |
573 content from one side of the merge, and one with a diff from the base | 571 content from one side of the merge, and one with a diff from the base |
575 if not labels: | 573 if not labels: |
576 labels = _defaultconflictlabels | 574 labels = _defaultconflictlabels |
577 if len(labels) < 3: | 575 if len(labels) < 3: |
578 labels.append(b'base') | 576 labels.append(b'base') |
579 return _merge( | 577 return _merge( |
580 repo, | 578 repo, mynode, fcd, fco, fca, toolconf, backup, labels, b'mergediff' |
581 mynode, | |
582 orig, | |
583 fcd, | |
584 fco, | |
585 fca, | |
586 toolconf, | |
587 backup, | |
588 labels, | |
589 b'mergediff', | |
590 ) | 579 ) |
591 | 580 |
592 | 581 |
593 def _imergeauto( | 582 def _imergeauto( |
594 repo, | 583 repo, |
595 mynode, | 584 mynode, |
596 orig, | |
597 fcd, | 585 fcd, |
598 fco, | 586 fco, |
599 fca, | 587 fca, |
600 toolconf, | 588 toolconf, |
601 backup, | 589 backup, |
637 b"automatic tag merging of %s failed! " | 625 b"automatic tag merging of %s failed! " |
638 b"(use 'hg resolve --tool :merge' or another merge " | 626 b"(use 'hg resolve --tool :merge' or another merge " |
639 b"tool of your choice)\n" | 627 b"tool of your choice)\n" |
640 ), | 628 ), |
641 ) | 629 ) |
642 def _itagmerge( | 630 def _itagmerge(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
643 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None | |
644 ): | |
645 """ | 631 """ |
646 Uses the internal tag merge algorithm (experimental). | 632 Uses the internal tag merge algorithm (experimental). |
647 """ | 633 """ |
648 success, status = tagmerge.merge(repo, fcd, fco, fca) | 634 success, status = tagmerge.merge(repo, fcd, fco, fca) |
649 return success, status, False | 635 return success, status, False |
650 | 636 |
651 | 637 |
652 @internaltool(b'dump', fullmerge, binary=True, symlink=True) | 638 @internaltool(b'dump', fullmerge, binary=True, symlink=True) |
653 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None): | 639 def _idump(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
654 """ | 640 """ |
655 Creates three versions of the files to merge, containing the | 641 Creates three versions of the files to merge, containing the |
656 contents of local, other and base. These files can then be used to | 642 contents of local, other and base. These files can then be used to |
657 perform a merge manually. If the file to be merged is named | 643 perform a merge manually. If the file to be merged is named |
658 ``a.txt``, these files will accordingly be named ``a.txt.local``, | 644 ``a.txt``, these files will accordingly be named ``a.txt.local``, |
677 repo.wwrite(fd + b".base", fca.data(), fca.flags()) | 663 repo.wwrite(fd + b".base", fca.data(), fca.flags()) |
678 return False, 1, False | 664 return False, 1, False |
679 | 665 |
680 | 666 |
681 @internaltool(b'forcedump', mergeonly, binary=True, symlink=True) | 667 @internaltool(b'forcedump', mergeonly, binary=True, symlink=True) |
682 def _forcedump( | 668 def _forcedump(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
683 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None | |
684 ): | |
685 """ | 669 """ |
686 Creates three versions of the files as same as :dump, but omits premerge. | 670 Creates three versions of the files as same as :dump, but omits premerge. |
687 """ | 671 """ |
688 return _idump( | 672 return _idump(repo, mynode, fcd, fco, fca, toolconf, backup, labels=labels) |
689 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=labels | 673 |
690 ) | 674 |
691 | 675 def _xmergeimm(repo, mynode, fcd, fco, fca, toolconf, backup, labels=None): |
692 | |
693 def _xmergeimm( | |
694 repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels=None | |
695 ): | |
696 # In-memory merge simply raises an exception on all external merge tools, | 676 # In-memory merge simply raises an exception on all external merge tools, |
697 # for now. | 677 # for now. |
698 # | 678 # |
699 # It would be possible to run most tools with temporary files, but this | 679 # It would be possible to run most tools with temporary files, but this |
700 # raises the question of what to do if the user only partially resolves the | 680 # raises the question of what to do if the user only partially resolves the |
758 ui, tmpl, defaults=templatekw.keywords, resources=tres | 738 ui, tmpl, defaults=templatekw.keywords, resources=tres |
759 ) | 739 ) |
760 ui.status(t.renderdefault(props)) | 740 ui.status(t.renderdefault(props)) |
761 | 741 |
762 | 742 |
763 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, backup, labels): | 743 def _xmerge(repo, mynode, fcd, fco, fca, toolconf, backup, labels): |
764 tool, toolpath, binary, symlink, scriptfn = toolconf | 744 tool, toolpath, binary, symlink, scriptfn = toolconf |
765 uipathfn = scmutil.getuipathfn(repo) | 745 uipathfn = scmutil.getuipathfn(repo) |
766 if fcd.isabsent() or fco.isabsent(): | 746 if fcd.isabsent() or fco.isabsent(): |
767 repo.ui.warn( | 747 repo.ui.warn( |
768 _(b'warning: %s cannot merge change/delete conflict for %s\n') | 748 _(b'warning: %s cannot merge change/delete conflict for %s\n') |
1107 isexternal = True | 1087 isexternal = True |
1108 | 1088 |
1109 toolconf = tool, toolpath, binary, symlink, scriptfn | 1089 toolconf = tool, toolpath, binary, symlink, scriptfn |
1110 | 1090 |
1111 if mergetype == nomerge: | 1091 if mergetype == nomerge: |
1112 r, deleted = func(repo, mynode, orig, fcd, fco, fca, toolconf, labels) | 1092 r, deleted = func(repo, mynode, fcd, fco, fca, toolconf, labels) |
1113 return True, r, deleted | 1093 return True, r, deleted |
1114 | 1094 |
1115 if orig != fco.path(): | 1095 if orig != fco.path(): |
1116 ui.status( | 1096 ui.status( |
1117 _(b"merging %s and %s to %s\n") | 1097 _(b"merging %s and %s to %s\n") |
1120 else: | 1100 else: |
1121 ui.status(_(b"merging %s\n") % fduipath) | 1101 ui.status(_(b"merging %s\n") % fduipath) |
1122 | 1102 |
1123 ui.debug(b"my %s other %s ancestor %s\n" % (fcd, fco, fca)) | 1103 ui.debug(b"my %s other %s ancestor %s\n" % (fcd, fco, fca)) |
1124 | 1104 |
1125 if precheck and not precheck(repo, mynode, orig, fcd, fco, fca, toolconf): | 1105 if precheck and not precheck(repo, mynode, fcd, fco, fca, toolconf): |
1126 if onfailure: | 1106 if onfailure: |
1127 if wctx.isinmemory(): | 1107 if wctx.isinmemory(): |
1128 raise error.InMemoryMergeConflictsError( | 1108 raise error.InMemoryMergeConflictsError( |
1129 b'in-memory merge does not support merge conflicts' | 1109 b'in-memory merge does not support merge conflicts' |
1130 ) | 1110 ) |
1173 return not r, r, False | 1153 return not r, r, False |
1174 | 1154 |
1175 needcheck, r, deleted = func( | 1155 needcheck, r, deleted = func( |
1176 repo, | 1156 repo, |
1177 mynode, | 1157 mynode, |
1178 orig, | |
1179 fcd, | 1158 fcd, |
1180 fco, | 1159 fco, |
1181 fca, | 1160 fca, |
1182 toolconf, | 1161 toolconf, |
1183 backup, | 1162 backup, |