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