comparison mercurial/filemerge.py @ 34034:7558917f291e

filemerge: add `_workingpath` This reduces any reliance on `a`. Differential Revision: https://phab.mercurial-scm.org/D401
author Phil Cohen <phillco@fb.com>
date Thu, 31 Aug 2017 11:28:59 -0700
parents d37f1bb68169
children 96123bdea43e
comparison
equal deleted inserted replaced
34033:d37f1bb68169 34034:7558917f291e
468 same directory as ``a.txt``. 468 same directory as ``a.txt``.
469 469
470 This implies permerge. Therefore, files aren't dumped, if premerge 470 This implies permerge. Therefore, files aren't dumped, if premerge
471 runs successfully. Use :forcedump to forcibly write files out. 471 runs successfully. Use :forcedump to forcibly write files out.
472 """ 472 """
473 a, unused, unused, unused = files 473 a = _workingpath(repo, fcd)
474
475 fd = fcd.path() 474 fd = fcd.path()
476 475
477 util.copyfile(a, a + ".local") 476 util.copyfile(a, a + ".local")
478 repo.wwrite(fd + ".other", fco.data(), fco.flags()) 477 repo.wwrite(fd + ".other", fco.data(), fco.flags())
479 repo.wwrite(fd + ".base", fca.data(), fca.flags()) 478 repo.wwrite(fd + ".base", fca.data(), fca.flags())
492 tool, toolpath, binary, symlink = toolconf 491 tool, toolpath, binary, symlink = toolconf
493 if fcd.isabsent() or fco.isabsent(): 492 if fcd.isabsent() or fco.isabsent():
494 repo.ui.warn(_('warning: %s cannot merge change/delete conflict ' 493 repo.ui.warn(_('warning: %s cannot merge change/delete conflict '
495 'for %s\n') % (tool, fcd.path())) 494 'for %s\n') % (tool, fcd.path()))
496 return False, 1, None 495 return False, 1, None
497 a, b, c, back = files 496 unused, b, c, back = files
497 a = _workingpath(repo, fcd)
498 out = "" 498 out = ""
499 env = {'HG_FILE': fcd.path(), 499 env = {'HG_FILE': fcd.path(),
500 'HG_MY_NODE': short(mynode), 500 'HG_MY_NODE': short(mynode),
501 'HG_OTHER_NODE': str(fco.changectx()), 501 'HG_OTHER_NODE': str(fco.changectx()),
502 'HG_BASE_NODE': str(fca.changectx()), 502 'HG_BASE_NODE': str(fca.changectx()),
595 have. 595 have.
596 """ 596 """
597 if fcd.isabsent(): 597 if fcd.isabsent():
598 return None 598 return None
599 599
600 a = repo.wjoin(fcd.path()) 600 a = _workingpath(repo, fcd)
601 back = scmutil.origpath(ui, repo, a) 601 back = scmutil.origpath(ui, repo, a)
602 if premerge: 602 if premerge:
603 util.copyfile(a, back) 603 util.copyfile(a, back)
604 return back 604 return back
605 605
703 703
704 needcheck, r, deleted = func(repo, mynode, orig, fcd, fco, fca, 704 needcheck, r, deleted = func(repo, mynode, orig, fcd, fco, fca,
705 toolconf, files, labels=labels) 705 toolconf, files, labels=labels)
706 706
707 if needcheck: 707 if needcheck:
708 r = _check(r, ui, tool, fcd, files) 708 r = _check(repo, r, ui, tool, fcd, files)
709 709
710 if r: 710 if r:
711 if onfailure: 711 if onfailure:
712 ui.warn(onfailure % fd) 712 ui.warn(onfailure % fd)
713 713
716 if not r and back is not None: 716 if not r and back is not None:
717 util.unlink(back) 717 util.unlink(back)
718 util.unlink(files[1]) 718 util.unlink(files[1])
719 util.unlink(files[2]) 719 util.unlink(files[2])
720 720
721 def _check(r, ui, tool, fcd, files): 721 def _check(repo, r, ui, tool, fcd, files):
722 fd = fcd.path() 722 fd = fcd.path()
723 a, unused, unused, back = files 723 unused, unused, unused, back = files
724 724
725 if not r and (_toolbool(ui, tool, "checkconflicts") or 725 if not r and (_toolbool(ui, tool, "checkconflicts") or
726 'conflicts' in _toollist(ui, tool, "check")): 726 'conflicts' in _toollist(ui, tool, "check")):
727 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(), 727 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
728 re.MULTILINE): 728 re.MULTILINE):
736 r = 1 736 r = 1
737 737
738 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or 738 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or
739 'changed' in 739 'changed' in
740 _toollist(ui, tool, "check")): 740 _toollist(ui, tool, "check")):
741 if back is not None and filecmp.cmp(a, back): 741 if back is not None and filecmp.cmp(_workingpath(repo, fcd), back):
742 if ui.promptchoice(_(" output file %s appears unchanged\n" 742 if ui.promptchoice(_(" output file %s appears unchanged\n"
743 "was merge successful (yn)?" 743 "was merge successful (yn)?"
744 "$$ &Yes $$ &No") % fd, 1): 744 "$$ &Yes $$ &No") % fd, 1):
745 r = 1 745 r = 1
746 746
747 if back is not None and _toolbool(ui, tool, "fixeol"): 747 if back is not None and _toolbool(ui, tool, "fixeol"):
748 _matcheol(a, back) 748 _matcheol(_workingpath(repo, fcd), back)
749 749
750 return r 750 return r
751
752 def _workingpath(repo, ctx):
753 return repo.wjoin(ctx.path())
751 754
752 def premerge(repo, mynode, orig, fcd, fco, fca, labels=None): 755 def premerge(repo, mynode, orig, fcd, fco, fca, labels=None):
753 return _filemerge(True, repo, mynode, orig, fcd, fco, fca, labels=labels) 756 return _filemerge(True, repo, mynode, orig, fcd, fco, fca, labels=labels)
754 757
755 def filemerge(repo, mynode, orig, fcd, fco, fca, labels=None): 758 def filemerge(repo, mynode, orig, fcd, fco, fca, labels=None):