Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/mercurial/simplemerge.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
�c@s�ddklZddkZddkZddkZddkZdefd��YZd�Zd�Z	de
fd��YZd	�ZdS(
i�(t_NtCantReprocessAndShowBasecBseZRS((t__name__t
__module__(((s(/sys/lib/python/mercurial/simplemerge.pyRscCs�|d|djpt�|d|djpt�t|d|d�}t|d|d�}||jo||fSndSdS(sGiven 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)
    iiN(tAssertionErrortmaxtmintNone(tratrbtsatsb((s(/sys/lib/python/mercurial/simplemerge.pyt	intersects
cCst||||jotSnxPtt||�t||��D])\}}||||jotSq?q?WtSdS(s?Compare a[astart:aend] == b[bstart:bend], without slicing.
    N(tFalsetziptxrangetTrue(tatastarttaendtbtbstarttbendtiatib((s(/sys/lib/python/mercurial/simplemerge.pyt
compare_range2s"t
Merge3Textc	Bs�eZdZd
d
d
d�Zd
d
d
dddd
ed�Zd�Zd�Zd�Z	d	�Z
d
�Zee�Zd�Z
d�ZRS(s�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.cCs�||_||_||_|djoti|�}n|djoti|�}n|djoti|�}n||_||_||_dS(N(	tbasetexttatexttbtextRtmdifft
splitnewlinestbaseRR(tselfRRRR RR((s(/sys/lib/python/mercurial/simplemerge.pyt__init__Bs			


		s<<<<<<<s=======s>>>>>>>c		cs�t|_d}	t|i�djoF|idid�o
d}	qk|idid�o
d}	qkn|o|o
t��n|o|d|}n|o|d|}n|o|o|d|}n|i�}
|tjo|i|
�}
nx�|
D]�}|d}|djo2x�t	|d|d�D]}
|i
|
Vq@Wq|d	jp
|d
jo2xSt	|d|d�D]}
|i|
Vq�Wq|djo2xt	|d|d�D]}
|i|
Vq�Wq|djo�t|_||	Vx+t	|d
|d�D]}
|i|
VqW|dj	o;||	Vx/t	|d|d�D]}
|i
|
Vq`Wn||	Vx+t	|d|d�D]}
|i|
Vq�W||	Vqt
|��qWdS(s'Return merge in cvs-like form.
        s
is
s
t t	unchangediiRtsameRtconflictiiiiN(R
t	conflictstlenRtendswithRt
merge_regionsRtreprocess_merge_regionstrangeR RRt
ValueError(R!tname_atname_bt	name_basetstart_markert
mid_markert
end_markertbase_markert	reprocesstnewlineR*tttwhatti((s(/sys/lib/python/mercurial/simplemerge.pytmerge_linesPsd	






		
		
ccs�x�|i�D]~}|d}|djo6x^t|d|d�D]}d|i|VqBWq
|djp
|djo>xt|d|d�D]}|dd|i|Vq�Wq
|d	jo6x�t|d|d�D]}d
|i|Vq�Wq
|djowdVx/t|d
|d�D]}d|i|Vq%WdVx/t|d|d�D]}d|i|Vq\WdVq
t|��q
WdS(shReturn merge with conflicts, showing origin of lines.

        Most useful for debugging merge.
        iR$iisu | RR%s | Rsb | R&s<<<<
iisA | s----
iisB | s>>>>
N(R*R,R RRR-(R!R7R8R9((s(/sys/lib/python/mercurial/simplemerge.pytmerge_annotated�s4


 

	c
cs x|i�D]}|d}|djo!||i|d|d!fVq
|djp
|djo!||i|d|d!fVq
|djo!||i|d|d!fVq
|djoK||i|d|d!|i|d	|d
!|i|d|d!fVq
t|��q
Wd
S(s�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.
        iR$iiRR%RR&iiiiN(R*R RRR-(R!R7R8((s(/sys/lib/python/mercurial/simplemerge.pytmerge_groups�s


!!
!
ccsld}}}xW|i�D]I\}}}}}}	||}
|
djpt�|
||jpt�|
|	|jpt�||}||}||}
|djpt�|djpt�|
djpt�|p|ot|i|||i||�}t|i|||i||�}t|i|||i||�}|od||fVn}|o|od||fVn\|o|od||fVn;|o&|od||||||fVn
td��|}|}n|}|
djo`||jpt�||jpt�||jpt�d||fV|}|}|	}qqWdS(	spReturn 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.
        iR%RRR&s#can't handle a=b=base but unmatchedR$N(tfind_sync_regionsRRRR R(R!tizRRtzmatchtzendtamatchRtbmatchRtmatchlentlen_atlen_btlen_basetequal_atequal_bR%((s(/sys/lib/python/mercurial/simplemerge.pyR*�sP






ccsQxJ|D]B}|ddjo|Vqn|\}}}}}}}	|i||!}
|i||	!}tidi|
�di|��}|}
|}x�|d D]w\}}}||7}||7}|i|
|||�}|dj	o	|Vnd|||fV||}
||}q�W|i|
|||	�}|dj	o	|VqqWdS(s�Where there are conflict regions, remove the agreed lines.

        Lines where both A and B have made the same changes are
        eliminated.
        iR&ti�R%N(RRRtget_matching_blockstjointmismatch_regionR(R!R*tregionttypeR>R?RRARRBta_regiontb_regiontmatchestnext_atnext_bt	region_iat	region_ibt
region_lentreg((s(/sys/lib/python/mercurial/simplemerge.pyR+s4

	
	

cCs;||jp
||joddd||||fSndS(NR&(R(RRRTRSRU((s(/sys/lib/python/mercurial/simplemerge.pyRL9scCsud}}ti|i|i�}ti|i|i�}t|�}t|�}g}x�||jo�||jo�||\}}	}
||\}}}
t|||
f|||
f�}|o.|d}|d}||}||
jpt�||
jpt�||jpt�||jpt�|	||}|||}||}||}|i||!|i	||!jp$t|i||!|i	||!f�|i||!|i
||!jpt�|i||||||f�n||
||
jo|d7}q[|d7}q[Wt|i�}t|i	�}t|i
�}|i||||||f�|S(s�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.
        ii(RRJRRRR(RRR RRtappend(R!RRtamatchestbmatchesRDREtsltabaseRAtalentbbaseRBtblenR9tintbasetintendtintlentasubtbsubRR((s(/sys/lib/python/mercurial/simplemerge.pyR=>sH
#




$!(c	Cs�ti|i|i�}ti|i|i�}g}x�|o�|o�|dd}||dd}|dd}||dd}t||f||f�}|o|i|�n||jo|d=q9|d=q9W|S(s8Return a list of ranges in base that are not conflicted.ii(RRJRRRRRX(	R!tamtbmtuncta1ta2tb1tb2R9((s(/sys/lib/python/mercurial/simplemerge.pytfind_unconflicted{s
N(RRt__doc__RR"R
R:R;R<R*R+RLtstaticmethodR=Rl(((s(/sys/lib/python/mercurial/simplemerge.pyR=s$0		"	U			=cs���fd�}|}|}�idg�}|o|id�}n|o|id�}n|otitd���n||�}	||�}
||�}tii|�}�id�p@titii	|��}|tii
|�ddt�}
n
ti
}
�id�}t|
|	|�}x3|id	|d
|d|�D]}|
i|�qTW�id�p|
i�n|io/�id�p�itd
��ndSndS(Ncs�t|d�}|i�}|i�ti|�obtd�|}�id�pti|��q��id�p�itd�|�q�n|S(NR	s%s looks like a binary file.ttexttquietswarning: %s
(	topentreadtclosetutiltbinaryRtgettAborttwarn(tfilenametfRotmsg(tuitopts(s(/sys/lib/python/mercurial/simplemerge.pytreadfile�s
tlabeliscan only specify two labels.tprinttwt
atomictempt
no_minimalR.R/R5Rps!warning: conflicts during merge.
i(RvtpopRtRwRtostpathtrealpathtopenertdirnametbasenameRtsyststdoutRR:twritetrenameR'Rx(R|tlocalR totherR}R~R.R/tlabelst	localtextRt	othertextR�toutR5tm3tline((R|R}s(/sys/lib/python/mercurial/simplemerge.pytsimplemerge�s<%	
(
ti18nRRtRR�R�t	ExceptionRRRtobjectRR�(((s(/sys/lib/python/mercurial/simplemerge.pys<module>s		

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].