HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/merge3.cpython-39.pyc
a

�*�^�D�@s�ddlmZddlZddlmZmZGdd�dej�Zdd�Zd	d
�Z	Gdd�de
�Zd
d�Ze
dkr~ddlZe�eej��dS)�)�absolute_importN�)�errors�textfilec@seZdZdZdS)�CantReprocessAndShowBaseznCan't reprocess and show base, because reprocessing obscures the relationship of conflicting lines to the baseN)�__name__�
__module__�__qualname__Z_fmt�r
r
�//usr/lib/python3/dist-packages/breezy/merge3.pyrsrcCs<t|d|d�}t|d|d�}||kr4||fSdSdS)aGiven two ranges return the range where they intersect or None.

    >>> intersect((0, 10), (0, 6))
    (0, 6)
    >>> intersect((0, 10), (5, 15))
    (5, 10)
    >>> intersect((0, 10), (10, 15))
    >>> intersect((0, 9), (10, 15))
    >>> intersect((0, 9), (7, 15))
    (7, 9)
    rrN)�max�min)Zra�rbZsaZsbr
r
r�	intersect%s
rcCsN||||krdStt||�t||��D]\}}||||kr*dSq*dS)z?Compare a[astart:aend] == b[bstart:bend], without slicing.
    FTN)�zip�range)�a�astart�aend�b�bstart�bend�ia�ibr
r
r�
compare_range;src@sheZdZdZddd�Zdd	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
edd��Zdd�Z
dd�ZdS)�Merge3z�3-way merge of texts.

    Given BASE, OTHER, THIS, tries to produce a combined text
    incorporating the changes from both BASE->OTHER and BASE->THIS.
    All three will typically be sequences of lines.FcCs>|s"t�|�t�|�t�|�||_||_||_||_dS)aConstructor.

        :param base: lines in BASE
        :param a: lines in A
        :param b: lines in B
        :param is_cherrypick: flag indicating if this merge is a cherrypick.
            When cherrypicking b => a, matches with b and base do not conflict.
        :param allow_objects: if True, do not require that base, a and b are
            plain Python strs.  Also prevents BinaryFile from being raised.
            Lines can be any sequence of comparable and hashable Python
            objects.
        N)rZcheck_text_lines�baserr�
is_cherrypick)�selfrrrrZ
allow_objectsr
r
r�__init__Ns



zMerge3.__init__N�<<<<<<<�=======�>>>>>>>c	csd}	t|j�dkr<|jd�d�r(d}	n|jd�d�r<d}	|rJ|rJt��|rZ|d|}|rj|d|}|r~|r~|d|}|��}
|dur�|�|
�}
|
D�]\}|d}|dkr�t|d|d	�D]}
|j|
Vq�q�|d
ks�|dk�rt|d|d	�D]}
|j|
Vq�q�|dk�rBt|d|d	�D]}
|j|
V�q,q�|d
k�r�||	Vt|d|d�D]}
|j|
V�qh|du�r�||	Vt|d|d	�D]}
|j|
V�q�||	Vt|d|d�D]}
|j|
V�q�||	Vq�t	|��q�dS)z'Return merge in cvs-like form.
        �
rs
�
� T�	unchangedr�r�samer�conflict��N��)
�lenr�endswithr�
merge_regions�reprocess_merge_regionsrrr�
ValueError)rZname_aZname_bZ	name_baseZstart_markerZ
mid_markerZ
end_markerZbase_markerZ	reprocess�newliner0�t�what�ir
r
r�merge_linesdsR







zMerge3.merge_linesccs:|��D�]*}|d}|dkrHt|d|d�D]}d|j|Vq0q|dksX|dkr�t|d|d�D]}|dd|j|Vqjq|d	kr�t|d|d�D]}d
|j|Vq�q|dk�r,dVt|d
|d�D]}d|j|Vq�dVt|d|d�D]}d|j|V�qdVqt|��qdS)zhReturn merge with conflicts, showing origin of lines.

        Most useful for debugging merge.
        rr&rr'zu | rr(z | rzb | r)z<<<<
r*r+zA | z----
r,r-zB | z>>>>
N)r0rrrrr2)rr4r5r6r
r
r�merge_annotated�s(
zMerge3.merge_annotatedccs�|��D]�}|d}|dkr:||j|d|d�fVq|dksJ|dkrh||j|d|d�fVq|dkr�||j|d|d�fVq|dkr�||j|d|d�|j|d	|d
�|j|d|d�fVqt|��qd
S)a�Yield sequence of line groups.  Each one is a tuple:

        'unchanged', lines
             Lines unchanged from base

        'a', lines
             Lines taken from a

        'same', lines
             Lines taken from a (and equal to b)

        'b', lines
             Lines taken from b

        'conflict', base_lines, a_lines, b_lines
             Lines from base were changed to either a or b and conflict.
        rr&rr'rr(rr)r*r+r,r-N)r0rrrr2)rr4r5r
