Mercurial > hg
comparison mercurial/filemerge.py @ 48431:6b1049d71c3e
filemerge: make `_filemerge()` do both premerge and merge
This patch removes the `premerge` argument from `_filemerge()` and
makes it do both the "premerge" and "merge" steps without the caller
having to call it twice.
Differential Revision: https://phab.mercurial-scm.org/D11859
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 03 Dec 2021 21:41:43 -0800 |
parents | 921853391276 |
children | f45a4a47f6a8 |
comparison
equal
deleted
inserted
replaced
48430:921853391276 | 48431:6b1049d71c3e |
---|---|
1025 # shouldn't delete. | 1025 # shouldn't delete. |
1026 if d and uselocalpath: | 1026 if d and uselocalpath: |
1027 util.unlink(d) | 1027 util.unlink(d) |
1028 | 1028 |
1029 | 1029 |
1030 def _filemerge(premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None): | 1030 def _filemerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=None): |
1031 """perform a 3-way merge in the working directory | 1031 """perform a 3-way merge in the working directory |
1032 | 1032 |
1033 premerge = whether this is a premerge | 1033 premerge = whether this is a premerge |
1034 mynode = parent node before merge | 1034 mynode = parent node before merge |
1035 orig = original local filename before merge | 1035 orig = original local filename before merge |
1100 | 1100 |
1101 if mergetype == nomerge: | 1101 if mergetype == nomerge: |
1102 r, deleted = func(repo, mynode, orig, fcd, fco, fca, toolconf, labels) | 1102 r, deleted = func(repo, mynode, orig, fcd, fco, fca, toolconf, labels) |
1103 return True, r, deleted | 1103 return True, r, deleted |
1104 | 1104 |
1105 if premerge: | 1105 if orig != fco.path(): |
1106 if orig != fco.path(): | 1106 ui.status( |
1107 ui.status( | 1107 _(b"merging %s and %s to %s\n") |
1108 _(b"merging %s and %s to %s\n") | 1108 % (uipathfn(orig), uipathfn(fco.path()), fduipath) |
1109 % (uipathfn(orig), uipathfn(fco.path()), fduipath) | 1109 ) |
1110 ) | 1110 else: |
1111 else: | 1111 ui.status(_(b"merging %s\n") % fduipath) |
1112 ui.status(_(b"merging %s\n") % fduipath) | |
1113 | 1112 |
1114 ui.debug(b"my %s other %s ancestor %s\n" % (fcd, fco, fca)) | 1113 ui.debug(b"my %s other %s ancestor %s\n" % (fcd, fco, fca)) |
1115 | 1114 |
1116 if precheck and not precheck(repo, mynode, orig, fcd, fco, fca, toolconf): | 1115 if precheck and not precheck(repo, mynode, orig, fcd, fco, fca, toolconf): |
1117 if onfailure: | 1116 if onfailure: |
1120 b'in-memory merge does not support merge conflicts' | 1119 b'in-memory merge does not support merge conflicts' |
1121 ) | 1120 ) |
1122 ui.warn(onfailure % fduipath) | 1121 ui.warn(onfailure % fduipath) |
1123 return True, 1, False | 1122 return True, 1, False |
1124 | 1123 |
1125 back = _makebackup(repo, ui, wctx, fcd, premerge) | 1124 back = _makebackup(repo, ui, wctx, fcd, True) |
1126 files = (None, None, None, back) | 1125 files = (None, None, None, back) |
1127 r = 1 | 1126 r = 1 |
1128 try: | 1127 try: |
1129 internalmarkerstyle = ui.config(b'ui', b'mergemarkers') | 1128 internalmarkerstyle = ui.config(b'ui', b'mergemarkers') |
1130 if isexternal: | 1129 if isexternal: |
1138 if markerstyle != b'basic': | 1137 if markerstyle != b'basic': |
1139 formattedlabels = _formatlabels( | 1138 formattedlabels = _formatlabels( |
1140 repo, fcd, fco, fca, labels, tool=tool | 1139 repo, fcd, fco, fca, labels, tool=tool |
1141 ) | 1140 ) |
1142 | 1141 |
1143 if premerge and mergetype == fullmerge: | 1142 if mergetype == fullmerge: |
1144 # conflict markers generated by premerge will use 'detailed' | 1143 # conflict markers generated by premerge will use 'detailed' |
1145 # settings if either ui.mergemarkers or the tool's mergemarkers | 1144 # settings if either ui.mergemarkers or the tool's mergemarkers |
1146 # setting is 'detailed'. This way tools can have basic labels in | 1145 # setting is 'detailed'. This way tools can have basic labels in |
1147 # space-constrained areas of the UI, but still get full information | 1146 # space-constrained areas of the UI, but still get full information |
1148 # in conflict markers if premerge is 'keep' or 'keep-merge3'. | 1147 # in conflict markers if premerge is 'keep' or 'keep-merge3'. |
1158 ) | 1157 ) |
1159 | 1158 |
1160 r = _premerge( | 1159 r = _premerge( |
1161 repo, fcd, fco, fca, toolconf, files, labels=premergelabels | 1160 repo, fcd, fco, fca, toolconf, files, labels=premergelabels |
1162 ) | 1161 ) |
1163 # complete if premerge successful (r is 0) | 1162 # we're done if premerge was successful (r is 0) |
1164 return not r, r, False | 1163 if not r: |
1164 return not r, r, False | |
1165 | 1165 |
1166 needcheck, r, deleted = func( | 1166 needcheck, r, deleted = func( |
1167 repo, | 1167 repo, |
1168 mynode, | 1168 mynode, |
1169 orig, | 1169 orig, |
1276 def _workingpath(repo, ctx): | 1276 def _workingpath(repo, ctx): |
1277 return repo.wjoin(ctx.path()) | 1277 return repo.wjoin(ctx.path()) |
1278 | 1278 |
1279 | 1279 |
1280 def filemerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=None): | 1280 def filemerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=None): |
1281 complete, merge_ret, deleted = _filemerge( | 1281 return _filemerge(repo, wctx, mynode, orig, fcd, fco, fca, labels=labels) |
1282 True, repo, wctx, mynode, orig, fcd, fco, fca, labels=labels | |
1283 ) | |
1284 if not complete: | |
1285 complete, merge_ret, deleted = _filemerge( | |
1286 False, repo, wctx, mynode, orig, fcd, fco, fca, labels=labels | |
1287 ) | |
1288 return complete, merge_ret, deleted | |
1289 | 1282 |
1290 | 1283 |
1291 def loadinternalmerge(ui, extname, registrarobj): | 1284 def loadinternalmerge(ui, extname, registrarobj): |
1292 """Load internal merge tool from specified registrarobj""" | 1285 """Load internal merge tool from specified registrarobj""" |
1293 for name, func in pycompat.iteritems(registrarobj._table): | 1286 for name, func in pycompat.iteritems(registrarobj._table): |