$Jc@sddklZddklZlZlZddkZddkZddkZddk Z ddk Z ddk Z ddk Z ddk ZddkZddkZddkZddkZddkZeidZdefdYZdefdYZd Zd Zd2Zd3Zd4ZdefdYZdZ defdYZ!eidZ"eidZ#defdYZ$defdYZ%defdYZ&de&fdYZ'de&fdYZ(dZ)d Z*d!Z+de-d"Z.d de-dd#Z/he-d$Z0d d%Z1d&Z2hd'd(Z3d dhd'd)Z4d*Z5d+Z6dddddd,Z7d-de-dd.Z8d/Z9d0d1Z:dS(5i(t_(thextnullidtshortNsdiff --git a/(.*) b/(.*)t PatchErrorcBseZRS((t__name__t __module__(((s"/sys/lib/python/mercurial/patch.pyRstNoHunkscBseZRS((RR(((s"/sys/lib/python/mercurial/patch.pyRscCsg}||gD]}|ti|||q~\}}tii|otitd|ntii|}|oXtii| oDyti |Wqt j o titd|qXnti ||dS(Ns,cannot create %s: destination already existss8cannot create %s: unable to create destination directory( tutilt canonpathtostpathtexiststAbortRtdirnametisdirtmakedirstIOErrortcopyfile(tsrctdsttbasedirt_[1]txtabssrctabsdsttdstdir((s"/sys/lib/python/mercurial/patch.pyRs< cCstidti}tidd\}}ti|d}ytiii |}|d}|d}d|i dd j} d&} d&} d&} g} |oo|i d o8|i d }|d jo||d i}qn|idd}|id|n|o|id|nd }d'}d }x|iD]}|i}|id|||joqOn|idt}|i|}|ot}t}|itd|id |d 7}ti}xy||id  iD]^}|i do:|itdt}|id |id&}n|o|i do|d}|id|q1|i do|d} q1|i do|d} q1|i do|d } q1|i d!o| i|d q1n|d"jo| o t}n|i d# o&| o|i||id$q q W|i }|o2|i||i!d$p|id$qqqO| o&|o|djo|d$|7}qOqOWWn!|i"ti#|nX|o%|i | od%||f}n|i"|p-ti#|d&||| | d&d&d&fSn| o| i$d pd&}| o| i$d pd&}|||| | | ||fS((s?extract patch from data read from fileobj. patch can be a normal patch or contained in an email message. return tuple (filename, message, user, date, node, p1, p2). Any item in the returned tuple can be None. If filename is None, fileobj did not contain a patch. Caller must unlink filename when done.s^^(?:Index:[ \t]|diff[ \t]|RCS file: |retrieving revision [0-9]+(\.[0-9]+)*$|(---|\*\*\*)[ \t])tprefixs hg-patch-twtSubjecttFromsgit-send-emailsX-Mailerts[PATCHt]iis t s Subject: %s s From: %s s text/plains text/x-diffs text/x-patchsContent-Type: %s tdecodesfound patch at byte %d s# HG changeset patchspatch generated by hg export s# User is# Date s # Branch i s # Node ID i s # Parent s---s# s s%s %sN(s text/plains text/x-diffs text/x-patch(%tretcompilet MULTILINEttempfiletmkstempR tfdopentemailtParsertparsetgettNonet startswithtfindtlstriptreplacetdebugtwalktget_content_typet get_payloadtTruetsearchtFalseRtstartt cStringIOtStringIOt splitlinestseekttruncatetappendtwritetgetvaluetendswithtclosetunlinktpop(tuitfileobjtdiffretfdttmpnamettmpfptmsgtsubjecttusert gitsendmailtdatetnodeidtbranchtparentstpendt diffs_seentok_typestmessagetpartt content_typetpayloadtmthgpatcht ignoretexttcfptlinetp1tp2((s"/sys/lib/python/mercurial/patch.pytextract,s                        iiit patchmetacBs eZdZdZdZRS(sPatched file metadata 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY or COPY. 'path' is patched file path. 'oldpath' is set to the origin file when 'op' is either COPY or RENAME, None otherwise. If file mode is changed, 'mode' is a tuple (islink, isexec) where 'islink' is True if the file is a symlink and 'isexec' is True if the file is executable. Otherwise, 'mode' is None. cCs:||_d|_d|_d|_d|_t|_dS(NtMODIFYi(R R-toldpathtmodetoptlinenoR8tbinary(tselfR ((s"/sys/lib/python/mercurial/patch.pyt__init__s      cCs'|d@}|d@}||f|_dS(Ni i@(Rf(RjRftislinktisexec((s"/sys/lib/python/mercurial/patch.pytsetmodes  (RRt__doc__RkRn(((s"/sys/lib/python/mercurial/patch.pyRcs  c Csd}g}d}d}xP|D]H}|d7}|id}|idocti|}|oI|o|i|n|idd\}}t|}||_qgq|o|idoB|i djo|t O}n|i|d}|t O}qn|id od|_ |d |_ qg|id o|d |_ qg|id od|_ |d |_ qg|ido|d|_ qg|ido'd|_ |it|ddqg|ido'd|_ |it|ddqg|ido|it|ddqg|ido|tO}t|_qgqqW|o|i|n|p t }n||fS(s9extract git-style metadata about patches from iis s diff --gitis--- tCOPYtRENAMEs rename from i s rename to i s copy from scopy to is deleted filetDELETEisnew file mode tADDs new mode sGIT binary patchN(RpRq(R-trstripR.tgitretmatchR?tgroupRcRhRgt GP_FILTERtGP_PATCHReR Rntintt GP_BINARYR6Ri( tlrtgpt gitpatchestdopatchRhR_R[RR((s"/sys/lib/python/mercurial/patch.pyt readgitpatchsd          t linereadercBs/eZedZdZdZdZRS(cCs||_g|_||_dS(N(tfptbufttextmode(RjRR((s"/sys/lib/python/mercurial/patch.pyRks  cCs%|dj o|ii|ndS(N(R-RR?(RjR_((s"/sys/lib/python/mercurial/patch.pytpushs cCsh|io|id}|id=|Sn|ii}|io"|ido|d d}n|S(Nis is (RRtreadlineRRB(Rjtl((s"/sys/lib/python/mercurial/patch.pyRs   ccs'x |i}|pPn|VqdS(N(R(RjR((s"/sys/lib/python/mercurial/patch.pyt__iter__s  (RRR8RkRRR(((s"/sys/lib/python/mercurial/patch.pyRs   s&@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@s((---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)t patchfilecBsteZed dZdZdZdZdZdZ dZ dZ d dZ d Z d ZRS( cCs||_||_||_||_g|_t|_||_|p9y|i||_t |_Wqt j oqXn|ii t d|ih|_ d|_d|_g|_t|_|itd|_dS(Ns!unable to find '%s' for patching i(tfnameteoltopenerRFtlinesR8R tmissingt readlinesR6RtwarnRthashtdirtytoffsettrejt fileprintedt printfilethunks(RjRFRRRR((s"/sys/lib/python/mercurial/patch.pyRk s*               cCsD|i|d}z tt||idj SWd|iXdS(Ntr(RtlistRRR-RC(RjRR((s"/sys/lib/python/mercurial/patch.pyR"s cCs|i|d}zz|io_|idjoOxY|D]@}|o&|ddjo|d |i}n|i|q6Wn|i|Wd|iXdS(NRs i(RRR@t writelinesRC(RjRRRR((s"/sys/lib/python/mercurial/patch.pyR)scCsti|dS(N(R RD(RjR((s"/sys/lib/python/mercurial/patch.pyRD6scCsu|iodSn|p |iio t|_ntd|i}|o|ii|n|ii|dS(Nspatching file %s (RRFtverboseR6RRRtnote(RjRts((s"/sys/lib/python/mercurial/patch.pyR9s  csSy|i|}Wn gSnXt|djo|idfdn|S(Nitkeycst|S((tabs(R(tlinenum(s"/sys/lib/python/mercurial/patch.pytQs(Rtlentsort(RjRRtcand((Rs"/sys/lib/python/mercurial/patch.pyt findlinesEscCsIh|_x9t|iD](\}}|ii|gi|qWdS(N(Rt enumerateRt setdefaultR?(RjRR((s"/sys/lib/python/mercurial/patch.pyt hashlinesTs  cstipdSnid}iitdtii|ffd}i||dS(Ns.rejs7%d out of %d hunks FAILED -- saving rejects to file %s c3sotiii}d||fVxDiD]9}x0|iD]%}|V|ddjo dVq>q>Wq.WdS(Ns--- %s +++ %s is s \ No newline at end of file (R R tbasenameRRthunk(tbaseRR(Rj(s"/sys/lib/python/mercurial/patch.pytrejlinesgs  (RRRFRRRRR(RjRR((Rjs"/sys/lib/python/mercurial/patch.pyt write_rejYs     cCs=|ipdSn|p |i}n|i||idS(N(RRRR(Rjtdest((s"/sys/lib/python/mercurial/patch.pyR@rs   cCs|i|idS(N(R@R(Rj((s"/sys/lib/python/mercurial/patch.pyRCys c Cs|ipJttd|i|it|i|it|i|i fn|i d7_ |o|i n|i o|i i|dSn|ioB|io5|iitd|i|i i|dSnt|to]|io|i|in5|i|i(|it|i7_d|_dSn|i}|idjo d}n|i|id}|}ti||i|djoh|io|i|in@|i|i|||i+|i|i |i7_d|_dSn|i |i!dddjot|i}n|}x{t"dD]m}xdt#t$gD]V}|i||}|i%|dd|} x!| D]} ti||i| djo|i||} | |i| | t|+|it| t|7_d|_|o'd|} |ii} |i&t#nd } |ii'} | ||}|djotd }n td }| ||i| d| |f|SqqWqxWqeW|i&t#|iitd |i|f|i i|dS( Nsbad hunk #%d %s (%d %d %d %d)iisfile %s already exists iR!is with fuzz %d Rs-Hunk #%d succeeded at %d %s(offset %d line). s.Hunk #%d succeeded at %d %s(offset %d lines). sHunk #%d FAILED at %d ((tcompleteRRtnumbertdescRtatlenatbtlenbRtreverseRRR?R t createfileRFRRt isinstancetgithunktrmfileRDtnewRRRtoldtstartat diffhelpersttesthunkRRtxrangeR6R8RRR(RjthRRR9t orig_startt search_starttfuzzlenttoponlyRRtnewlinestfuzzstrtfRRL((s"/sys/lib/python/mercurial/patch.pytapply}s  *                ! #N(RRR8R-RkRRRDRRRRR@RCR(((s"/sys/lib/python/mercurial/patch.pyRs       RcBseZeedZdZdZdZdZdZdZ dZ dZ d ed Z d Z d ed ZRS( cCss||_||_|g|_g|_g|_|o|i|n|i|||_|o| |_dS(N( RRRRRtread_context_hunktread_unified_hunktcreatetremove(RjRtnumR|tcontextRR((s"/sys/lib/python/mercurial/patch.pyRks       cCsoti|i}|pttd|in|i\|_}|_|_ }|_ |idjo d|_nt |i|_|i djo d|_ nt |i |_ t |i|_t |i |_ t i||i|i|i |i|ix[t|iddjo@|id=|id=|id=|id8_|i d8_ qWdS(Ns bad hunk #%diii(tunidescRvRRRRtgroupsRRtstartbRR-RzRtaddlinesRRRR(RjR|R[tfootfoo2((s"/sys/lib/python/mercurial/patch.pyRs&*  +   cCsN|i|_ti|i}|pttd|in|i\}|_}}}t |i|_|djo |i}nt ||i|_ |io|i d7_ nxt |i D]}|i}|i do|i|Pn|d} |i dp|i dod| } n>|i dod | } n ttd |i|f|ii| |ii| qW|i}|i d o;|id d } | |id <| |id <|i}nti|}|pttd|in|i\}|_}} }t |i|_| djo |i} nt | |i|_|io|id7_nd} xt |iD]}|i}|i d o6|id d } | |id <| |i| d}|i dp|i d o|ii|dqqWnd|i|i |i|if|_|i|id to apply to the working directory. returns whether patch was applied with fuzz factor.s-d %ss%s %s -p%d < %sR!s spatching file s with fuzzissaving rejects to filetFAILEDspatch command failed: %sN(R8R?Rt shellquotetpopenRRtRR.tparse_patch_outputRR-R/R6RRCRRt explain_exit( tpatchertargst patchnameRFRR1RZRRR_tpft printed_filetcode((s"/sys/lib/python/mercurial/patch.pyt externalpatchNs>     tstrictc Cs6|d jo|iddd}ny/hd d<dd<dd<|i}Wn,tj o titd|nXyt|d }Wntj o |}nX|ot i }t i |nz"t |||d |d|} Wd |ot i |nX| d jo t n| d jS( swuse builtin patch to apply to the working directory. returns whether patch was applied with fuzz factor.tpatchRRis tcrlfs tlfs!Unsupported line endings type: %strbRNi(R-REtlowertKeyErrorRR Rtopent TypeErrorR R,tchdirR2R( tpatchobjRFRR1RZteolmodeRRtcurdirR/((s"/sys/lib/python/mercurial/patch.pyt internalpatchrs( /  "  c CsD|idd}g}y|o t|||||||Snyt||||||SWntj o~tidptidpd}|itd|tio|i dnt|||||||SnXWnPt j oD}t |} | oti | q@ti tdnXdS(sApply to the working directory. 'eolmode' specifies how end of lines should be handled. It can be: - 'strict': inputs are read in binary mode, EOLs are preserved - 'crlf': EOLs are ignored when patching and reset to CRLF - 'lf': EOLs are ignored when patching and reset to LF - None: get it from user settings, default to 'strict' 'eolmode' is ignored when using an external patcher program. Returns whether patch was applied with fuzz factor. RFRjR%s-no valid hunks found; trying with %r instead s--binaryspatch failed to applyN( RERhRvRRtfind_exeR2RtneedbinarypatchR?RRR ( RdRFRR1RZRtRbRcR&R((s"/sys/lib/python/mercurial/patch.pyRjs*  &  c Csd}d}dd}||}||}||jodSnd||t|fg}x0|ti|D]}|i||q}W|iddi|S(s print base85-encoded binary diffcSsI|p ddSnt|}tid|}|i||iS(Nt0i(sblob %d(RRtsha1tupdatet hexdigest(RRR((s"/sys/lib/python/mercurial/patch.pytgitindexs    cSsot|}|djottd|d}nt|dtdd}d|ti|tfS(NiRiRs%c%s (RtchrRRt b85encodeR6(R_R((s"/sys/lib/python/mercurial/patch.pytfmtlines   i4cssEt|}d}x,||jo||||!V||7}qWdS(Ni(R(RtcsizeRR((s"/sys/lib/python/mercurial/patch.pytchunks  Rs)index %s..%s GIT binary patch literal %s s (RRtcompressR?R( ttottnR}RRttohashttnhashR/R((s"/sys/lib/python/mercurial/patch.pytb85diffs       cCs7||jo&|id||id|ndS(Ns old mode %s s new mode %s (R?(theadertomodetnmode((s"/sys/lib/python/mercurial/patch.pyt _addmodehdrs c%cs |djo ti}n|p|iid}nd}|}||}||} |p|i|| d|}n|d \} } } | o| o| odSnti|i} |i }|i i o d}nS|i i ot pt}g}||gD]}|o|||qq~}|ioYti||| |t\}}|i}x(|iD]\}}||| sPH0$  f ;! ? ~  B ) $$ & r  (