mercurial/simplemerge.py
branchstable
changeset 44790 84614212ae39
parent 43534 3b581ad59459
child 44988 ad6971e6740c
equal deleted inserted replaced
44789:783f059509e4 44790:84614212ae39
    20 
    20 
    21 from .i18n import _
    21 from .i18n import _
    22 from . import (
    22 from . import (
    23     error,
    23     error,
    24     mdiff,
    24     mdiff,
       
    25     node as nodemod,
    25     pycompat,
    26     pycompat,
       
    27     util,
    26 )
    28 )
    27 from .utils import stringutil
    29 from .utils import stringutil
    28 
    30 
    29 
    31 
    30 class CantReprocessAndShowBase(Exception):
    32 class CantReprocessAndShowBase(Exception):
   447     for i, override in enumerate(overrides):
   449     for i, override in enumerate(overrides):
   448         result[i] = override
   450         result[i] = override
   449     return result
   451     return result
   450 
   452 
   451 
   453 
       
   454 def _bytes_to_set(b):
       
   455     """turns a multiple bytes (usually flags) into a set of individual byte"""
       
   456     return set(b[x : x + 1] for x in range(len(b)))
       
   457 
       
   458 
       
   459 def is_null(ctx):
       
   460     if not util.safehasattr(ctx, "node"):
       
   461         return False
       
   462     return ctx.node() != nodemod.nullid
       
   463 
       
   464 
   452 def simplemerge(ui, localctx, basectx, otherctx, **opts):
   465 def simplemerge(ui, localctx, basectx, otherctx, **opts):
   453     """Performs the simplemerge algorithm.
   466     """Performs the simplemerge algorithm.
   454 
   467 
   455     The merged result is written into `localctx`.
   468     The merged result is written into `localctx`.
   456     """
   469     """
   501         if opts.get(b'print'):
   514         if opts.get(b'print'):
   502             ui.fout.write(line)
   515             ui.fout.write(line)
   503         else:
   516         else:
   504             mergedtext += line
   517             mergedtext += line
   505 
   518 
       
   519     # merge flags if necessary
       
   520     flags = localctx.flags()
       
   521     localflags = _bytes_to_set(flags)
       
   522     otherflags = _bytes_to_set(otherctx.flags())
       
   523     if is_null(basectx) and localflags != otherflags:
       
   524         baseflags = _bytes_to_set(basectx.flags())
       
   525         flags = localflags & otherflags
       
   526         for f in localflags.symmetric_difference(otherflags):
       
   527             if f not in baseflags:
       
   528                 flags.add(f)
       
   529         flags = b''.join(sorted(flags))
       
   530 
   506     if not opts.get(b'print'):
   531     if not opts.get(b'print'):
   507         localctx.write(mergedtext, localctx.flags())
   532         localctx.write(mergedtext, flags)
   508 
   533 
   509     if m3.conflicts and not mode == b'union':
   534     if m3.conflicts and not mode == b'union':
   510         return 1
   535         return 1