^c(EddlZddlZddlZddlmZddlmZmZddlm Z m Z m Z m Z mZm Z ddlmZe jdZe jdZejZejZejZejZejZejZGd d ZeZdd Zd ZdZdZddZddZ efdZ!efdZ"dZ#dZ$dZ%dZ&dZ'dZ(dS)N)_)getattrsetattr) diffhelperencodingerrorpolicypycompatutil)dateutilbdiffmpatchceZdZdZdZiddddddddd dd dd dd d ddddddddddddddddZdZdZdS)diffoptsacontext is the number of context lines text treats all files as text showfunc enables diff -p output git enables the git extended patch format nodates removes dates from diff headers nobinary ignores binary files noprefix disables the 'a/' and 'b/' prefixes (ignored in plain mode) ignorews ignores all whitespace changes in the diff ignorewsamount ignores changes in the amount of whitespace ignoreblanklines ignores changes whose lines are all blank upgrade generates git diffs to avoid data loss TscontextstextFsshowfuncsgitsnodatessnobinarysnoprefixsindexrsignorewssignorewsamounts ignorewseolsignoreblanklinessupgradesshowsimilaritysworddiffsxdiffc tj|}|jD]7}||}| |j|}t |||8 t |j|_dS#t$r<tj tdtj |jzwxYw)Ns3diff context lines count must be an integer, not %r) r byteskwargsdefaultskeysgetrintcontext ValueErrorr InputErrorrbytestr)selfoptskvs 1/usr/lib/python3/dist-packages/mercurial/mdiff.py__init__zdiffopts.__init__Ks#D))##%%  A AyM!$ D!Q     t|,,DLLL   "HII"4<001  s 'BACc fdjD}tj|}||t di|S)Nc2i|]}|t|S)r).0rrs r! z!diffopts.copy..\s%;;;74##;;;r%)rr strkwargsupdater)rkwargsrs` r!copyz diffopts.copy[sT;;;;T];;;!$'' F$r(N)__name__ __module__ __qualname____doc___HAS_DYNAMIC_ATTRIBUTESrr"r,r%r(r!rr(s  #A U   E  U  U ! U 5  U E 5 U %!H&      r(rTc.|jrt|d}n"|jrt|d}|r0|jr)t jdd|d}|jrt jdd|}|S)Nrrs + s [ \t\r\f]+\ns\n) ignorewsrfixwsignorewsamountignoreblanklinesresubstrip ignorewseol)rtextblanks r!wscleanr>es }${{4## ${{4## 8&8vfeT**0077 6v&55 Kr(c#zKfd|D}fd|D}dt|}}dt|}}||ks||kr||d} } } | |ks|| dks| |ks || dkrUd} | |kr#|| dkr| dz } | |kr || dk| |kr#|| dkr| dz } | |kr || dknF| |kr@|| dkr4|| dkr(| dz } | dz } | |kr|| dkr || dk(||z|| z||z|| zg| fV| }| }||k||kdSdS)Nc8g|]}t|rdpdSrrr>r&lrs r! zsplitblock..t- < < <wtQ%A* < < .urFr(r=~rlen) base1lines1base2lines2rs1e1s2e2i1i2btypes ` r! splitblockrWqs= < < EEEE  ! r''R"WWWWWWr(c4|\}}|\}}|||zko||kS)aReturn True if `hunk` defined as (start, length) is in `linerange` defined as (lowerbound, upperbound). >>> hunkinrange((5, 10), (2, 7)) True >>> hunkinrange((5, 10), (6, 12)) True >>> hunkinrange((5, 10), (13, 17)) True >>> hunkinrange((5, 10), (3, 17)) True >>> hunkinrange((5, 10), (1, 3)) False >>> hunkinrange((5, 10), (18, 20)) False >>> hunkinrange((5, 10), (1, 5)) False >>> hunkinrange((5, 10), (15, 27)) False r%)hunk linerangestartlength lowerbound upperbounds r! hunkinranger_s0*ME6&J  & =5:+==r(c|\}}d\}}g}|D]}|\\}} } } } || kr|| kr| dkr|| z |z}|| z |z}nB| |cxkr| krnn| dkr | | |z z }n|}| |cxkr| krnn| dkr ||| z z}n| }t| | | z f|r||||||kr!tjt d|||ffS)afilter `blocks` like (a1, a2, b1, b2) from items outside line range `rangeb` from ``(b1, b2)`` point of view. Return `filteredblocks, rangea` where: * `filteredblocks` is list of ``block = (a1, a2, b1, b2), stype`` items of `blocks` that are inside `rangeb` from ``(b1, b2)`` point of view; a block ``(b1, b2)`` being inside `rangeb` if ``rangeb[0] < b2 and b1 < rangeb[1]``; * `rangea` is the line range w.r.t. to ``(a1, a2)`` parts of `blocks`. )NNrHNsline range exceeds file size)r_appendr rr) blocksrangeblbbubblbaubafilteredblocksblocka1a2b1b2stypes r! blocksinrangerosIHCHCN))"'RR% "99u}}(R-C(R-CCS~~~~2~~~~~D==S/CCCC~~~~2~~~~~D==b/CCC R"W / / )  ! !% ( ( ( {ckS3YYq!@AABBB C: %%r(cx|!|jrtjtds tjStjS)Ns xdiffblocks)xdiffr safehasattrrrb xdiffblocksrs r!chooseblocksfuncrus9 z ~66 |  r(c #K|t}|js|js|jr"t ||d}t ||d}t |||}t |D] \}}|dkr ||dz }ngd}|d|d|d|dg}|d|dks|d|dkrd} |jr|t|}|t|}t |d ||d|d} t |d ||d|d} | | krd } || fV|d fV dS) abReturn (block, type) tuples, where block is an mdiff.blocks line entry. type is '=' for blocks matching exactly one another (bdiff blocks), '!' for non-matching blocks and '~' for blocks matching only after having filtered blank lines. line1 and line2 are text1 and text2 split with splitnewlines() if they are already available. NFrr)rrrrr!r(rIrH) defaultoptsr4r6r;r>ru enumerater7 splitnewlinesjoin) text1text2rrMrOdiffirPstypeoldnews r! allblocksrs | },+,t/?,eU++eU++ ! D ! !% / /D42 q55QU AA A qT2a5!A$1 & Q41Q4<<1Q41Q4<<D$ >*511F>*511FdCHHVAaD1Q4K-@$A$ABBdCHHVAaD1Q4K-@$A$ABB#::DT'MMM$h3r(cdfd }gdf} |s|s| Sjrdx} } nd} d} tjd} tj|}tj|}|r9|r*|r(t |t |kr||kr| Sg} dd|zgff}n|s|d  }t|}|d || z}nd | ||||fz}d | |z|||fz}||g} t |}d d d|f}d|zgd|Dz}|r/|dxxd z cc<|tj ||ff}n|s|d  }t|}d | ||||fz}|d|| z}nd| ||||fz}||g} t |}d|d d f}d|zgd|Dz}|r/|dxxd z cc<|tj ||ff}nGt||}t|s| Sd | ||||fzd| ||||fzg} | |fS)a|Return a unified diff as a (headers, hunks) tuple. If the diff is not null, `headers` is a list with unified diff header lines "--- " and "+++ " and `hunks` is a generator yielding (hunkrange, hunklines) coming from _unidiff(). Otherwise, `headers` and `hunks` are empty. Set binary=True if either a or b should be taken as a binary file. Nc>js jsd|zS|rd|vrdSdS)Ns %s  r()gitnodates)datefnrs r!datetagzunidiff..datetag s:x "  "T> !  $"**5sr(r%r(sa/sb/)rrsBinary file %s has changed r3s--- /dev/null%ss --- %s%s%ss+++ %s%srrs@@ -0,0 +1,%d @@ cg|]}d|zS+r%r&es r!rEzunidiff..35J5J5J1dQh5J5J5Jr(s+++ /dev/null%ss +++ %s%s%ss@@ -1,%d +0,0 @@ cg|]}d|zS-r%rs r!rEzunidiff..Crr(rtN) noprefixr datestrr pconvertrKendswithr{rarMISSING_NEWLINE_MARKER_unidiffnext)aadbbdfn1fn2binaryrrsentinelaprefixbprefixepoch headerlineshunkswithout_newlinel1l2size hunkrange hunkliness ` r!unidiffrs`2vH Q }''  V $ $E -  C -  C -   s1vvQ''AFFO 83>?@B ( jj/// !   9#ggenn4BB'3C0@0@!AAB GcM772s+;+;< <2h 1vv1dO *T125J5J5J5J5JJ  @ bMMMU "MMM   Z> ? ? ?Y')  jj/// !   gsGGB,<,<= = 9#ggenn4BB'3C0@0@!AAB2h 1vvaO *T125J5J5J5J5JJ  @ bMMMU "MMM   Z> ? ? ?Y')AD)))E{{ O Wc772s+;+;< < Wc772s+;+;< <  r(c#PKttfdfd}ddgfd}d}d}d}tD]$\}} |\} } } } | dkr| d kr|| | z | | z z z }(g}| | }| | }| |z} | |z} || }|| }d}|rD||d jzd zkr|}|d }|d }n|sd }d V||D]}|V|r| |d <| |d <|d }n|| || |g}d|| D|t|d<d|D|t|d<d|D|t|d<&|r|sd }d V||D]}|VdS|sdVdSdS)aYield hunks of a headerless unified diff from t1 and t2 texts. Each hunk consists of a (hunkrange, hunklines) tuple where `hunkrange` is a tuple (s1, l1, s2, l2) representing the range information of the hunk to form the '@@ -s1,l1 +s2,l2 @@' header and `hunklines` is a list of lines of the hunk combining said header followed by line additions and deletions. The hunks are prefixed with a bool. c,|jz}||kr|}|Srr)rDrKretrs r! contextendz_unidiff..contextendcs"$, 99C r(c,|jz }|dkrdS|SNrr)rDrrs r! contextstartz_unidiff..contextstartis"$, 771 r(rr(c3K|\}}}}}|t}||z }||z |z|z }d} jr\} } t|dz | dz dD]f} | ddrBd| z} t j| r | dd} | d<ng|d<|r|dz }|r|dz }||||f} d| | fzzg|zfdt||Dz} d }d s||ztdzkrtt| dz ddD]o} | | d rR| | drd }| | xxd z cc<| | dztj np|sd s||ztdzkrttt| dz ddD]R} | | d r5| | xxd z cc<| | dztj nS| | fVdS)Nr(rrrr)s@@ -%d,%d +%d,%d @@%s c&g|] }d|zSrr%)r&xrs r!rEz/_unidiff..yieldhunk..s!555tbe|555r(Fr3)rrTr) rKshowfuncrangeisalnumrstripr isasciistrr startswithinsertrr)rYastartrkbstartrmdeltaaendalenblenfunclastposrrrskiprrrlastfuncrt1t2s r! yieldhunkz_unidiff..yieldhunkqs *.'VRz"c"gg&&f}F{T!B& = !$MGT6A:w{B77  a51:%%''"Q%,,..0D *400)#CRCy"&HQKE!HQK   aKF   aKFD&$. '9w+> ? @ 5555U2t__555 6 {{5!! ftms2ww{&B&B3y>>A-r266  Q<**<88 |..t44$#aLLLE)LLL$$QUJ,MNNNE   BKK.. 6D=CGGaK3O3O3y>>A-r266  Q<**400aLLLE)LLL$$QUJ,MNNNE""""""r(NFrxrIrrTcg|]}d|zSrr%r&rs r!rEz_unidiff..s???Atax???r(cg|]}d|zSrr%rs r!rEz_unidiff..555Atax555r(cg|]}d|zSrr%rs r!rEz_unidiff..rr()r{rrrK)rrrrrrY ignoredlines has_hunksrrnrjrkrlrmrrrrrprevrrrrrs``` @@@@r!rrUs r  B r  B  3xH:#:#:#:#:#:#:#:#:#:#:#@ DLIb"dB33*6*65BB D==}} bR"W 55 BiBi l lb!!b!!  Q$,.222aa  $IJJJ"4AGGGG  3DGDGGEEBE2D??F2I???c%jjll55555c%jjll55555c%jjll  IJJJ4  AGGGG    r(cxd}d d}|d}|d}||krdSg}|d|dt|z|tj|D] }|||!|dd|S) z print base85-encoded binary diffct|}|dkr(tjtd|zdz }n*tj|dz tdzdz }d|t j|dfzS)NAras%c%s T)rKr bytechrordr b85encode)linerDs r!fmtlinezb85diff..fmtlinesw II 77 TQ!233AA R#d))!3a!788AAt~dD99:::r(4c3pKt|}d}||kr||||zV||z }||kdSdSrrJ)r<csizerDrs r!chunkzb85diff..chunksT II !eeq1u9}% % % % JA!eeeeeer(Nr(sGIT binary patch s literal %d r3)r)rarKzlibcompressr|)totnrrrrDs r!b85diffrs;;; z  z  Rxxs CJJ$%%%JJR())) U4=$$ % % 771::JJu 88C==r(cd}g}|t|kratjd|||dz\}}}|dz }|||||z||z }|t|kad|S)Nr>lll r()rKstructunpackrar|)binpostp1p2rDs r! patchtextrs C A C..M'3sS2X~+>?? B r  S37]#$$$ q C.. 88A;;r(ct|dkrtj|dSt||gS)Nrr)rKr bufferrpatches)rrs r!patchrs9 1vv{{{3### >>!cU # ##r(cLdt||DS)NcNg|]"}|d|d|d|dz f#S)rrwrr%)r&ds r!rEz'get_matching_blocks..#s3 B B B!QqT1Q41! % B B Br()rrb)rrs r!get_matching_blocksr"s$ B Bu||Aq/A/A B B BBr(c8|rtjddd|ndS)Nrrr(rpack)r\s r!trivialdiffheaderr&s"17 @6;w1f - - -S@r(c0tjdd||S)Nrrr)oldlennewlens r!replacediffheaderr *s ;w66 2 22r()Tr)NNN))r8rri18nrr rrrrr r r utilsr importmodrrrbr5r patchedsizetextdiffr{rryr>rWr_rorurrrrrrrrr r%r(r!rsX !!  ( # #   . ;# 7 7 7 7 7 7 7 7 thjj     4>>>4%&%&%&P!!!!''''T2=PPPPf&RRRRj"""J$$$CCCAAA33333r(