^cBCddlmZddlmZmZddlmZdZdZGddZ dZ d Z d Z d Z ddZdZdZdZGddZ ddZd S))_)errormdiff) stringutilc|d|dksJ|d|dksJt|d|d}t|d|d}||kr||fSdS)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) rN)maxmin)rarbsasbs 7/usr/lib/python3/dist-packages/mercurial/simplemerge.py intersectrss a5BqE>>>> a5BqE>>>> RUBqE  B RUBqE  B Bww2v tc||z ||z krdStt||t||D]\}}||||krdSdS)z:Compare a[astart:aend] == b[bstart:bend], without slicing.FT)ziprange)aastartaendbbstartbendiaibs r compare_ranger3so v 4&=))ueFD))5+>+>??B R5AbE>>55 trc,eZdZdZddZdZdZdZdS) Merge3Textz3-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||_||_||_|tj|}|tj|}|tj|}||_||_||_dSN)basetextatextbtextr splitnewlinesbaserr)selfr"r#r$r&rrs r__init__zMerge3Text.__init__Dso    <&x00D 9#E**A 9#E**A rc# K|D]}|d}|dkr ||j|d|dfV0|dks|dkr ||j|d|dfV\|dkr ||j|d|dfV|dkrU||j|d|d|j|d |d |j|d |d ffVt |d S)aYield 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 unchangedrasamebconflictN) merge_regionsr&rr ValueError)r'twhats r merge_groupszMerge3Text.merge_groupsRsN$##%% ' 'AQ4D|##DIadQqTk222222DF1Q4!A$;//////DF1Q4!A$;//////$$ !A$1+.qtad{+qtad{+!&&&% ' 'rc #Kdx}x}}|D]&}|\}}}}} } ||z } | dksJ| ||z ksJ| | | z ksJ||z } | |z } ||z }| dksJ| dksJ|dksJ| s| rt|j|||j||}t|j|| |j||}t|j|||j|| }|rd||fVn7|r |sd|| fVn+|r |sd||fVn|s|s d|||||| fVnt d|}| }|}| dkr%||ksJ|| ksJ||ksJd||fV|}|}| }(dS) aReturn 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. rr-r.r,r/s#can't handle a=b=base but unmatchedr*N)find_sync_regionsrrr&rAssertionError)r'izrrregionzmatchzendamatchrbmatchrmatchlenlen_alen_blen_baseequal_aequal_bsames rr4zMerge3Text.merge_regionsxsR>R",,..6 6 F7= 4FD&$f}Hq====v ....v ....RKERKE{HA::::A::::q====  'FB 2v(FB 2v%TVRVLL Q!2v-----QWQF*****QWQF***** QQ%r62vr6IIIII()OPPPB !||V||||V||||V||||"FD0000m6 6 rcdx}}tj|j|j}tj|j|j}t |}t |}g}||kr1||kr*||\}} } ||\} } } t ||| zf| | | zf}|r|d}|d}||z }|| ksJ|| ksJ||ksJ| |ksJ| ||z z}| || z z}||z}||z}|j|||j||ks&J|j|||j||f|j|||j ||ksJ| ||||||f|| z| | zkr|dz }n|dz }||kr||k*t |j}t |j}t |j } | ||||| | f|S)zReturn a list of sync regions, where both descendants 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. rr) rget_matching_blocksr"r#r$lenrr&rrappend)r'rramatchesbmatchesrCrDslabaser@alenbbaserAbleniintbaseintendintlenasubbsubrrs rr:zMerge3Text.find_sync_regionss[ R,T]DJGG,T]DJGGH H  5jjR%ZZ"*2, E64"*2, E645%$,/%1FGGA EA$1')~~~~~~~~''''''''5151f}f}y0DF494EEEEIgfn-F49%HEEE y0DF494EEEEE 7FD$dCDDD ..aaK5jjR%ZZNdi..DF DF  7GUE5%@AAA r)NNN)__name__ __module__ __qualname____doc__r(r8r4r:rrrr>sfGG    $'$'$'LWWWr;;;;;rrctj|r=td|jz}t j|dS)zUverifies that text is non-binary (unless opts[text] is passed, then we just warn)s%s looks like a binary file.N)rbinarytextrfctxpathrAbort)inputmsgs r _verifytextrgsX&&/005:??3D3DDk#rcDtd|D}g}|D]}|jrc|jr,|jdz|dzdz|jz}n|j}|t j|dl|d|S)Nc3PK|]!}|jrt|jndV"dS)rN)labelrK).0res r z!_format_labels..s8 I I%+4c%+1 I I I I I Ir:r H)r rj label_detailljustrLrellipsis)inputspadlabelsrerjs r_format_labelsrvs I I& I I I I IC F    ; ! $[4'..sQw77()   MM*-eV<< = = = = MM$     Mrct|jdkrD|jddrdS|jddrdSdS)Nrs   )rKrendswith)m3s r_detect_newliner|+sZ 24yy1}} 47  G $ $ 7 T!W  e $ $ 5 5rct|}t|}d}||kr;||kr5||||kr#|dz }||kr||kr||||k#|}d}||krK||krE|| dz || dz kr+|dz }||kr ||kr|| dz || dz k+|}|d|}||||z }||||z } |||z d} ||| | fS)zTrim conflict regions of lines where A and B sides match. Lines where both A and B have made the same changes at the beginning or the end of each merge region are eliminated from the conflict region and are instead considered the same. rrN)rK) a_linesb_linesrQrSii startmatches endmatches lines_before new_a_lines new_b_lines lines_afters r _minimizer4sJ w<>rN<<<<<<<=======>>>>>>>c>t|}d}|r|dz|z}|r|dz|z}|}g} |D]\} } | dkrd}| \} } }t| |}|\}} }}| || ||z| | | ||z| || ||z| || | | |fS)zReturn merge in cvs-like form.Frnr/T)r|r8rextendrL)r{name_aname_b start_marker mid_marker end_markernewline conflictsr8linesr7 group_lines base_linesr~r minimizedrrs rrender_minimizedrQsUb!!GI 4#d*V3  0$&/ ??$$L E)&&k ;  I+6 (J!'733I:C 7L'7K LL & & & LL/ 0 0 0 LL ! ! ! LLg- . . . LL ! ! ! LLg- . . . LL % % % % LL % % % % ) rct|}d}g}|D]\}}|dkr|\} } } d}|d|z|z|| |d|z|z|| |d|z|| |d|z|z||||fS)z+Render conflicts as 3-way conflict markers.Fr/Ts<<<<<<< s||||||| rs>>>>>>> )r|r8rLr) r{rr name_baserrrr7rrr~rs r render_merge3rtsb!!GI E__.. & &k ;  +6 (JI LLv-7 8 8 8 LL ! ! ! LLy07: ; ; ; LL $ $ $ LLg- . . . LL ! ! ! LLv-7 8 8 8 8 LL % % % % ) rc tt|}g}d}|D] \}}|dkr|\} } } d| } tt j| d| | | } tt j| d| | | }d}d}|d|z|||| kr|d|z|z|| |d |z|z|d |z|z||| | | n|d |z|z|d |z|z|||| | |d|z|z|| |d |zd }||||fS) zDRender conflicts as conflict markers with one snapshot and one diff.Fr/r)lines1lines2c4td|DS)Nc3JK|]\}}|dk |d|dz VdS)=rrNr^)rkblockkinds rrlz;render_mergediff..matching_lines..sE#tt||!HuQx'#|||r)sum)blockss rmatching_linesz(render_mergediff..matching_liness0'-rc3K|D]l\}}|dkr!||d|dD] }d|zV ,||d|dD] }d|zV ||d|dD] }d|zV mdS) Nrrrrn-r+r0+r^)rrrrrlines r diff_linesz$render_mergediff..diff_liness#)..KE4t||$*58eAh+>$?..D"&+----.%+58eAh+>$?..D"&+----$*58eAh+>$?..D"&+----...rrs======= s------- s+++++++ rT)r|r8joinlistr allblocksrLr)r{rrrrrrr7rrr~r base_textb_blocksa_blocksrrs rrender_mergediffrszb!!G EI__..7&7&k ;  +6 (J,,IHHW%%%" HHHW%%%" H    . . . LLg- . . .~h''..*B*BBB [61G;<<< W%%% [94w>??? [61G;<<< ZZ*gFFGGGG [94w>??? [61G;<<< ZZ*gFFGGG [61G;<<< W%%% LLg- . . .II LL % % % % ) rcg}|D]A\}}|dkr!|D]}|||,||B|S)Nr/)r8r)r{sidesrr7rsides r_resolversz E__..&&k ;   0 0 [.//// 0 LL % % % % Lrc"eZdZddZdZdZdS) MergeInputNc>||_||_||_d|_dSr!)rbrjrp_text)r'rbrjrps rr(zMergeInput.__init__s%  ) rcZ|j|j|_|jSr!)rrb decodeddata)r's rrazMergeInput.texts) : ..00DJzrc||_dSr!)r)r'ras rset_textzMergeInput.set_texts  r)NN)rZr[r\r(rarr^rrrrsF   rrmergeFc|s-t|t|t|t|||}d}|dkrt|d}n|dkrt|d}n|dkrt|d}np|dkr"t |||}t |g|R\}}nH|d kr"t |||}t |g|R\}}n t ||}t|g|R\}}d |} | |fS) z[Performs the simplemerge algorithm. The merged result is written into `localctx`. Fsunion)rr+slocal)rsother)r+s mergediffsmerge3r) rgrrarrvrrrr) localr&othermode allow_binaryr{rrru mergedtexts r simplemergersk EDE DIIKKuzz|| < rs(.NNNNNNNNb(???>      F*===@<  %!%!%!%!%!%!r