Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/filemerge.py @ 48540:da38519cbd10
filemerge: rename backup variables from `back` to `backup`
`backup` seems like an obviously clearer name for something containing
something related to a backup.
Differential Revision: https://phab.mercurial-scm.org/D11876
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 06 Dec 2021 13:15:40 -0800 |
parents | a16eedf47843 |
children | ba34141f8dbb |
comparison
equal
deleted
inserted
replaced
48539:23ce9e7bf1e5 | 48540:da38519cbd10 |
---|---|
291 if b'\n' in data: # UNIX | 291 if b'\n' in data: # UNIX |
292 return b'\n' | 292 return b'\n' |
293 return None # unknown | 293 return None # unknown |
294 | 294 |
295 | 295 |
296 def _matcheol(file, back): | 296 def _matcheol(file, backup): |
297 """Convert EOL markers in a file to match origfile""" | 297 """Convert EOL markers in a file to match origfile""" |
298 tostyle = _eoltype(back.data()) # No repo.wread filters? | 298 tostyle = _eoltype(backup.data()) # No repo.wread filters? |
299 if tostyle: | 299 if tostyle: |
300 data = util.readfile(file) | 300 data = util.readfile(file) |
301 style = _eoltype(data) | 301 style = _eoltype(data) |
302 if style: | 302 if style: |
303 newdata = data.replace(style, tostyle) | 303 newdata = data.replace(style, tostyle) |
401 | 401 |
402 def _premerge(repo, fcd, fco, fca, toolconf, files, labels=None): | 402 def _premerge(repo, fcd, fco, fca, toolconf, files, labels=None): |
403 tool, toolpath, binary, symlink, scriptfn = toolconf | 403 tool, toolpath, binary, symlink, scriptfn = toolconf |
404 if symlink or fcd.isabsent() or fco.isabsent(): | 404 if symlink or fcd.isabsent() or fco.isabsent(): |
405 return 1 | 405 return 1 |
406 unused, unused, unused, back = files | 406 unused, unused, unused, backup = files |
407 | 407 |
408 ui = repo.ui | 408 ui = repo.ui |
409 | 409 |
410 validkeep = [b'keep', b'keep-merge3', b'keep-mergediff'] | 410 validkeep = [b'keep', b'keep-merge3', b'keep-mergediff'] |
411 | 411 |
436 if not r: | 436 if not r: |
437 ui.debug(b" premerge successful\n") | 437 ui.debug(b" premerge successful\n") |
438 return 0 | 438 return 0 |
439 if premerge not in validkeep: | 439 if premerge not in validkeep: |
440 # restore from backup and try again | 440 # restore from backup and try again |
441 _restorebackup(fcd, back) | 441 _restorebackup(fcd, backup) |
442 return 1 # continue merging | 442 return 1 # continue merging |
443 | 443 |
444 | 444 |
445 def _mergecheck(repo, mynode, orig, fcd, fco, fca, toolconf): | 445 def _mergecheck(repo, mynode, orig, fcd, fco, fca, toolconf): |
446 tool, toolpath, binary, symlink, scriptfn = toolconf | 446 tool, toolpath, binary, symlink, scriptfn = toolconf |
753 repo.ui.warn( | 753 repo.ui.warn( |
754 _(b'warning: %s cannot merge change/delete conflict for %s\n') | 754 _(b'warning: %s cannot merge change/delete conflict for %s\n') |
755 % (tool, uipathfn(fcd.path())) | 755 % (tool, uipathfn(fcd.path())) |
756 ) | 756 ) |
757 return False, 1, None | 757 return False, 1, None |
758 unused, unused, unused, back = files | 758 unused, unused, unused, backup = files |
759 localpath = _workingpath(repo, fcd) | 759 localpath = _workingpath(repo, fcd) |
760 args = _toolstr(repo.ui, tool, b"args") | 760 args = _toolstr(repo.ui, tool, b"args") |
761 | 761 |
762 with _maketempfiles( | 762 with _maketempfiles( |
763 repo, fco, fca, repo.wvfs.join(back.path()), b"$output" in args | 763 repo, fco, fca, repo.wvfs.join(backup.path()), b"$output" in args |
764 ) as temppaths: | 764 ) as temppaths: |
765 basepath, otherpath, localoutputpath = temppaths | 765 basepath, otherpath, localoutputpath = temppaths |
766 outpath = b"" | 766 outpath = b"" |
767 mylabel, otherlabel = labels[:2] | 767 mylabel, otherlabel = labels[:2] |
768 if len(labels) >= 3: | 768 if len(labels) >= 3: |
916 b"l": b" [%s]" % labels[0], | 916 b"l": b" [%s]" % labels[0], |
917 b"o": b" [%s]" % labels[1], | 917 b"o": b" [%s]" % labels[1], |
918 } | 918 } |
919 | 919 |
920 | 920 |
921 def _restorebackup(fcd, back): | 921 def _restorebackup(fcd, backup): |
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(backup.data(), fcd.flags()) |
925 | 925 |
926 | 926 |
927 def _makebackup(repo, ui, wctx, fcd): | 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 |
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) |
942 from . import context | 942 from . import context |
943 | 943 |
944 back = scmutil.backuppath(ui, repo, fcd.path()) | 944 backup = scmutil.backuppath(ui, repo, fcd.path()) |
945 inworkingdir = back.startswith(repo.wvfs.base) and not back.startswith( | 945 inworkingdir = backup.startswith(repo.wvfs.base) and not backup.startswith( |
946 repo.vfs.base | 946 repo.vfs.base |
947 ) | 947 ) |
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 = backup[len(repo.wvfs.base) + 1 :] |
953 wctx[relpath].write(fcd.data(), fcd.flags()) | 953 wctx[relpath].write(fcd.data(), fcd.flags()) |
954 return wctx[relpath] | 954 return wctx[relpath] |
955 else: | 955 else: |
956 # Otherwise, write to wherever path the user specified the backups | 956 # Otherwise, write to wherever path the user specified the backups |
957 # should go. We still need to switch based on whether the source is | 957 # 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 | 958 # in-memory so we can use the fast path of ``util.copy`` if both are |
959 # on disk. | 959 # on disk. |
960 if isinstance(fcd, context.overlayworkingfilectx): | 960 if isinstance(fcd, context.overlayworkingfilectx): |
961 util.writefile(back, fcd.data()) | 961 util.writefile(backup, fcd.data()) |
962 else: | 962 else: |
963 a = _workingpath(repo, fcd) | 963 a = _workingpath(repo, fcd) |
964 util.copyfile(a, back) | 964 util.copyfile(a, backup) |
965 # 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 |
966 # the backup context regardless of where it lives. | 966 # the backup context regardless of where it lives. |
967 return context.arbitraryfilectx(back, repo=repo) | 967 return context.arbitraryfilectx(backup, repo=repo) |
968 | 968 |
969 | 969 |
970 @contextlib.contextmanager | 970 @contextlib.contextmanager |
971 def _maketempfiles(repo, fco, fca, localpath, uselocalpath): | 971 def _maketempfiles(repo, fco, fca, localpath, uselocalpath): |
972 """Writes out `fco` and `fca` as temporary files, and (if uselocalpath) | 972 """Writes out `fco` and `fca` as temporary files, and (if uselocalpath) |
1116 b'in-memory merge does not support merge conflicts' | 1116 b'in-memory merge does not support merge conflicts' |
1117 ) | 1117 ) |
1118 ui.warn(onfailure % fduipath) | 1118 ui.warn(onfailure % fduipath) |
1119 return True, 1, False | 1119 return True, 1, False |
1120 | 1120 |
1121 back = _makebackup(repo, ui, wctx, fcd) | 1121 backup = _makebackup(repo, ui, wctx, fcd) |
1122 files = (None, None, None, back) | 1122 files = (None, None, None, backup) |
1123 r = 1 | 1123 r = 1 |
1124 try: | 1124 try: |
1125 internalmarkerstyle = ui.config(b'ui', b'mergemarkers') | 1125 internalmarkerstyle = ui.config(b'ui', b'mergemarkers') |
1126 if isexternal: | 1126 if isexternal: |
1127 markerstyle = _toolstr(ui, tool, b'mergemarkers') | 1127 markerstyle = _toolstr(ui, tool, b'mergemarkers') |
1186 ui.warn(onfailure % fduipath) | 1186 ui.warn(onfailure % fduipath) |
1187 _onfilemergefailure(ui) | 1187 _onfilemergefailure(ui) |
1188 | 1188 |
1189 return True, r, deleted | 1189 return True, r, deleted |
1190 finally: | 1190 finally: |
1191 if not r and back is not None: | 1191 if not r and backup is not None: |
1192 back.remove() | 1192 backup.remove() |
1193 | 1193 |
1194 | 1194 |
1195 def _haltmerge(): | 1195 def _haltmerge(): |
1196 msg = _(b'merge halted after failed merge (see hg resolve)') | 1196 msg = _(b'merge halted after failed merge (see hg resolve)') |
1197 raise error.InterventionRequired(msg) | 1197 raise error.InterventionRequired(msg) |
1223 | 1223 |
1224 | 1224 |
1225 def _check(repo, r, ui, tool, fcd, files): | 1225 def _check(repo, r, ui, tool, fcd, files): |
1226 fd = fcd.path() | 1226 fd = fcd.path() |
1227 uipathfn = scmutil.getuipathfn(repo) | 1227 uipathfn = scmutil.getuipathfn(repo) |
1228 unused, unused, unused, back = files | 1228 unused, unused, unused, backup = files |
1229 | 1229 |
1230 if not r and ( | 1230 if not r and ( |
1231 _toolbool(ui, tool, b"checkconflicts") | 1231 _toolbool(ui, tool, b"checkconflicts") |
1232 or b'conflicts' in _toollist(ui, tool, b"check") | 1232 or b'conflicts' in _toollist(ui, tool, b"check") |
1233 ): | 1233 ): |
1250 and ( | 1250 and ( |
1251 _toolbool(ui, tool, b"checkchanged") | 1251 _toolbool(ui, tool, b"checkchanged") |
1252 or b'changed' in _toollist(ui, tool, b"check") | 1252 or b'changed' in _toollist(ui, tool, b"check") |
1253 ) | 1253 ) |
1254 ): | 1254 ): |
1255 if back is not None and not fcd.cmp(back): | 1255 if backup is not None and not fcd.cmp(backup): |
1256 if ui.promptchoice( | 1256 if ui.promptchoice( |
1257 _( | 1257 _( |
1258 b" output file %s appears unchanged\n" | 1258 b" output file %s appears unchanged\n" |
1259 b"was merge successful (yn)?" | 1259 b"was merge successful (yn)?" |
1260 b"$$ &Yes $$ &No" | 1260 b"$$ &Yes $$ &No" |
1262 % uipathfn(fd), | 1262 % uipathfn(fd), |
1263 1, | 1263 1, |
1264 ): | 1264 ): |
1265 r = 1 | 1265 r = 1 |
1266 | 1266 |
1267 if back is not None and _toolbool(ui, tool, b"fixeol"): | 1267 if backup is not None and _toolbool(ui, tool, b"fixeol"): |
1268 _matcheol(_workingpath(repo, fcd), back) | 1268 _matcheol(_workingpath(repo, fcd), backup) |
1269 | 1269 |
1270 return r | 1270 return r |
1271 | 1271 |
1272 | 1272 |
1273 def _workingpath(repo, ctx): | 1273 def _workingpath(repo, ctx): |