File: //usr/lib/python3/dist-packages/mercurial/__pycache__/simplemerge.cpython-310.pyc
o
�]LbpC � @ s� d dl mZ ddlmZ ddlmZmZmZ ddlm Z dd� Z
dd � ZG d
d� de�Z
dd
� Zdd� Zdd� Zdd� Z d&dd�Zdd� Zdd� Zdd� ZG d d!� d!e�Z " #d'd$d%�ZdS )(� )�absolute_import� )�_)�error�mdiff�pycompat)�
stringutilc C s` | d | d ks
J �|d |d ksJ �t | d |d �}t| d |d �}||k r.||fS dS )a Given 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)
r r N)�max�min)�ra�rb�sa�sb� r �7/usr/lib/python3/dist-packages/mercurial/simplemerge.py� intersect s r c C sR || || kr
dS t t�||�t�||��D ]\}}| | || kr& dS qdS )z:Compare a[astart:aend] == b[bstart:bend], without slicing.FT)�zipr �xrange)�a�astart�aend�b�bstart�bend�ia�ibr r r �
compare_range5 s ��r c @ s2 e Zd ZdZddd�Zdd� Zdd� Zd d
� ZdS )�
Merge3Textz�3-way merge of texts.
Given strings BASE, OTHER, THIS, tries to produce a combined text
incorporating the changes from both BASE->OTHER and BASE->THIS.Nc C s^ || _ || _|| _|d u rt�|�}|d u rt�|�}|d u r$t�|�}|| _|| _|| _d S �N)�basetext�atext�btextr �
splitnewlines�baser r )�selfr r r! r# r r r r r �__init__H s
zMerge3Text.__init__c c s� � | � � D ]n}|d }|dkr|| j|d |d � fV q|dks&|dkr5|| j|d |d � fV q|dkrH|| j|d |d � fV q|dkrp|| j|d |d � | j|d |d
� | j|d |d � ffV qt|��d
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.
r � unchangedr � � a� same� b� conflict� � � � N)�
merge_regionsr# r r �
ValueError)r$ �t�whatr r r �merge_groupsV s$ ��� �zMerge3Text.merge_groupsc c s� � d } }}| � � D ]�}|\}}}}} }
|| }|dksJ �||| ks'J �||
| ks/J �|| }| | }
|| }|dksAJ �|
dksGJ �|dksMJ �|sQ|
r�t| j||| j||�}t| j|| | j||�}t| j||| j|| �}|r{d||fV n)|r�|s�d|| fV n|r�|s�d||fV n|s�|s�d|||||| fV ntd��|}| }|}|dkr�||ks�J �|| ks�J �||ks�J �d||fV |}|}|
}qdS ) a� Return 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]
'conflict', zstart, zend, astart, aend, bstart, bend
Conflict between a and b, with z as common ancestor
Method is as follows:
The two sequences align only on regions which match the base
and both descendants. 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.
r r) r* r( r+ s# can't handle a=b=base but unmatchedr&