comparison mercurial/simplemerge.py @ 48507:58a3be48ddd2

simplemerge: stop merging file flags As 384df4db6520 (merge: merge file flags together with file content, 2013-01-09) explains, we shouldn't do a 3-way merge of the symlink. However, since 84614212ae39 (flags: actually merge flags in simplemerge, 2020-05-16), we do that in `simplemerge.simplemerge()`. What's more, the merging of the executable flag there isn't actually necessary; it was made a no-op by the very next commit, i.e. 4234c9af515d (flags: read flag from dirstate/disk for workingcopyctx (issue5743), 2020-05-16). I found the overall flag-merging code (not the bit in `simplemerge.py`) very hard to follow, but I think I now finally understand how it works. `mergestate.resolve()` calculates the merged file flags and sets them on the local side of the merge (confusingly by calling `_restore_backup()`). Then it calls `filemerge.filemerge()`, which in turn calls `simplemerge.simplemerge()` (if premerge is enabled). That means that the flags on the local side `fcs.flags()` are already correct when the flag-merging code in `simplemerge.simplemerge()` runs. Interestingly, that code still works when the local side already has the merged value, it just doesn't change the value. Here's a truth table to explain why: ``` BLOMCAR 0000000 0011111 0101011 0111111 1000000 1010000 1100000 1111101 ``` B: Base L: Local O: Other M: Merged flags from `mergestate.resolve()`, i.e. what's called "local" when we get to `simplemerge.simplemerge()` C: `commonflags` in `simplemerge.simplemerge()`, i.e. `M & O` A: `addedflags` in `simplemerge.simplemerge()`, i.e. `(M ^ O) - B` R: Re-merged flags `simplemerge.simplemerge()`, i.e. `C | A` As you can see, the re-merged flags are always unchanged compared to the initial merged flags (R equals M). Therefore, this patch effectively backs out 84614212ae39. (I might later refactor this code to have the flags explicitly passed in.) `simplemerge.simplemerge()` is also called from `contrib/simplemerge.py`, but that code never passes any flags. Differential Revision: https://phab.mercurial-scm.org/D11879
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 06 Dec 2021 23:17:43 -0800
parents 9e1f174d305b
children fa159bb463e6
comparison
equal deleted inserted replaced
48506:608a35db186c 48507:58a3be48ddd2
17 # s: "i hate that." 17 # s: "i hate that."
18 18
19 from __future__ import absolute_import 19 from __future__ import absolute_import
20 20
21 from .i18n import _ 21 from .i18n import _
22 from .node import nullrev
23 from . import ( 22 from . import (
24 error, 23 error,
25 mdiff, 24 mdiff,
26 pycompat, 25 pycompat,
27 util,
28 ) 26 )
29 from .utils import stringutil 27 from .utils import stringutil
30 28
31 29
32 class CantReprocessAndShowBase(Exception): 30 class CantReprocessAndShowBase(Exception):
422 for i, override in enumerate(overrides): 420 for i, override in enumerate(overrides):
423 result[i] = override 421 result[i] = override
424 return result 422 return result
425 423
426 424
427 def is_not_null(ctx):
428 if not util.safehasattr(ctx, "node"):
429 return False
430 return ctx.rev() != nullrev
431
432
433 def _mergediff(m3, name_a, name_b, name_base): 425 def _mergediff(m3, name_a, name_b, name_base):
434 lines = [] 426 lines = []
435 conflicts = False 427 conflicts = False
436 for group in m3.merge_groups(): 428 for group in m3.merge_groups():
437 if group[0] == b'conflict': 429 if group[0] == b'conflict':
544 name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs) 536 name_a=name_a, name_b=name_b, **pycompat.strkwargs(extrakwargs)
545 ) 537 )
546 ) 538 )
547 conflicts = m3.conflicts and not mode == b'union' 539 conflicts = m3.conflicts and not mode == b'union'
548 540
549 # merge flags if necessary
550 flags = localctx.flags()
551 localflags = set(pycompat.iterbytestr(flags))
552 otherflags = set(pycompat.iterbytestr(otherctx.flags()))
553 if is_not_null(basectx) and localflags != otherflags:
554 baseflags = set(pycompat.iterbytestr(basectx.flags()))
555 commonflags = localflags & otherflags
556 addedflags = (localflags ^ otherflags) - baseflags
557 flags = b''.join(sorted(commonflags | addedflags))
558
559 mergedtext = b''.join(lines) 541 mergedtext = b''.join(lines)
560 if opts.get('print'): 542 if opts.get('print'):
561 ui.fout.write(mergedtext) 543 ui.fout.write(mergedtext)
562 else: 544 else:
563 localctx.write(mergedtext, flags) 545 # localctx.flags() already has the merged flags (done in
546 # mergestate.resolve())
547 localctx.write(mergedtext, localctx.flags())
564 548
565 if conflicts: 549 if conflicts:
566 return 1 550 return 1