##// END OF EJS Templates
filemerge: make the 'local' path match the format that 'base' and 'other' use...
Kyle Lippincott -
r37095:1e30a26a default
parent child Browse files
Show More
@@ -512,8 +512,11 b' def _xmerge(repo, mynode, orig, fcd, fco'
512 512 return False, 1, None
513 513 unused, unused, unused, back = files
514 514 localpath = _workingpath(repo, fcd)
515 with _maketempfiles(repo, fco, fca) as temppaths:
516 basepath, otherpath = temppaths
515 args = _toolstr(repo.ui, tool, "args")
516
517 with _maketempfiles(repo, fco, fca, repo.wvfs.join(back.path()),
518 "$output" in args) as temppaths:
519 basepath, otherpath, localoutputpath = temppaths
517 520 outpath = ""
518 521 mylabel, otherlabel = labels[:2]
519 522 if len(labels) >= 3:
@@ -533,11 +536,10 b' def _xmerge(repo, mynode, orig, fcd, fco'
533 536 }
534 537 ui = repo.ui
535 538
536 args = _toolstr(ui, tool, "args")
537 539 if "$output" in args:
538 540 # read input from backup, write to original
539 541 outpath = localpath
540 localpath = repo.wvfs.join(back.path())
542 localpath = localoutputpath
541 543 replace = {'local': localpath, 'base': basepath, 'other': otherpath,
542 544 'output': outpath, 'labellocal': mylabel,
543 545 'labelother': otherlabel, 'labelbase': baselabel}
@@ -665,17 +667,18 b' def _makebackup(repo, ui, wctx, fcd, pre'
665 667 return context.arbitraryfilectx(back, repo=repo)
666 668
667 669 @contextlib.contextmanager
668 def _maketempfiles(repo, fco, fca):
669 """Writes out `fco` and `fca` as temporary files, so an external merge
670 tool may use them.
670 def _maketempfiles(repo, fco, fca, localpath, uselocalpath):
671 """Writes out `fco` and `fca` as temporary files, and (if uselocalpath)
672 copies `localpath` to another temporary file, so an external merge tool may
673 use them.
671 674 """
672 675 tmproot = None
673 676 tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix')
674 677 if tmprootprefix:
675 678 tmproot = tempfile.mkdtemp(prefix=tmprootprefix)
676 679
677 def temp(prefix, ctx):
678 fullbase, ext = os.path.splitext(ctx.path())
680 def maketempfrompath(prefix, path):
681 fullbase, ext = os.path.splitext(path)
679 682 pre = "%s~%s" % (os.path.basename(fullbase), prefix)
680 683 if tmproot:
681 684 name = os.path.join(tmproot, pre)
@@ -683,23 +686,42 b' def _maketempfiles(repo, fco, fca):'
683 686 name += ext
684 687 f = open(name, r"wb")
685 688 else:
686 (fd, name) = tempfile.mkstemp(prefix=pre + '.', suffix=ext)
689 fd, name = tempfile.mkstemp(prefix=pre + '.', suffix=ext)
687 690 f = os.fdopen(fd, r"wb")
691 return f, name
692
693 def tempfromcontext(prefix, ctx):
694 f, name = maketempfrompath(prefix, ctx.path())
688 695 data = repo.wwritedata(ctx.path(), ctx.data())
689 696 f.write(data)
690 697 f.close()
691 698 return name
692 699
693 b = temp("base", fca)
694 c = temp("other", fco)
700 b = tempfromcontext("base", fca)
701 c = tempfromcontext("other", fco)
702 d = localpath
703 if uselocalpath:
704 # We start off with this being the backup filename, so remove the .orig
705 # to make syntax-highlighting more likely.
706 if d.endswith('.orig'):
707 d, _ = os.path.splitext(d)
708 f, d = maketempfrompath("local", d)
709 with open(localpath, 'rb') as src:
710 f.write(src.read())
711 f.close()
712
695 713 try:
696 yield b, c
714 yield b, c, d
697 715 finally:
698 716 if tmproot:
699 717 shutil.rmtree(tmproot)
700 718 else:
701 719 util.unlink(b)
702 720 util.unlink(c)
721 # if not uselocalpath, d is the 'orig'/backup file which we
722 # shouldn't delete.
723 if d and uselocalpath:
724 util.unlink(d)
703 725
704 726 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None):
705 727 """perform a 3-way merge in the working directory
@@ -1585,7 +1585,7 b' Verify naming of temporary files and tha'
1585 1585 $ hg update -q -C 2
1586 1586 $ hg merge -y -r tip --tool echo --config merge-tools.echo.args='$base $local $other $output'
1587 1587 merging f and f.txt to f.txt
1588 */f~base.* $TESTTMP/f.txt.orig */f~other.*.txt $TESTTMP/f.txt (glob)
1588 */f~base.* */f~local.*.txt */f~other.*.txt $TESTTMP/f.txt (glob)
1589 1589 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1590 1590 (branch merge, don't forget to commit)
1591 1591
@@ -1600,7 +1600,7 b' Verify naming of temporary files and tha'
1600 1600 > --config merge-tools.echo.args='$base $local $other $output' \
1601 1601 > --config experimental.mergetempdirprefix=$TESTTMP/hgmerge.
1602 1602 merging f and f.txt to f.txt
1603 $TESTTMP/hgmerge.*/f~base $TESTTMP/f.txt.orig $TESTTMP/hgmerge.*/f~other.txt $TESTTMP/f.txt (glob)
1603 $TESTTMP/hgmerge.*/f~base $TESTTMP/hgmerge.*/f~local.txt $TESTTMP/hgmerge.*/f~other.txt $TESTTMP/f.txt (glob)
1604 1604 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
1605 1605 (branch merge, don't forget to commit)
1606 1606
General Comments 0
You need to be logged in to leave comments. Login now