Skip to content
  • Thomas Gummerer's avatar
    rerere: teach rerere to handle nested conflicts · 4af32207
    Thomas Gummerer authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Currently rerere can't handle nested conflicts and will error out when
    it encounters such conflicts.  Do that by recursively calling the
    'handle_conflict' function to normalize the conflict.
    
    Note that a conflict like this would only be produced if a user
    commits a file with conflict markers, and gets a conflict including
    that in a susbsequent operation.
    
    The conflict ID calculation here deserves some explanation:
    
    As we are using the same handle_conflict function, the nested conflict
    is normalized the same way as for non-nested conflicts, which means
    the ancestor in the diff3 case is stripped out, and the parts of the
    conflict are ordered alphabetically.
    
    The conflict ID is however is only calculated in the top level
    handle_conflict call, so it will include the markers that 'rerere'
    adds to the output.  e.g. say there's the following conflict:
    
        <<<<<<< HEAD
        1
        =======
        <<<<<<< HEAD
        3
        =======
        2
        >>>>>>> branch-2
        >>>>>>> branch-3~
    
    it would be recorde as follows in the preimage:
    
        <<<<<<<
        1
        =======
        <<<<<<<
        2
        =======
        3
        >>>>>>>
        >>>>>>>
    
    and the conflict ID would be calculated as
    
        sha1(1<NUL><<<<<<<
        2
        =======
        3
        >>>>>>><NUL>)
    
    Stripping out vs. leaving the conflict markers in place in the inner
    conflict should have no practical impact, but it simplifies the
    implementation.
    
    Signed-off-by: default avatarThomas Gummerer <t.gummerer@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    4af32207