comparison mercurial/filemerge.py @ 48478:0994125a31e5

filemerge: remove `premerge` argument from `_makebackup()` We now always pass `True`, so there's no need to pass it. Differential Revision: https://phab.mercurial-scm.org/D11863
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 06 Dec 2021 12:30:54 -0800
parents f45a4a47f6a8
children a16eedf47843
comparison
equal deleted inserted replaced
48477:f45a4a47f6a8 48478:0994125a31e5
922 # TODO: Add a workingfilectx.write(otherfilectx) path so we can use 922 # TODO: Add a workingfilectx.write(otherfilectx) path so we can use
923 # util.copy here instead. 923 # util.copy here instead.
924 fcd.write(back.data(), fcd.flags()) 924 fcd.write(back.data(), fcd.flags())
925 925
926 926
927 def _makebackup(repo, ui, wctx, fcd, premerge): 927 def _makebackup(repo, ui, wctx, fcd):
928 """Makes and returns a filectx-like object for ``fcd``'s backup file. 928 """Makes and returns a filectx-like object for ``fcd``'s backup file.
929 929
930 In addition to preserving the user's pre-existing modifications to `fcd` 930 In addition to preserving the user's pre-existing modifications to `fcd`
931 (if any), the backup is used to undo certain premerges, confirm whether a 931 (if any), the backup is used to undo certain premerges, confirm whether a
932 merge changed anything, and determine what line endings the new file should 932 merge changed anything, and determine what line endings the new file should
933 have. 933 have.
934 934
935 Backups only need to be written once (right before the premerge) since their 935 Backups only need to be written once since their content doesn't change
936 content doesn't change afterwards. 936 afterwards.
937 """ 937 """
938 if fcd.isabsent(): 938 if fcd.isabsent():
939 return None 939 return None
940 # TODO: Break this import cycle somehow. (filectx -> ctx -> fileset -> 940 # TODO: Break this import cycle somehow. (filectx -> ctx -> fileset ->
941 # merge -> filemerge). (I suspect the fileset import is the weakest link) 941 # merge -> filemerge). (I suspect the fileset import is the weakest link)
948 if isinstance(fcd, context.overlayworkingfilectx) and inworkingdir: 948 if isinstance(fcd, context.overlayworkingfilectx) and inworkingdir:
949 # If the backup file is to be in the working directory, and we're 949 # If the backup file is to be in the working directory, and we're
950 # merging in-memory, we must redirect the backup to the memory context 950 # merging in-memory, we must redirect the backup to the memory context
951 # so we don't disturb the working directory. 951 # so we don't disturb the working directory.
952 relpath = back[len(repo.wvfs.base) + 1 :] 952 relpath = back[len(repo.wvfs.base) + 1 :]
953 if premerge: 953 wctx[relpath].write(fcd.data(), fcd.flags())
954 wctx[relpath].write(fcd.data(), fcd.flags())
955 return wctx[relpath] 954 return wctx[relpath]
956 else: 955 else:
957 if premerge: 956 # Otherwise, write to wherever path the user specified the backups
958 # Otherwise, write to wherever path the user specified the backups 957 # should go. We still need to switch based on whether the source is
959 # should go. We still need to switch based on whether the source is 958 # in-memory so we can use the fast path of ``util.copy`` if both are
960 # in-memory so we can use the fast path of ``util.copy`` if both are 959 # on disk.
961 # on disk. 960 if isinstance(fcd, context.overlayworkingfilectx):
962 if isinstance(fcd, context.overlayworkingfilectx): 961 util.writefile(back, fcd.data())
963 util.writefile(back, fcd.data()) 962 else:
964 else: 963 a = _workingpath(repo, fcd)
965 a = _workingpath(repo, fcd) 964 util.copyfile(a, back)
966 util.copyfile(a, back)
967 # A arbitraryfilectx is returned, so we can run the same functions on 965 # A arbitraryfilectx is returned, so we can run the same functions on
968 # the backup context regardless of where it lives. 966 # the backup context regardless of where it lives.
969 return context.arbitraryfilectx(back, repo=repo) 967 return context.arbitraryfilectx(back, repo=repo)
970 968
971 969
1119 b'in-memory merge does not support merge conflicts' 1117 b'in-memory merge does not support merge conflicts'
1120 ) 1118 )
1121 ui.warn(onfailure % fduipath) 1119 ui.warn(onfailure % fduipath)
1122 return True, 1, False 1120 return True, 1, False
1123 1121
1124 back = _makebackup(repo, ui, wctx, fcd, True) 1122 back = _makebackup(repo, ui, wctx, fcd)
1125 files = (None, None, None, back) 1123 files = (None, None, None, back)
1126 r = 1 1124 r = 1
1127 try: 1125 try:
1128 internalmarkerstyle = ui.config(b'ui', b'mergemarkers') 1126 internalmarkerstyle = ui.config(b'ui', b'mergemarkers')
1129 if isexternal: 1127 if isexternal: