921 None) copies `localpath` to another temporary file, so an external merge |
920 None) copies `localpath` to another temporary file, so an external merge |
922 tool may use them. |
921 tool may use them. |
923 """ |
922 """ |
924 tmproot = pycompat.mkdtemp(prefix=b'hgmerge-') |
923 tmproot = pycompat.mkdtemp(prefix=b'hgmerge-') |
925 |
924 |
926 def maketempfrompath(prefix, path): |
925 def maketempfrompath(prefix, path, data): |
927 fullbase, ext = os.path.splitext(path) |
926 fullbase, ext = os.path.splitext(path) |
928 pre = b"%s~%s" % (os.path.basename(fullbase), prefix) |
927 pre = b"%s~%s" % (os.path.basename(fullbase), prefix) |
929 name = os.path.join(tmproot, pre) |
928 name = os.path.join(tmproot, pre) |
930 if ext: |
929 if ext: |
931 name += ext |
930 name += ext |
932 f = open(name, "wb") |
931 util.writefile(name, data) |
933 return f, name |
932 return name |
934 |
933 |
935 def tempfromcontext(prefix, ctx): |
934 def tempfromcontext(prefix, ctx): |
936 f, name = maketempfrompath(prefix, ctx.path()) |
935 return maketempfrompath(prefix, ctx.path(), ctx.decodeddata()) |
937 data = ctx.decodeddata() |
|
938 f.write(data) |
|
939 f.close() |
|
940 return name |
|
941 |
936 |
942 b = tempfromcontext(b"base", fca) |
937 b = tempfromcontext(b"base", fca) |
943 c = tempfromcontext(b"other", fco) |
938 c = tempfromcontext(b"other", fco) |
944 d = localpath |
939 d = localpath |
945 if localpath is not None: |
940 if localpath is not None: |
946 f, d = maketempfrompath(b"local", d) |
|
947 data = util.readfile(localpath) |
941 data = util.readfile(localpath) |
948 f.write(data) |
942 d = maketempfrompath(b"local", localpath, data) |
949 f.close() |
|
950 |
943 |
951 try: |
944 try: |
952 yield b, c, d |
945 yield b, c, d |
953 finally: |
946 finally: |
954 shutil.rmtree(tmproot) |
947 shutil.rmtree(tmproot) |