666 @contextlib.contextmanager |
667 @contextlib.contextmanager |
667 def _maketempfiles(repo, fco, fca): |
668 def _maketempfiles(repo, fco, fca): |
668 """Writes out `fco` and `fca` as temporary files, so an external merge |
669 """Writes out `fco` and `fca` as temporary files, so an external merge |
669 tool may use them. |
670 tool may use them. |
670 """ |
671 """ |
|
672 tmproot = None |
|
673 tmprootprefix = repo.ui.config('experimental', 'mergetempdirprefix') |
|
674 if tmprootprefix: |
|
675 tmproot = tempfile.mkdtemp(prefix=tmprootprefix) |
|
676 |
671 def temp(prefix, ctx): |
677 def temp(prefix, ctx): |
672 fullbase, ext = os.path.splitext(ctx.path()) |
678 fullbase, ext = os.path.splitext(ctx.path()) |
673 pre = "%s~%s." % (os.path.basename(fullbase), prefix) |
679 pre = "%s~%s" % (os.path.basename(fullbase), prefix) |
674 (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext) |
680 if tmproot: |
|
681 name = os.path.join(tmproot, pre) |
|
682 if ext: |
|
683 name += ext |
|
684 f = open(name, r"wb") |
|
685 else: |
|
686 (fd, name) = tempfile.mkstemp(prefix=pre + '.', suffix=ext) |
|
687 f = os.fdopen(fd, r"wb") |
675 data = repo.wwritedata(ctx.path(), ctx.data()) |
688 data = repo.wwritedata(ctx.path(), ctx.data()) |
676 f = os.fdopen(fd, r"wb") |
|
677 f.write(data) |
689 f.write(data) |
678 f.close() |
690 f.close() |
679 return name |
691 return name |
680 |
692 |
681 b = temp("base", fca) |
693 b = temp("base", fca) |
682 c = temp("other", fco) |
694 c = temp("other", fco) |
683 try: |
695 try: |
684 yield b, c |
696 yield b, c |
685 finally: |
697 finally: |
686 util.unlink(b) |
698 if tmproot: |
687 util.unlink(c) |
699 shutil.rmtree(tmproot) |
|
700 else: |
|
701 util.unlink(b) |
|
702 util.unlink(c) |
688 |
703 |
689 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): |
704 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): |
690 """perform a 3-way merge in the working directory |
705 """perform a 3-way merge in the working directory |
691 |
706 |
692 premerge = whether this is a premerge |
707 premerge = whether this is a premerge |