comparison mercurial/filemerge.py @ 48785:b53f2f5a18de

filemerge: move removal of `.orig` extension on temp file close to context The place where the `.orig` extension is removed in `_maketempfiles()` doesn't make it clear that it's the backup path, which is why we have a comment in the code explaining it. Let's instead move it out of the function and close to where we get it from `backup.path()`, so that becomes clear. Differential Revision: https://phab.mercurial-scm.org/D12190
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 14 Feb 2022 22:04:50 -0800
parents 9d0d0a388c39
children f20feb496d3c
comparison
equal deleted inserted replaced
48784:9d0d0a388c39 48785:b53f2f5a18de
744 localpath = _workingpath(repo, fcd) 744 localpath = _workingpath(repo, fcd)
745 args = _toolstr(repo.ui, tool, b"args") 745 args = _toolstr(repo.ui, tool, b"args")
746 localoutputpath = None 746 localoutputpath = None
747 if b"$output" in args: 747 if b"$output" in args:
748 localoutputpath = backup.path() 748 localoutputpath = backup.path()
749 # Remove the .orig to make syntax-highlighting more likely.
750 if localoutputpath.endswith(b'.orig'):
751 localoutputpath, ext = os.path.splitext(localoutputpath)
749 752
750 with _maketempfiles( 753 with _maketempfiles(
751 fco, 754 fco,
752 fca, 755 fca,
753 localoutputpath, 756 localoutputpath,
938 941
939 b = tempfromcontext(b"base", fca) 942 b = tempfromcontext(b"base", fca)
940 c = tempfromcontext(b"other", fco) 943 c = tempfromcontext(b"other", fco)
941 d = localpath 944 d = localpath
942 if localpath is not None: 945 if localpath is not None:
943 # We start off with this being the backup filename, so remove the .orig
944 # to make syntax-highlighting more likely.
945 if d.endswith(b'.orig'):
946 d, _ = os.path.splitext(d)
947 f, d = maketempfrompath(b"local", d) 946 f, d = maketempfrompath(b"local", d)
948 with open(localpath, b'rb') as src: 947 with open(localpath, b'rb') as src:
949 f.write(src.read()) 948 f.write(src.read())
950 f.close() 949 f.close()
951 950