o ]LbE@s<ddlmZddlZddlZddlZddlmZddlmZm Z ddl m Z m Z m Z mZmZmZddlmZedZed ZejZejZejZejZejZejZGd d d eZeZd)d dZddZddZ ddZ!d*ddZ"d+ddZ#efddZ$efddZ%ddZ&dd Z'd!d"Z(d#d$Z)d%d&Z*d'd(Z+dS),)absolute_importN)_)getattrsetattr) diffhelperencodingerrorpolicypycompatutil)dateutilbdiffmpatchc@seZdZdZdZiddddddddd dd dd dd d ddddddddddddddddZddZddZdS)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 Ks~t|}|jD]}||}|dur|j|}t|||q z t|j|_WdSty>t t dt |jw)Ns3diff context lines count must be an integer, not %r) r byteskwargsdefaultskeysgetrintcontext ValueErrorr InputErrorrbytestr)selfoptskvr1/usr/lib/python3/dist-packages/mercurial/mdiff.py__init__Ls     zdiffopts.__init__c s6fddjD}t|}||tdi|S)Ncsi|]}|t|qSr)r).0rrrr ]z!diffopts.copy..r)rr strkwargsupdater)rkwargsrrr#r copy\s  z diffopts.copyN)__name__ __module__ __qualname____doc___HAS_DYNAMIC_ATTRIBUTESrr!r)rrrr r)sL       rTcCs\|jr t|d}n |jrt|d}|r"|jr"tdd|d}|jr,tdd|}|S)Nrrs + s [ \t\r\f]+\ns\n) ignorewsrfixwsignorewsamountignoreblanklinesresubstrip ignorewseol)rtextblankrrr wscleanfs  r:c #sfdd|D}fdd|D}dt|}}dt|}}||ks)||kr||d} } } | |ksE|| dksE| |ksE|| dkrxd} | |kr_|| dkr_| d7} | |kr_|| dksQ| |krw|| dkrw| d7} | |krw|| dksin(| |kr|| dkr|| dkr| d7} | d7} | |kr|| dkr|| dks|||| |||| g| fV| }| }||ks)||ks)dSdS)Ncg|] }t|r dp dqSrrr:r"lrrr uzsplitblock..cr;r<r=r>r@rr rAvrBr=~rlen) base1lines1base2lines2rs1e1s2e2i1i2btyperr@r splitblockrs0(  "rRcCs$|\}}|\}}|||ko||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 upperboundrrr hunkinrangesrYc Cs|\}}d\}}g}|D]c}|\\}} } } } || kr/|| kr/| dkr/|| |}|| |}n2| |kr9| krHnn | dkrF| | |}n|}| |krR| krann | dkr_||| }n| }t| | | f|ro||q |dus||dus|||krttd|||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`. )NNrCNsline range exceeds file size)rYappendr rr) blocksrangeblbbubblbaubafilteredblocksblocka1a2b1b2styperrr blocksinranges,    rhcCs&|dus |jr ttdstjStjS)Ns xdiffblocks)xdiffr safehasattrrr[ xdiffblocksr@rrr chooseblocksfuncs rlc cs@|durt}|js|js|jrt||d}t||d}t|||}t|D]v\}}|dkr6||d}ngd}|d|d|d|dg}|d|dksX|d|dkrd} |jr|duret|}|durmt|}t|d ||d|d} t|d ||d|d} | | krd } || fV|d fVq'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!rDrC) defaultoptsr0r2r7r:rl enumerater3 splitnewlinesjoin) text1text2rrHrJdiffirKstypeoldnewrrr allblockss4       r|csfdfdd }gdf} |s|s| Sjrd} } nd} d} td} t|}t|}|rN|r@|r@t|t|kr@||kr@| Sg} dd |gff}| |fS|s|d  }t|}|dured || }n d | ||||f}d | ||||f}||g} t|}ddd|f}d|gdd|D}|r|dd 7<|t j ||ff}| |fS|s |d  }t|}d | ||||f}|durd|| }n d| ||||f}||g} t|}d|ddf}d|gdd|D}|r|dd 7<|t j ||ff}| |fSt ||d}t |s| Sd | ||||fd| ||||fg} | |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. Ncs(js js d|S|rd|vrdSdS)Ns %s  ro)gitnodates)datefnr@rr datetags  zunidiff..datetagrrosa/sb/)rrsBinary file %s has changed r/s--- /dev/null%ss --- %s%s%ss+++ %s%srrs@@ -0,0 +1,%d @@ cSg|]}d|qS+rr"errr rA4zunidiff..s+++ /dev/null%ss +++ %s%s%ss@@ -1,%d +0,0 @@ cSr-rrrrr rADrr@N) noprefixr datestrr pconvertrFendswithrrrZrMISSING_NEWLINE_MARKER_unidiffnext)aadbbdfn1fn2binaryrrsentinelaprefixbprefixepoch headerlineshunkswithout_newlinel1l2size hunkrange hunklinesrr@r unidiffsp      +          rc#sttfddfdd}ddgfdd}d }d}d }tD]\}} |\} } } } | d krP| d krO|| | | | 7}q3g}| | }| | }| |8} | |8} || }|| }d }|r||d jd kr|}|d }|d}n|sd}dV||D]}|Vq|r| |d <| |d<|d}n|| || |g}dd|| D|t|d <dd|D|t|d <dd|D|t|d <q3|r|sd}dV||D]}|Vqd S|sd Vd Sd S)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. cs|j}||kr |}|Srr)r?rFretr@rr contextendd z_unidiff..contextendcs|j}|dkr dS|SNrr)r?rr@rr contextstartjrz_unidiff..contextstartrroc3s|\}}}}}|t}||}||||}d} jrY\} } t|d| ddD]%} | ddrTd| } t| rN| dd} | d<nq/|d<|r_|d7}|re|d7}||||f} d| | fg|fdd t||D} d }d s||tdkrtt| dddD]%} | |  d r| |  drd }| | d 7<| | dt j nq|sd s||tdkrtt| dddD]} | |  dr| | d 7<| | dt j nq| | fVdS)Nrorrrr})s@@ -%d,%d +%d,%d @@%s csg|]}d|qSr}rr"x)rrr rAr%z/_unidiff..yieldhunk..Fr/)rr}Tr) rFshowfuncr xrangeisalnumrstripr isasciistrr startswithinsertrr)rSastartrdbstartrfdeltaaendalenblenfunclastposrwrrskiprrrlastfuncrt1t2rr yieldhunkrs\     "z_unidiff..yieldhunkNFrnrDrrTcSrrrrrrr rArz_unidiff..cSrrrrrrr rArcSrrrrrrr rAr)rrr|rrF)rrrrrrS ignoredlines has_hunksrxrgrcrdrerfrrzr{rrprevrrrr rVsh   @      "  rcCsdd}d dd}|durd}|durd}||krdSg}|d|d t||t|D] }|||q2|d d|S) z print base85-encoded binary diffcSsVt|}|dkrttd|d}n t|dtdd}d|t|dfS)NAras%c%s T)rFr bytechrordr b85encode)liner?rrr fmtlines zb85diff..fmtline4css@t|}d}||kr||||V||7}||ks dSdSrrE)r8csizer?rwrrr chunkszb85diff..chunkNrosGIT binary patch s literal %d r/)r)rZrFzlibcompressrs)totnrrrr?rrr b85diffs    rcCsnd}g}|t|kr2td|||d\}}}|d7}|||||||7}|t|ks d|S)Nr>lll ro)rFstructunpackrZrs)binpostp1p2r?rrr patchtexts  rcCs&t|dkr t|dSt||gS)Nrr)rFr bufferrpatches)rrrrr patchs  rcCsddt||DS)NcSs*g|]}|d|d|d|dfqS)rrmrr)r"drrr rA$s*z'get_matching_blocks..)rr[)rrrrr get_matching_blocks#srcCs|r tddd|SdS)Nrrrorpack)rVrrr trivialdiffheader'srcCstdd||S)Nrrr)oldlennewlenrrr replacediffheader+sr)Tr)NNN), __future__rr4rri18nrr rrrrr r r utilsr importmodrrr[r1r patchedsizetextdiffrrobjectrrpr:rRrYrhrlr|rrrrrrrrrrrr sB      :   ( * S%