##// END OF EJS Templates
filemerge: make `_maketempfiles()` more reusable...
Martin von Zweigbergk -
r49637:f9033770 default
parent child Browse files
Show More
@@ -742,20 +742,26 b' def _xmerge(repo, mynode, local, other, '
742 742 return False, 1, None
743 743 localpath = _workingpath(repo, fcd)
744 744 args = _toolstr(repo.ui, tool, b"args")
745 localoutputpath = None
745
746 files = [
747 (b"base", fca.path(), fca.decodeddata()),
748 (b"other", fco.path(), fco.decodeddata()),
749 ]
750 outpath = b""
746 751 if b"$output" in args:
752 # read input from backup, write to original
753 outpath = localpath
747 754 localoutputpath = backup.path()
748 755 # Remove the .orig to make syntax-highlighting more likely.
749 756 if localoutputpath.endswith(b'.orig'):
750 757 localoutputpath, ext = os.path.splitext(localoutputpath)
758 localdata = util.readfile(localpath)
759 files.append((b"local", localoutputpath, localdata))
751 760
752 with _maketempfiles(
753 fco,
754 fca,
755 localoutputpath,
756 ) as temppaths:
757 basepath, otherpath, localoutputpath = temppaths
758 outpath = b""
761 with _maketempfiles(files) as temppaths:
762 basepath, otherpath = temppaths[:2]
763 if len(temppaths) == 3:
764 localpath = temppaths[2]
759 765
760 766 def format_label(input):
761 767 if input.label_detail:
@@ -777,10 +783,6 b' def _xmerge(repo, mynode, local, other, '
777 783 }
778 784 ui = repo.ui
779 785
780 if b"$output" in args:
781 # read input from backup, write to original
782 outpath = localpath
783 localpath = localoutputpath
784 786 replace = {
785 787 b'local': localpath,
786 788 b'base': basepath,
@@ -915,10 +917,9 b' def _makebackup(repo, ui, fcd):'
915 917
916 918
917 919 @contextlib.contextmanager
918 def _maketempfiles(fco, fca, localpath):
919 """Writes out `fco` and `fca` as temporary files, and (if localpath is not
920 None) copies `localpath` to another temporary file, so an external merge
921 tool may use them.
920 def _maketempfiles(files):
921 """Creates a temporary file for each (prefix, path, data) tuple in `files`,
922 so an external merge tool may use them.
922 923 """
923 924 tmproot = pycompat.mkdtemp(prefix=b'hgmerge-')
924 925
@@ -931,18 +932,11 b' def _maketempfiles(fco, fca, localpath):'
931 932 util.writefile(name, data)
932 933 return name
933 934
934 def tempfromcontext(prefix, ctx):
935 return maketempfrompath(prefix, ctx.path(), ctx.decodeddata())
936
937 b = tempfromcontext(b"base", fca)
938 c = tempfromcontext(b"other", fco)
939 d = localpath
940 if localpath is not None:
941 data = util.readfile(localpath)
942 d = maketempfrompath(b"local", localpath, data)
943
935 temp_files = []
936 for prefix, path, data in files:
937 temp_files.append(maketempfrompath(prefix, path, data))
944 938 try:
945 yield b, c, d
939 yield temp_files
946 940 finally:
947 941 shutil.rmtree(tmproot)
948 942
General Comments 0
You need to be logged in to leave comments. Login now