r
r�merge_groups�s�zMerge3.merge_groupsc	csLd}}}|��D�]0\}}}}}}	||}
||}||}|sH|�r"t|j|||j||�}
|
rpd||fVn�t|j|||j||�}t|j|||j||�}|r�|s�d||fVnh|r�|s�d||fVnR|�s|�s|jr�|�||||||�D]
}|Vq�nd||||||fVntd��|}|}|}|
dkrd||fV|}|}|	}qdS)	apReturn sequences of matching and conflicting regions.

        This returns tuples, where the first value says what kind we
        have:

        'unchanged', start, end
             Take a region of base[start:end]

        'same', astart, aend
             b and a are different from base but give the same result

        'a', start, end
             Non-clashing insertion from a[start:end]

        Method is as follows:

        The two sequences align only on regions which match the base
        and both descendents.  These are found by doing a two-way diff
        of each one against the base, and then finding the
        intersections between those regions.  These "sync regions"
        are by definition unchanged in both and easily dealt with.

        The regions in between can be in any of three cases:
        conflicted, or changed on only one side.
        rr(rrr)z#can't handle a=b=base but unmatchedr&N)�find_sync_regionsrrrrr�_refine_cherrypick_conflict�AssertionError)r�izrr�zmatch�zend�amatchr�bmatchrZmatchlen�len_a�len_br(Zequal_aZequal_bZnoder
r
rr0�sT

�
�
��
��zMerge3.merge_regionsc	csDt�d|j||�|j||����}d}d}	d}	d}
|D]~\}}}
||	}|dkrVnR|
r�d||||||||	||fVn(d}
d||||||||	||fV||
}||
}	q:|||ks�|	||k�r&|
r�d||||||||	||fVn(d}
d||||||||	||fV|
�s@d||||||fVdS)z:When cherrypicking b => a, ignore matches with b and base.NrFr)T)�patiencediff�PatienceSequenceMatcherrr�get_matching_blocks)rZzstartr?rrrr�matchesZ
last_base_idxZ
last_b_idxZ	yielded_aZbase_idxZb_idxZ	match_lenZconflict_b_lenr
r
rr;2sF��
��
��z"Merge3._refine_cherrypick_conflictccs�|D]�}|ddkr|Vq|\}}}}}}}	|j||�}
|j||	�}t�d|
|���}|}
|}|dd�D]X\}}}||7}||7}|�|
|||�}|dur�|Vd|||fV||}
||}qp|�|
|||	�}|dur|VqdS)z�Where there are conflict regions, remove the agreed lines.

        Lines where both A and B have made the same changes are
        eliminated.
        rr)N���r()rrrDrErF�mismatch_region)rr0Zregion�typer=r>rr@rrAZa_regionZb_regionrG�next_a�next_b�	region_ia�	region_ibZ
region_lenZregr
r
rr1[s4�
�
zMerge3.reprocess_merge_regionscCs&||ks||kr"ddd||||fSdS)Nr)r
)rKrMrLrNr
r
rrIzszMerge3.mismatch_regioncCsJd}}t�d|j|j���}t�d|j|j���}t|�}t|�}g}||k�r||k�r||\}}	}
||\}}}
t|||
f|||
f�}|r�|d}|d}||}|	||}|||}||}||}|�||||||f�||
||
k�r|d7}qH|d7}qHt|j�}t|j�}t|j�}|�||||||f�|S)z�Return a list of sync regions, where both descendents match the base.

        Generates a list of (base1, base2, a1, a2, b1, b2).  There is
        always a zero-length sync region at the end of all the files.
        rNr)	rDrErrrFrr.r�append)rrrZamatchesZbmatchesrBrCZslZabaser@�alenZbbaserAZblenr6ZintbaseZintendZintlenZasubZbsubrrr
r
rr:sD
�
�	�




zMerge3.find_sync_regionsc	Cs�t�d|j|j���}t�d|j|j���}g}|r�|r�|dd}||dd}|dd}||dd}t||f||f�}|r�|�|�||kr�|d=q0|d=q0|S)z8Return a list of ranges in base that are not conflicted.Nrr')rDrErrrFrrrO)	rZamZbmZuncZa1Za2Zb1Zb2r6r
r
r�find_unconflicted�s&
�
�
zMerge3.find_unconflicted)FF)NNNr r!r"NF)rrr	�__doc__rr7r8r9r0r;r1�staticmethodrIr:rQr
r
r
rrGs(
�
6"[)
=rcCs�t|dd��}|��}Wd�n1s,0Yt|dd��}|��}Wd�n1sb0Yt|dd��}|��}Wd�n1s�0Yt|||�}tj�|���dS)NrZrtr'r*)�open�	readlinesr�sys�stdout�
writelinesr8)�argv�frrrZm3r
r
r�main�s&&&r[�__main__)Z
__future__rrD�rrZBzrErrorrrr�objectrr[rrV�exitrYr
r
r
r�<module>s