
    6h                      S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	SSK
Jr  SSKJrJrJr  SSKJrJrJrJrJrJrJrJrJrJrJrJrJr  SSKJ r J!r!J"r"J#r#  \RH                  (       a  S SK%r%S SKJ&r&J'r'  \RP                  r(\RR                  " S	5      r*\RR                  " S
5      r+\RR                  " S5      r,\RZ                  r-\R\                  r.\R^                  r/S r0/ SQr1\Rd                  S 5       r3S r4 " S S5      r5S r6 " S S5      r7 " S S5      r8 " S S\85      r9 " S S\95      r: " S S5      r; " S S\85      r<\RR                  " S5      r=\RR                  " S 5      r>/ S!Qr? " S" S#5      r@ " S$ S%5      rA " S& S'5      rBS( rCSTS) jrD " S* S+5      rE " S, S-5      rFS. rGS/ rHSTS0 jrIS1 rJS2 rKS3 rLS4 rMS5 rNS6 rOSUS7 jrPS8 rQ SUS9 jrRS: rS SVS; jrT    SWS< jrU SVS= jrV     SXS> jrWSYS? jrX " S@ SA\Y5      rZ\R                  r\\R                  r[\R                  r]          SZSB jr^       S[SC jr_SD r`SE raS\SF jrbSG rcSH rdSI reSJSKSLSM.rfSN rgSO rhSP riSQ rjS]SR jrkSS rlg)^    )annotationsN   _)hexsha1nodeconstantsshort)copies
diffhelperdiffutilencodingerrormailmdiffpathutilpycompatscmutilsimilarutilvfs)dateutilhashutilprocutil
stringutil)AnyIterators   diff --git a/(.*) b/(.*)s   (\t+|[^\t]+)s9   (\t+| +|[a-zA-Z0-9_\x80-\xff]+|[^ \ta-zA-Z0-9_\x80-\xff])c                >  ^^ S mS mU4S jnU4S jnU4S jnUU4S jnU4S jn " S S	5      nS
n/ nS/n	[        U S5      (       d  U" U 5      n U  H  n
UR                  U
5        U
R                  S5      (       a
  U" X5      s  $ U
R                  S5      (       a
  U" X5      s  $ T" X5      (       a5  SnU
R                  SS5      S   R	                  5       U	;   a
  U" X5      s  $ M  U
R                  S5      (       d  M  U(       d  M  U" X5      s  $    U" U5      $ )z6return an iterator of individual patches from a streamc                    U(       a  U R                  S5      (       a  gU R                  S5      (       a  gU R                  SS5      n[        U5      S:H  =(       a    SUS	   ;  $ )
N)       	T)r      -   +F   : r      r   r   )
startswithsplitlen)lineinheaderls      1/usr/lib/python3/dist-packages/mercurial/patch.pyisheadersplit.<locals>.isheaderJ   sU    66??-..JJua 1v{/t1Q4//    c                6    [        SR                  U 5      5      $ Nr.   )stringiojoin)liness    r+   chunksplit.<locals>.chunkT   s    ((r.   c              3     >#    SnU  HV  nUR                  5       (       d  SnU(       d$  UR                  S5      (       a  T" U5      v   / nSnUR                  U5        MX     U(       a  T" U5      v   g g 7f)NTF   # HG changeset patch)stripr%   append)streamcurr)   r(   r4   s       r+   hgsplitsplit.<locals>.hgsplitW   sk     D::<< 0G H HCj JJt  * s   A2A5c              3     >#    U  HH  nUR                  S5      (       a  [        T" USS  5      5       S h  vN   / nUR                  U5        MJ     U(       a  [        T" USS  5      5       S h  vN   g g  N@ N7f)N   From r   )r%   r&   r9   )r:   r;   r(   r4   s      r+   	mboxsplitsplit.<locals>.mboxsplitg   st     Dx(( s12w000JJt  U3qr7^,,,  1 -s!   3A;A79A;0A91A;9A;c              3  8  >#    S nU  H  nUR                  U5        M     T	" U5      n[        R                  " U5      nUR                  5       (       d  U" U5      v   g SnUR	                  5        H$  nUR                  5       nX;  a  M  U" U5      v   M&     g 7f)Nc                    [        5       n[        R                  " USS9nUR                  U 5        UR	                  S5        U$ )NF)mangle_from_r   )r1   r   	Generatorflattenseek)mfpgs      r+   msgfp'split.<locals>.mimesplit.<locals>.msgfps   s4    Br6AIIaLGGAJIr.   )z
text/plainztext/x-diffztext/x-patch)r9   r   parseis_multipartwalkget_content_type)
r:   r;   rK   r(   crH   ok_typespartctr4   s
            r+   	mimesplitsplit.<locals>.mimesplitr   s     	 DJJt #JJJqM~~(NDH**,%Dk!	 !s   BBc              3     >#    SnU  HL  nU(       d  T" X25      (       a  T" U5      v   / nSnU(       a  T" X25      (       d  SnUR                  U5        MN     U(       a  T" U5      v   g g 7fNFTr9   )r:   r;   r)   r(   r4   r,   s       r+   headersplitsplit.<locals>.headersplit   sh     D 8 8Cj  8 8 JJt  * s   A(A+c              3  "   >#    T" U 5      v   g 7fN )r;   r4   s    r+   	remaindersplit.<locals>.remainder   s     Cjs   c                  *    \ rS rSrS rS rS r\rSrg)split.<locals>.fiter   c                    Xl         g r]   rI   selfrI   s     r+   __init__split.<locals>.fiter.__init__   s    Gr.   c                    U $ r]   r^   rg   s    r+   __iter__split.<locals>.fiter.__iter__   s    Kr.   c                T    U R                   R                  5       nU(       d  [        eU$ r]   )rI   readlineStopIterationrg   r*   s     r+   nextsplit.<locals>.fiter.next   s"      "A##Hr.   re   N)	__name__
__module____qualname____firstlineno__rh   rl   rr   __next____static_attributes__r^   r.   r+   fiterrb      s    			 r.   rz   Fs   content-typerr   r7   r?   T   :r   r      --- )hasattrr9   r%   r&   lower)r:   r<   r@   rU   rZ   r_   rz   r)   r;   mimeheadersr(   r4   r,   s              @@r+   r&   r&   G   s   0) 	-"2   H
C"#K66""v

4??2336''__X&&V))d%%Hzz$"1%++-< -- = __W%%((v++ " S>r.   ))s   Dates   date)s   Branchs   branch)s   Node ID   nodeidc              #  &  #    [         R                  " SS9u  p#[        R                  " US5      n [	        XX45      v   UR                  5         [        R                  " U5        g! UR                  5         [        R                  " U5        f = f7f)at  extract patch from data read from fileobj.

patch can be a normal patch or contained in an email message.

return a dictionary. Standard keys are:
  - filename,
  - message,
  - user,
  - date,
  - branch,
  - node,
  - p1,
  - p2.
Any item can be missing from the dictionary. If filename is missing,
fileobj did not contain a patch. Caller must unlink filename when done.	   hg-patch-prefixwbN)r   mkstemposfdopen_extractcloseunlink)uifileobjfdtmpnametmpfps        r+   extractr      sh     $ "",7KBIIb$ErG33
		' 	
		's   .BA& 'B&(BBc           	     :
   [         R                  " S[         R                  [         R                  -  5      n0 n[        R
                  " U5      nUS   =(       a    [        R                  " US   5      nUS   =(       a    [        R                  " US   5      US'   U(       d3  US   (       d)  SR                  S UR                  5        5       5      S-   n/ nUS   n	U	(       a/  [        R                  " U	5      =US'   n	U R                  S	U	-  5        U(       an  UR                  S
5      (       a,  UR                  S5      n
U
S:  a  XzS-   S  R                  5       n[         R                  " SSU5      nU R                  SU-  5        US   (       a  U R                  SUS   -  5        SnSnSnUR                  5        GH  n[        R                   " UR#                  5       5      nU R                  SU-  5        X;  a  MC  [$        R&                  " [(        UR+                  SS95      nUR-                  U5      nU(       Ga6  SnSnSnU R                  SUR/                  S5      -  5        US-  n[1        5       nUS UR/                  S5       R3                  5        GH  nUR                  S5      (       a@  U(       d9  U R                  S5        SnSnUR5                  S5        UR7                  5         S nOU(       a  UR                  S5      (       a   USS  US'   U R                  SUS   -  5        OUR                  S5      (       a#  UR9                  USS  R                  5       5        OyUR                  S5      (       aX  [:         HM  u  nnS U-  nUR                  U5      (       d  M#  U[=        U5      S  UU'   U R                  S!UUU   4-  5        MO     OSnOUS":X  a  SnU(       a  GMS  U(       a  GM]  UR?                  U5        UR?                  S5        GM     URA                  5       nU(       a>  UR?                  U5        URC                  S5      (       d  UR?                  S5        GM  GM  GM  U(       a  GM  U(       d  GM  US#:X  d  GM  USU-   -  nGM     U(       a  UR                  U5      (       d  S$X}4-  nXS%'   URE                  5         U(       a/  URG                  S5      US&'   U(       a  URG                  S5      US''   U(       a  X%S('   U$ ))Ns}   ^(?:Index:[ \t]|diff[ \t]-|RCS file: |retrieving revision [0-9]+(\.[0-9]+)*$|---[ \t].*?^\+\+\+[ \t]|\*\*\*[ \t].*?^---[ \t])SubjectFroms   user   
c              3  t   #    U  H.  nS R                  [        [        R                  U5      5      v   M0     g7f)r#   N)r2   mapr   
strtolocal.0hs     r+   	<genexpr>_extract.<locals>.<genexpr>  s,      ALA

3x22A677s   68zX-Mercurial-Noder   s   Node ID: %s
s   [PATCH   ]r   r   s   \n[ \t]+r   s   Subject: %s
s	   From: %s
)
   text/plains   text/x-diffs   text/x-patchr.   s   Content-Type: %s
T)decodeFs   found patch at byte %d
r7   s   patch generated by hg export
s   # User    s	   # Parent 	      # s   # %s s   %s: %s
   ---r   s   %s
%ss   messages   p1s   p2s   filename)$recompile	MULTILINEDOTALLr   rM   
headdecoder2   itemsdebugr%   findlstripsubrO   r   bytestrrP   typingcastbytesget_payloadsearchstartr1   
splitlinesrG   truncater9   patchheadermapr'   writegetvalueendswithr   pop)r   r   r   r   diffredatamsgsubjectparentsnodeidpend
diffs_seenrR   messagerS   content_typepayloadrH   hgpatchhgpatchheader
ignoretextcfpr(   headerkeyr   s                             r+   r   r      sW    ZZ	% 	ryy F D
**W
C)n@Y!@GK@DOOCK$@DM4= JJ AD   	 G#$F#'??6#::Y&
!F*+i((<<%Dqy!(*-446&&tW5
!G+,G}
g./J?HG 
''(=(=(?@
&56'
 ++eT%5%5T%5%BCMM'"G!MJHH01771:=>!OJ*C!''!*-88:??#:;;GHH>?"G$(MHHQKLLN"G"z22(,QRWg!>?66tABx'89//+9KFC%-%6F#v66,0V,?S	 "S	7J)J K	 ,: ).V^!%J$}ZZIIdOIIe$7 ;8 llnGG$''..KK& /  LM,Iuw&Gk n w))'22w00	KKMkk!nU!++a.DK#[Kr.   c                  B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)	patchmetaid  a  Patched 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.
c                H    Xl         S U l        S U l        SU l        SU l        g )Ns   MODIFYF)patholdpathmodeopbinary)rg   r   s     r+   rh   patchmeta.__init__o  s#    		r.   c                (    US-  nUS-  nX#4U l         g )Ni    @   )r   )rg   r   islinkisexecs       r+   setmodepatchmeta.setmodev  s    $	r.   c                    [        U R                  5      nU R                  Ul        U R                  Ul        U R                  Ul        U R
                  Ul        U$ r]   )r   r   r   r   r   r   )rg   others     r+   copypatchmeta.copy{  sA    $))$YY
77{{r.   c                v    US:X  a  U R                   S:H  $ USU R                  =(       d    U R                  -   :H  $ )N	   /dev/null   ADD   a/)r   r   r   )rg   afiles     r+   _ispatchingapatchmeta._ispatchinga  s6    L 77f$$!:;;;r.   c                P    US:X  a  U R                   S:H  $ USU R                  -   :H  $ )Nr      DELETE   b/r   r   )rg   bfiles     r+   _ispatchingbpatchmeta._ispatchingb  s-    L 77i''		)))r.   c                T    U R                  U5      =(       a    U R                  U5      $ r]   )r   r   )rg   r   r   s      r+   
ispatchingpatchmeta.ispatching  s#      'DD,=,=e,DDr.   c                @    SU R                   < SU R                  < S3$ )Nz<patchmeta  >r   rk   s    r+   __repr__patchmeta.__repr__  s    &*ggtyy99r.   )r   r   r   r   r   N)rt   ru   rv   rw   __doc__rh   r   r   r   r   r   r   ry   r^   r.   r+   r   r   d  s+    %
<
*
E:r.   r   c                L   Sn/ nU  GH   nUR                  S5      nUR                  S5      (       aT  [        R                  U5      nU(       a6  U(       a  UR	                  U5        UR                  S5      n[        U5      nM}  M  U(       d  M  UR                  S5      (       a  UR	                  U5        SnM  UR                  S5      (       a  SUl        USS Ul        M  UR                  S	5      (       a  US
S Ul	        M  UR                  S5      (       a  SUl        US
S Ul        GM(  UR                  S5      (       a  USS Ul	        GMK  UR                  S5      (       a
  SUl        GMk  UR                  S5      (       a(  SUl        UR                  [        USS S5      5        GM  UR                  S5      (       a!  UR                  [        USS S5      5        GM  UR                  S5      (       d  GM  SUl        GM     U(       a  UR	                  U5        U$ )z9extract git-style metadata about patches from <patchname>N   
   diff --git a/r$   r|   s   rename from    RENAME   s
   rename to 
   s
   copy from    COPYs   copy to    s   deleted filer   s   new file mode r   is	   new mode    GIT binary patchT)rstripr%   gitrematchr9   groupr   r   r   r   r   intr   )lrgp
gitpatchesr(   rH   dsts         r+   readgitpatchr
    s    
BJ{{7#??+,,D!A%%b)ggajs^	 
 Rw''!!"%//!!"#Y
//rs)//!"#Y
--qr(11!!233

3tBCy!,-..

3tBCy!,-!455 	A B 
"r.   c                  ,    \ rS rSrS rS rS rS rSrg)
linereaderi  c                    Xl         / U l        g r]   )rI   bufrf   s     r+   rh   linereader.__init__  s    r.   c                B    Ub  U R                   R                  U5        g g r]   )r  r9   rg   r(   s     r+   pushlinereader.push  s    HHOOD! r.   c                    U R                   (       a  U R                   S   nU R                   S	 U$ U R                  R                  5       $ Nr   )r  rI   ro   rq   s     r+   ro   linereader.readline  s9    88AHww!!r.   c                .    [        U R                  S5      $ r0   )iterro   rk   s    r+   rl   linereader.__iter__  s    DMM3''r.   )r  rI   N)	rt   ru   rv   rw   rh   r  ro   rl   ry   r^   r.   r+   r  r    s    ""(r.   r  c                  >    \ rS rSrS rS rS rS rS rS r	S r
S	rg
)abstractbackendi  c                    Xl         g r]   r   )rg   r   s     r+   rh   abstractbackend.__init__  s    r.   c                    [         e)zpReturn target file data and flags as a (data, (islink,
isexec)) tuple. Data is None if file is missing/deleted.
NotImplementedErrorrg   fnames     r+   getfileabstractbackend.getfile  s
     "!r.   c                    [         e)zWrite data to target file fname and set its mode. mode is a
(islink, isexec) tuple. If data is None, the file content should
be left unchanged. If the file is modified after being copied,
copysource is set to the original file name.
r   rg   r#  r   r   
copysources        r+   setfileabstractbackend.setfile  s
     "!r.   c                    [         e)zUnlink target file.r   r"  s     r+   r   abstractbackend.unlink  s    !!r.   c                    g)zWrite rejected lines for fname. total is the number of hunks
which failed to apply and total the total number of hunks for this
files.
Nr^   )rg   r#  failedtotalr3   s        r+   writerejabstractbackend.writerej  s    r.   c                    [         er]   r   r"  s     r+   existsabstractbackend.exists      !!r.   c                    [         er]   r   rk   s    r+   r   abstractbackend.close  r5  r.   r  N)rt   ru   rv   rw   rh   r$  r)  r   r0  r3  r   ry   r^   r.   r+   r  r    s%    """""r.   r  c                  F   ^  \ rS rSrU 4S jrS rS rS rS rS r	Sr
U =r$ )		fsbackendi  c                Z   > [         TU ]  U5        [        R                  " U5      U l        g r]   )superrh   vfsmodr   opener)rg   r   basedir	__class__s      r+   rh   fsbackend.__init__  s     jj)r.   c                X   U R                   R                  U5      (       a  U R                   R                  U5      S4$ Sn U R                   R                  U5      R                  S-  S:g  n U R                   R                  U5      SU44$ ! [
         a     N,f = f! [
         a     gf = f)NTFFr   r   NN)r=  r   readlinklstatst_modeFileNotFoundErrorread)rg   r#  r   s      r+   r$  fsbackend.getfile  s    ;;e$$KK((/??	[[&&u-55=BF	KK$$U+eV_== ! 		 ! 		s$   +B -B 
BB
B)(B)c                   Uu  pVUc  U R                   R                  XU5        g U(       a  U R                   R                  X!5        g U R                   R                  X5        U(       a  U R                   R                  USS5        g g rX   )r=  setflagssymlinkr   )rg   r#  r   r   r(  r   r   s          r+   r)  fsbackend.setfile  sj    <KK  7KK,KKe*$$UE48 r.   c                r    U R                   R                  SS5      nU R                  R                  USUS9  g )Ns   experimentals   removeemptydirsT)ignoremissingrmdir)r   
configboolr=  
unlinkpath)rg   r#  rP  s      r+   r   fsbackend.unlink  s2    ""?4FGuDFr.   c                    US-   nU R                   R                  [        S5      X#U4-  5        U R                  US5      nUR	                  U5        UR                  5         g )Ns   .rejs7   %d out of %d hunks FAILED -- saving rejects to file %s
   w)r   warnr   r=  
writelinesr   )rg   r#  r.  r/  r3   rI   s         r+   r0  fsbackend.writerej  sX    IJe$%	
 [[%
e

r.   c                8    U R                   R                  U5      $ r]   )r=  lexistsr"  s     r+   r3  fsbackend.exists&  s    {{""5))r.   )r=  )rt   ru   rv   rw   rh   r$  r)  r   r0  r3  ry   __classcell__r?  s   @r+   r9  r9    s'    *
9G* *r.   r9  c                  L   ^  \ rS rSrU 4S jrS rU 4S jrU 4S jrS rSr	U =r
$ )workingbackendi*  c                   > [         TU ]  XR                  5        X l        X0l        [        5       U l        [        5       U l        / U l        g r]   )	r;  rh   rootrepo
similaritysetremovedchangedcopied)rg   r   rb  rc  r?  s       r+   rh   workingbackend.__init__+  s7    YY'	$uur.   c                    U R                   R                  R                  U5      R                  (       d.  U R	                  U5      (       a  [        [        S5      U-  5      eg g Ns$   cannot patch %s: file is not tracked)rb  dirstate	get_entryany_trackedr3  PatchApplicationErrorr   r"  s     r+   _checkknownworkingbackend._checkknown3  s[    yy!!++E2>>4;;D
 D
 (9:UB D
>r.   c                   > U R                  U5        [        TU ]	  XX45        Ub  U R                  R	                  XA45        U R
                  R                  U5        g r]   )ro  r;  r)  rg  r9   rf  add)rg   r#  r   r   r(  r?  s        r+   r)  workingbackend.setfile;  sL    T6!KK
23r.   c                   > U R                  U5        [        TU ]	  U5        U R                  R	                  U5        U R
                  R	                  U5        g r]   )ro  r;  r   re  rr  rf  )rg   r#  r?  s     r+   r   workingbackend.unlinkB  sA    ur.   c           	        U R                   R                  R                  U R                   5         U R                   S    n[        U R                  5      nU R
                   H2  u  p4[        R                  " U R                  U R                   XU5        M4     U R                  (       ac  UR                  [        U R                  5      5        U R                   H/  nXPR                   R                  ;  d  M  UR                  U5        M1     U(       a+  [        R                  " U R                   X R                  5        [        U R                  5      sS S S 5        $ ! , (       d  f       g = fr]   )rb  rk  changing_filesrd  rf  rg  r   dirstatecopyr   re  forgetsorteddiscardmarktouchedrc  )rg   wctxrf  srcr	  fs         r+   r   workingbackend.closeH  s    YY..tyy999T?D$,,'G KK$$TWWdiiCH (||F4<<01A		 2 22
  * & ##DIIwH$,,'! :99s   CE6AE
E))rf  rg  re  rb  rc  )rt   ru   rv   rw   rh   ro  r)  r   r   ry   r\  r]  s   @r+   r_  r_  *  s!      ( (r.   r_  c                  4    \ rS rSrSS jrSS jrS rS rSrg)		filestorei\  Nc                ~    S U l         0 U l        SU l        Xl        U R                  c  SU l        SU l        0 U l        g )Nr   i  @ )r=  filescreatedmaxsizesizer   )rg   r  s     r+   rh   filestore.__init__]  s;    
<<&DL		r.   c                   U R                   S:  d&  [        U5      U R                  -   U R                   ::  a0  X#U4U R                  U'   U =R                  [        U5      -  sl        g U R                  c/  [
        R                  " SS9n[        R                  " U5      U l        SU R                  -  nU R                  R                  Xb5        U =R                  S-  sl	        XcU4U R                  U'   g )Nr   r   r      %dr   )r  r'   r  r   r=  r   mkdtempr<  r   r  r   r  )rg   r#  r   r   rg  ra  fns          r+   r)  filestore.setfileg  s    <<!D	DII 5$,,F $F3DIIeIIT"I{{"''|<$jj.%BKKb'LLAL!#6 2DJJur.   c                    XR                   ;   a  U R                   U   $ U R                  (       a  XR                  ;  a  gU R                  U   u  p#nU R                  R                  U5      X44$ )N)NNN)r   r=  r  rH  )rg   r#  r  r   rg  s        r+   r$  filestore.getfileu  s[    II99U##{{e::5#::e,&{{#T11r.   c                |    U R                   (       a+  [        R                  " U R                   R                  5        g g r]   )r=  shutilrmtreebaserk   s    r+   r   filestore.close}  s$    ;;MM$++**+ r.   )r  r   r  r  r=  r  r]   )	rt   ru   rv   rw   rh   r)  r$  r   ry   r^   r.   r+   r  r  \  s    32,r.   r  c                  L   ^  \ rS rSrU 4S jrS rS rS rS rS r	S r
S	rU =r$ )
repobackendi  c                   > [         TU ]  U5        X l        X0l        X@l        [        5       U l        [        5       U l        0 U l        g r]   )	r;  rh   rb  ctxstorerd  rf  re  rg  )rg   r   rb  r  r  r?  s        r+   rh   repobackend.__init__  s8    	
uur.   c                P    XR                   ;  a  [        [        S5      U-  5      eg rj  )r  rn  r   r"  s     r+   ro  repobackend._checkknown  s,     '9:UB  !r.   c                     U R                   U   nUR                  5       nUR	                  5       SU;   SU;   44$ ! [        R                   a     gf = f)NrC     l   x)r  r   LookupErrorflagsr   )rg   r#  fctxr  s       r+   r$  repobackend.getfile  sY    	88E?D 

yy{TU]DEM:::    		s   ; AAc                   U(       a  U R                  U5        Uc  U R                  U   R                  5       nU R                  R	                  XX45        U R
                  R                  U5        U(       a  X@R                  U'   g g r]   )ro  r  r   r  r)  rf  rr  rg  r'  s        r+   r)  repobackend.setfile  sh    Z(<88E?'')D

59!+KK r.   c                \    U R                  U5        U R                  R                  U5        g r]   )ro  re  rr  r"  s     r+   r   repobackend.unlink  s"    r.   c                    XR                   ;   $ r]   )r  r"  s     r+   r3  repobackend.exists  s      r.   c                4    U R                   U R                  -  $ r]   )rf  re  rk   s    r+   r   repobackend.close  s    ||dll**r.   )rf  rg  r  re  rb  r  )rt   ru   rv   rw   rh   ro  r$  r)  r   r3  r   ry   r\  r]  s   @r+   r  r    s+    ;, !+ +r.   r  s*   @@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@s.   (?:---|\*\*\*) (\d+)(?:,(\d+))? (?:---|\*\*\*))   strict   crlf   lf   autoc                  B    \ rS rSrSS jrS rS rS rS rS r	S r
S	rg
)	patchfilei  c                   UR                   U l        XPl        S U l        X0l        Xl        / U l        SU l        SU l        UR                  U l	        UR                  U l        UR                  S;   U l        UR                  S:H  U l        U R                  c  UR                  U R                  5      u  pgO UR                  U R                  5      S S u  pgUGb(  U R                  S L =(       d    UR                  U R                  5      U l        SU l        U(       a  [         R"                  " U5      U l        U R                  c  Xpl	        U R                  (       a  U R                  S   R%                  S5      (       a  SU l        O*U R                  S   R%                  S5      (       a  SU l        US	:w  aJ  / nU R                   H2  n	U	R%                  S5      (       a  U	S S
 S-   n	UR'                  U	5        M4     Xl        O,U R                  (       a  SU l        U R                  c  SU l	        U R                  (       aU  U R
                  R)                  [+        S5      U R                  -  5        U R
                  R)                  [+        S5      5        0 U l        SU l        SU l        SU l        / U l        SU l        U R9                  S5        SU l        g )NFT)r   r   r   r   r$   r   r   r   r  )FFs!   unable to find '%s' for patching
sB   (use '--prefix' to apply patch relative to the current directory)
)r   r#  eolmodeeolbackendr   r3   r3  missingr   r   r(  r   createremover$  r   splitnewlinesr   r9   rV  r   hashdirtyoffsetskewrejfileprinted	printfilehunks)
rg   r   r  r  r  r  r   r   nlinesr*   s
             r+   rh   patchfile.__init__  s3   WW

GG	**ee;;eey(??" 4JD$t7;JD//T1OW^^DJJ5ODK DL"006
yy  	zz::a=))'22&DHZZ]++E22$DHi'F!ZZ::g.. !#2Aa( ( "(J{{$yy *	<<GGLL@ADJJNOGGLL, 	
	 u
r.   c                   U R                   S:X  a  U R                  nOU R                   S:X  a  SnOSnU R                   S:w  aP  U(       aI  US:w  aC  / nU H9  nU(       a  UR                  S5      (       a  US S U-   nUR                  U5        M;     UnU R                  R                  USR                  U5      X0R                  5        g )Nr  r  r   r   r  r.   )r  r  r   r9   r  r)  r2   r(  )rg   r#  r3   r   r  rawlinesr*   s          r+   rW  patchfile.writelines  s    <<7"((C\\W$CC<<9$HE**#2A"  EUCHHUOT??Kr.   c                &   U R                   (       a  g U(       d  U R                  R                  (       a  SU l         [        S5      U R                  -  nU(       a  U R                  R                  U5        g U R                  R                  U5        g )NTs   patching file %s
)r  r   verboser   r#  rV  note)rg   rV  ss      r+   r  patchfile.printfile  sX    477??#D#$tzz1GGLLOGGLLOr.   c                   ^ U R                   R                  U/ 5      n[        U5      S:  a  UR                  U4S jS9  U$ )Nr   c                    > [        U T-
  5      $ r]   )abs)xlinenums    r+   <lambda>%patchfile.findlines.<locals>.<lambda>  s    CG$4r.   )r   )r  getr'   sort)rg   r*   r  cands     ` r+   	findlinespatchfile.findlines  s8    
 yy}}Q#t9q=II4I5r.   c                   U R                   (       d  g [        R                  R                  U R                  5      nSX4-  /nU R                    HT  nUR
                   HA  nUR                  U5        USS  S:w  d  M  UR                  S[        R                  -   5        MC     MV     U R                  R                  U R                  [        U R                   5      U R                  U5        g )Ns   --- %s
+++ %s
r  r   )r  r   r   basenamer#  hunkr9   r   MISSING_NEWLINE_MARKERr  r0  r'   r  )rg   r  r3   r  r*   s        r+   	write_rejpatchfile.write_rej  s    
 xxww

+$|34AVVQRS6U?LL)J)J!JK  
 	djj#dhh-UKr.   c           
     ^   UR                  5       (       dk  [        [        S5      UR                  UR                  [        UR                  5      UR                  [        UR                  5      UR                  4-  5      eU =R                  S-  sl
        U R                  (       a  U R                  R                  U5        gU R                  (       a  U R                  (       a  U R                   (       a2  U R"                  R%                  [        S5      U R&                  -  5        O1U R"                  R%                  [        S5      U R&                  -  5        U R                  R                  U5        g[)        U[*        5      (       a  U R,                  (       a&  U R.                  R1                  U R&                  5        gUR3                  U R4                  5      nX R4                  S S & U =R6                  [        U5      -  sl        SU l        gUnU R:                  S;   d!  U R:                  S	:X  a!  U R<                  (       a  UR?                  5       nURA                  SS
5      u  pEpgXPR6                  -  nUnU RB                  S:X  a  [D        RF                  " X@R4                  U5      (       a  U R,                  (       a&  U R.                  R1                  U R&                  5        gX`R4                  XU[        U5      -   & U =R6                  [        U5      [        U5      -
  -  sl        SU l        g0 U l$        [K        U R4                  5       H0  u  pU RH                  RM                  U
/ 5      R                  U	5        M2     [O        U R"                  RQ                  SS5      S-   5       GH  nS GH  nURA                  X5      u  pEpgXPR6                  -   U RB                  -   n[S        U[        U R4                  5      5      nU(       a  U RU                  US   SS  U5      nOU/nU GH  nU(       a(  [D        RF                  " X@R4                  U5      (       d  M3  X`R4                  X"[        U5      -   & U =R6                  [        U5      [        U5      -
  -  sl        X(-
  U l!        SU l        X(-
  U-
  nU(       aJ  [        S5      nU RW                  S5        U R"                  R%                  XR                  US-   X4-  5        O8[        S5      nU R"                  RY                  XR                  US-   U4-  5        Us  s  s  $    GM     GM     U RW                  S5        U R"                  R%                  [        S5      UR                  U4-  5        U R                  R                  U5        g)Ns   bad hunk #%d %s (%d %d %d %d)r   r  s-   cannot create %s: destination already exists
s   file %s already exists
Tr   )r  r  r  F   patchs   fuzzrB  s9   Hunk #%d succeeded at %d with fuzz %d (offset %d lines).
s,   Hunk #%d succeeded at %d (offset %d lines).
s   Hunk #%d FAILED at %d
)-completePatchParseErrorr   numberdescr'   alenablenbr  r  r  r9   r3  r  r(  r   rV  r#  
isinstancebinhunkr  r  r   newr3   r  r  r  r  getnormalizedfuzzitr  r   testhunkr  	enumerate
setdefaultrange	configintminr  r  r  )rg   r   r*   horigoldoldstartr  newstart
orig_startr  r  fuzzlentoponlyr  r  r   s                   r+   applypatchfile.apply*  s:   zz||!2388QVVSXqvvs133xHI 
 	

a
<<HHOOA;;4;;GHjj!
 Q:;djjHIHHOOAa!!{{##DJJ/ 	 EE$**% !

1s1v%!
LL,,||w&
 !A ()xx5'9$sKK
 99>j11#zz8LL{{##DJJ/
  >A

8S&9:s3x#c(22!
 	djj)DAII  B'..q1 * TWW..xAAEFG(/0xx/I,s#kk1DII=xTZZ9>>#a&*h?D %:DA*"5"5c::q"I"I7:

13s8|4s3x#c('::$%N	%)
!"'!9""#!8#C
 !NN40 GGLL #xxQ&H H #$!8#C !GGLL!a%/H)HI&/  ) GH 	tQ12ahh
5KKLr.   c                    U R                   (       a1  U R                  U R                  U R                  U R                  5        U R                  5         [        U R                  5      $ r]   )r  rW  r#  r3   r   r  r'   r  rk   s    r+   r   patchfile.close  s=    ::OODJJ

DII>488}r.   )r  r(  r  r  r  r  r3  r  r#  r  r  r3   r  r   r  r  r  r  r   N)r  )rt   ru   rv   rw   rh   rW  r  r  r  r  r   ry   r^   r.   r+   r  r    s*    :xL$		L iVr.   r  c                  ,   \ rS rSrSr\R                  " S5      r\R                  " S5      r\R                  " S5      r	\R                  " S5      r
\R                  " S5      r\R                  " S5      rS	 rS
 rS rS rS rS rS rS rS rS rSrg)r   i  zpatch headers   diff --git a/(.*) b/(.*)$s   diff -r .* (.*)$s   (?:index|deleted file) s   (?:new file|deleted file) s'   (?:index|deleted|copy|rename|new mode) s   (?:new file|copy to|rename to)c                    Xl         / U l        g r]   r   r  )rg   r   s     r+   rh   header.__init__  s    
r.   c                :    [        S U R                   5       5      $ )Nc              3  B   #    U  H  oR                  S 5      v   M     g7f)   index Nr%   r   s     r+   r    header.binary.<locals>.<genexpr>  s     @Kq<<	**Ks   anyr   rk   s    r+   r   header.binary  s    @DKK@@@r.   c                   U R                    GH5  nUR                  S5      (       a  UR                  [        S5      5          g U R                  R                  U5      (       aB  UR                  U5        U R                  5       (       a  UR                  [        S5      5          g UR                  S5      (       av  UR                  [        S5      [        U R                  5      [        U R                   Vs/ s H#  n[        UR                  UR                  5      PM%     sn5      4-  5          g UR                  U5        GM8     g s  snf )Nr  s-   this modifies a binary file (all or nothing)
s   this is a binary file
r   s   %d hunks, %d lines changed
)r   r%   r   r   	pretty_rer  r   r'   r  summaxaddedre  )rg   rI   r   s      r+   prettyheader.pretty  s    A||I&&LMN~~##A&&;;==HHQ9:;||F##56DJJdjjIjS!))4jIJ HHQK%  Js   7*Ec                X    UR                  SR                  U R                  5      5        g r0   )r   r2   r   rf   s     r+   r   header.write  s    
$++&'r.   c                B   ^  [        U 4S jT R                   5       5      $ )Nc              3  Z   >#    U  H   nTR                   R                  U5      v   M"     g 7fr]   )allhunks_rer  r   r   rg   s     r+   r   "header.allhunks.<locals>.<genexpr>  s%     Bk4##))!,,k   (+r	  rk   s   `r+   allhunksheader.allhunks  s    BdkkBBBr.   c                   U R                   R                  U R                  S   5      nU(       a  UR                  5       u  p#X#:X  a  U/$ X#/$ U R                  R                  U R                  S   5      R                  5       $ r  )
diffgit_rer  r   groupsdiff_re)rg   r  fromfiletofiles       r+   r  header.files  sl    %%dkk!n5$||~H! z!%%<<%%dkk!n5<<>>r.   c                (    U R                  5       S   $ )Nr  )r  rk   s    r+   filenameheader.filename  s    zz|Br.   c                    SSR                  [        R                  " [        R                  U R	                  5       5      5      -  $ )Nz<header %s>r   )r2   r   rapplyfsdecoder  rk   s    r+   r   header.__repr__  s2    HHX__X%6%6

EF
 	
r.   c                B   ^  [        U 4S jT R                   5       5      $ )Nc              3  Z   >#    U  H   nTR                   R                  U5      v   M"     g 7fr]   )
newfile_rer  r  s     r+   r   #header.isnewfile.<locals>.<genexpr>  s#     A[4??((++[r  r	  rk   s   `r+   	isnewfileheader.isnewfile  s    AT[[AAAr.   c                   ^  [        T R                  5      S:H  nT R                  5       =(       a    UnU=(       d    [        U 4S jT R                   5       5      $ )Nr$   c              3  Z   >#    U  H   nTR                   R                  U5      v   M"     g 7fr]   )
special_rer  r  s     r+   r   !header.special.<locals>.<genexpr>  s&      #
.9DOO!!!$$kr  )r'   r   r/  r
  )rg   	nocontentemptynewfiles   `  r+   specialheader.special  sN     $)	~~'5I 
s #
.2kk#
  
 	
r.   r  N)rt   ru   rv   rw   r   r   r   r  r   r  r  r3  r-  rh   r   r  r   r  r  r%  r   r/  r7  ry   r^   r.   r+   r   r     s    89Jjj,-G**78K

89IFGJ=>JA*(C? 

B
r.   r   c                  p    \ rS rSrSr SS jrS rS rS rS r	S	 r
\
rS
 r\R                  S 5       rSrg)
recordhunki  zCpatch hunk

XXX shouldn't we merge this with the other hunk class?
Nc	                   ^ SU4S jjn	Xl         U	" US5      u  ol        X*-   U l        X:-   U l        U	" US5      u  ol        X@l        X`l        U R                  U R                  5      u  U l        U l	        g )NFc                `   > Tb'  [        U 5      T-
  nUS:  a  U(       a  X US  4$ X S T 4$ SU 4$ r  )r'   )r3   reversedelta
maxcontexts      r+   trimcontext(recordhunk.__init__.<locals>.trimcontext  sI    %E
Z/19$EFm33$KZ&888e8Or.   T)F)
r   beforefromlinetolineafterprocr  countchangesr  re  )rg   r   rC  rD  rF  rB  r  rE  r?  r@  trimedbefore_trimedafters           `   r+   rh   recordhunk.__init__  sl    	 $/$=!k /+#.ue#< j		#'#4#4TYY#? 
DLr.   c                X   [        U[        5      (       d  gUR                  U R                  :H  =(       au    UR                  U R                  :H  =(       aU    U R                  UR                  :H  =(       a5    U R
                  R                  5       UR
                  R                  5       :H  $ )NF)r  r:  r  rF  rC  r   r  )rg   vs     r+   __eq__recordhunk.__eq__  sz    !Z(( VVtyy  :499$:!**,: ""$(88		
r.   c                    [        [        U R                  5      [        U R                  R	                  5       5      U R
                  U R                  45      $ r]   )r  tupler  r   r  rC  rF  rk   s    r+   __hash__recordhunk.__hash__  sC    dii dkk'')*			
 	
r.   c                    [        U Vs/ s H  o"R                  S5      (       d  M  UPM     sn5      n[        U Vs/ s H  o"R                  S5      (       d  M  UPM     sn5      nX44$ s  snf s  snf )zhunk -> (n+,n-)r"   r!   )r'   r%   )rg   r  r   rr  rems        r+   rG  recordhunk.countchanges%  sU    d9dll4&81d9:d9dll4&81d9:x :9s   A*A*A/A/c           	        SSSS.nU R                    Vs/ s H  nSXSS    USS 4-  PM     nn[        U R                  U R                  U R                  U R
                  U R                  UU R                  5      $ s  snf )	zreturn another recordhunk which is the reverse of the hunk

If this hunk is diff(A, B), the returned hunk is diff(B, A). To do
that, swap fromline/toline and +/- signs while keep other things
unchanged.
r!   r"      \)r"   r!   rW  s   %s%sr   r   N)r  r:  r   rD  rC  rF  rB  rE  )rg   rH   r*   r  s       r+   reversehunkrecordhunk.reversehunk+  s     tE26:ii@i1qV9ae,,i@KKKKMMIIKKJJ
 	
 As   A=c           	     "   [        U R                  5      [        U R                  5      -   nU R                  (       a&  U R                  S   [        R                  :X  a  US-  nX R
                  -   nX R                  -   nUR                  SU R                  UU R                  UU R                  =(       a    SU R                  -   4-  5        UR                  SR                  U R                  U R                  -   U R                  -   5      5        g )Nr  r   s   @@ -%d,%d +%d,%d @@%s
r   r.   )r'   rB  rE  r   r  re  r  r   rC  rD  rF  r2   r  )rg   rI   r>  fromlentolens        r+   r   recordhunk.write>  s    DKK 3tzz?2::$**R.J,M,MMQJE,,&

"
&		0tdii/		
 	$++		1DJJ>?@r.   c                6    U R                   R                  5       $ r]   )r   r%  rk   s    r+   r%  recordhunk.filenameR  s    {{##%%r.   c                @    SU R                  5       U R                  4-  $ )Ns   <hunk %r@%d>)r%  rC  rk   s    r+   r   recordhunk.__repr__U  s    $--/4==!AAAr.   )	r  rE  rB  rC  r   r  rF  re  rD  r]   )rt   ru   rv   rw   r   rh   rM  rQ  rG  rX  r   r  r%  r   	strmethodr   ry   r^   r.   r+   r:  r:    sT     @<	


&A$ F& B Br.   r:  c                    [        S5      [        S5      [        S5      [        S5      S.[        S5      [        S5      [        S5      [        S	5      S.[        S
5      [        S5      [        S5      [        S5      S.S.$ )Ns   apply change %d/%d to '%s'?s   discard change %d/%d to '%s'?s   keep change %d/%d to '%s'?s   record change %d/%d to '%s'?)s   applys   discards   keep   records   apply this change to '%s'?s   discard this change to '%s'?s   keep this change to '%s'?s   record this change to '%s'?s0  [Ynesfdaq?]$$ &Yes, apply this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Apply remaining changes to this &file$$ &Done, skip remaining changes and files$$ Apply &all changes to all remaining files$$ &Quit, applying no changes$$ &? (display help)s8  [Ynesfdaq?]$$ &Yes, discard this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Discard remaining changes to this &file$$ &Done, skip remaining changes and files$$ Discard &all changes to all remaining files$$ &Quit, discarding no changes$$ &? (display help)s-  [Ynesfdaq?]$$ &Yes, keep this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Keep remaining changes to this &file$$ &Done, skip remaining changes and files$$ Keep &all changes to all remaining files$$ &Quit, keeping all changes$$ &? (display help)s4  [Ynesfdaq?]$$ &Yes, record this change$$ &No, skip this change$$ &Edit this change manually$$ &Skip remaining changes to this file$$ Record remaining changes to this &file$$ &Done, skip remaining changes and files$$ Record &all changes to all remaining files$$ &Quit, recording no changes$$ &? (display help))   multiple   single   helpr   r^   r.   r+   getmessagesrh  Z  s     67:;4589	
 569:3478	
 	( 	( 	( 	(K1
? ?r.   c                  ^ ^^^ [        5       mTc  SmUUU 4S jn[        5       n0 nSu  pxS[        S U 5       5      pU GH  nU	[        UR                  5      -  n	SnSnSR                  UR                  5      nX;   a  MB  UR                  U5        Uc  UR                  T 5        UR                  5       n[        S	5      [        S
5      R                  S U 5       5      -  n[        U4S jU 5       5      (       a  Su  nnnOU" XxUS5      u  npxnU(       d  M  U/XkR                  5       '   UR                  5       (       a'  XkR                  5       ==   UR                  -  ss'   GM+  [        UR                  5       GH\  u  nnUc  Uc  UR                  T 5        U
S:X  a  TS   T   UR                  5       -  nO7U	[        UR                  5      -
  U-   nTS   T   UU
UR                  5       4-  nU" XxUU5      u  npxnU(       aV  U(       a+  [        R                  " U5      nU=R                   U-  sl        UUR                  5          R#                  U5        M  Ub]  U HT  nUR                   HA  nU(       a  U=R                   U-  sl        UUR                  5          R#                  U5        MC     MV     GM@  UUR$                  UR&                  -
  -  nGM_     GM     [        UR)                  5        Vs/ s H-  oS   R+                  5       (       d  [        U5      S:  d  M+  UPM/     sn/ 5      0 4$ s  snf )z:Interactively filter patch chunks into applied-only chunksNrd  c           	       > SnUb  XX4$ U b  X X4$  TS   T   nTR                  SX%4-  5      nTR                  S5        US:X  aI  TR                  U5      S    H/  u  pxTR                  SU[        R                  " U5      4-  5        M1     M~  US	:X  a  Sn	GOUS:X  a  S
n	GOUS:X  Gai  Uc-  TR                  [        S5      5        TR                  S5        M  UR                  R                  5       (       a.  TR                  [        S5      5        TR                  S5        GM  S[        S5      -   n
[        R                  " SSS9u  pSn [        R                  " [        R                  " US5      5      nUR                  R                  U5        UR                  U5        UR                  SR                  U
R                  5        Vs/ s H  nSU-   S-   PM     sn5      5        UR!                  5         TR#                  5       nTR%                  SUU4-  STR'                  5       0SS9n	U	S	:w  a8  TR)                  [        S5      U	-  5         [        R*                  " U5        AGM^  [-        US5      n[/        5       nU HB  n[        R0                  " U5      nUR3                  S5      (       a  M1  UR                  U5        MD     UR!                  5         UR5                  S	5        [7        U5      n[        R*                  " U5        AS
n	OMUS:X  a  S
=pOCUS:X  a  S=pO9US:X  a  S
=pO/US :X  a  S=pO%US!:X  a  [8        R:                  " [        S"5      5      eW	XU4$ s  snf ! [        R*                  " U5        Af = f)#zprompt query, and process base inputs

- y/n for the rest of file
- y/n for the rest
- ? (help)
- q (quit)

Return True/False and possibly updated skipfile and skipall.
NTrg  s   %s
(enter ? for help) %sr   r   r   s   %s - %s
r   Fr$   s    cannot edit patch for whole files!   cannot edit patch for binary filer   s  
To remove '-' lines, make them ' ' lines (context).
To remove '+' lines, delete them.
Lines starting with # will be removed from the patch.

If the patch applies cleanly, the edited hunk will immediately be
added to the record list. If it does not apply cleanly, a rejects
file will be generated: you can use that when you try again. If
all lines of the hunk are removed, then the edit is aborted and
the hunk is left unchanged.
s
   hg-editor-s   .diff)r   suffixr   r.   r   s   %s "%s"s   HGUSERs   filterpatch)environ
blockedtags    editor exited with exit code %d
rb   #            r   s	   user quit)promptchoicer   extractchoicesr   r~   r   r   r   r   r   r   nativeeolwriterr   r   r2   r   r   	geteditorsystemusernamerV  r   openr1   fromnativeeolr%   rG   
parsepatchr   CanceledError)skipfileskipallqueryr4   
newpatchesrespsrrQ   tretphelppatchfdpatchfn	ncpatchfpr  ieditorpatchfpr(   messages	operationr   s                      r+   promptfilterpatch.<locals>.prompt  sT    
g99w::W%i0E  <~ MNAHHUOAv--e4Q7DAHH\Qq0A,BBC 8aaa=HHQBCDHHUO<<&&((HHQCDEHHUO 
"  &.%5%5(&" !	!",,RYYw-EFALL&&q)KKNGG8=8H8H8JK8J1UQY.8JK
 GGI\\^F))$'88!*BKKM :#1 $ C
 ax"F G# MN  IIg&! #7D1G (
I '#11$7#t44%OOD1 !( MMONN1%!+I!6JIIg&! a!&&ha!%%ha %%ga $$ga))!L/:::55Q L2 IIg&!s.   A?M+ M&!A4M+ 0AM+ 9AM+ &M+ +NrC  r   c              3  L   #    U  H  n[        UR                  5      v   M     g 7fr]   )r'   r  r   s     r+   r   filterpatch.<locals>.<genexpr>  s     6gAGGgs   "$r   r.   s   examine changes to %s?s    and c              3  ,   #    U  H
  nS U-  v   M     g7f)s   '%s'Nr^   r   r  s     r+   r   r    s      >
!&AGaKs   c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr]   )exact)r   r  r  s     r+   r   r     s     -u!u{{1~~us   !)TNNrf  re  )rh  rd  r  r'   r  r2   r   rr  r  r  r   allr%  r  r  r   rD  r9   re  r  valuesr7  )r   headersr  r  r  seenappliedr~  r  posr/  r   	fixoffsethdrr  r   r  npr  r4   idxr  newpatchnewhunkr  s   ` ``                    @r+   filterpatchr    s   }H	h6T 5DG"HC6g66s177|	hhqxx ;?HHRL	)*Qx[-=-= >
!&>
 .
 
 -u----NAw'-hd'K$Ax"!"

::<<JJL!QWW,!!!''*HAuGOR zy))4u~~7GGCL(1,{+I6NN$: 
 0630,Ax*  IIe,ELLI-L()007' *H#+>>$#NNi7N 0 0 23::7C $2 !+ U]]U[[88	7 +1 j 	(I(1aDLLNNc!fqjQ(I	
 	 Is   >*L<,L<c                  D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)r  iO  c                    X l         Xl        U/U l        / U l        / U l        S =U l        U l        S =U l        U l        Ub+  U(       a  U R                  U5        g U R                  U5        g g r]   )r  r  r  r  r  startar  startbr  read_context_hunkread_unified_hunk)rg   r  numr  contexts        r+   rh   hunk.__init__P  sh    	F	"&&di"&&di>&&r*&&r*	 r.   c                   S n[        U R                  U R                  SS5      nU R                  Ul        U R                  Ul        U R                   Ul         U" U R                  5      Ul        U" U R                  5      Ul        U R
                  Ul        U R                  Ul        U R                  Ul        U R                  Ul        U$ )z1Return a copy with line endings normalized to LF.c                z    / nU  H2  nUR                  S5      (       a  US S S-   nUR                  U5        M4     U$ )Nr   r  r   )r   r9   )r3   r  r(   s      r+   	normalize%hunk.getnormalized.<locals>.normalizea  sC    F==))9u,Dd#  Mr.   N)	r  r  r  r  r  r  r  r  r  )rg   r  nhs      r+   r  hunk.getnormalized^  s    	 $))T[[$5KK	))))  KK	KK	))))	r.   c                X   [         R                  U R                  5      nU(       d!  [        [	        S5      U R
                  -  5      eUR                  5       u  U l        U l        U l	        U l
        U R                  c  SU l        O[        U R                  5      U l        U R                  c  SU l
        O[        U R                  5      U l
        [        U R                  5      U l        [        U R                  5      U l	         [        R                  " XR                  U R                  U R                  U R                  U R                   5        ['        U R                  S   5      S:X  ao  U R                  S	 U R                  S	 U R                   S	 U =R                  S-  sl        U =R                  S-  sl
        ['        U R                  S   5      S:X  a  Mo  U R)                  U5        g ! ["        R$                   a(  n[        [	        S5      U R
                  U4-  5      eS nAff = f)N   bad hunk #%dr   s   bad hunk #%d: %sr  r   )unidescr  r  r  r   r  r  r  r  r  r  r  r   addlinesr  r  r  r   
ParseErrorr'   _fixnewline)rg   r  rH   es       r+   r  hunk.read_unified_hunkv  s   MM$))$!!O"4t{{"BCC9:6TYTY99DIDIIDI99DIDIIDI$++&$++&	MIItyy$))TVVTVV $))B- A%		"r
r
IINIIINI $))B- A% 	  	M!!$7"8DKK;K"KLL	Ms   AG- -H)#H$$H)c                   UR                  5       U l        [        R                  U R                  5      nU(       d!  [	        [        S5      U R                  -  5      eUR                  5       u  U l        n[        U R                  5      U l        Uc  U R                  n[        U5      U R                  -
  U l
        U R                  (       a  U =R                  S-  sl
        [        U R                  5       H  nUR                  5       nUR                  S5      (       a  UR                  U5          OUSS  nUR                  S5      (       d  UR                  S5      (       a  SU-   nO?UR                  S5      (       a  S	U-   nO#[	        [        S
5      U R                  U4-  5      eU R                  R                  U5        U R                   R                  U5        M     UR                  5       nUR                  S5      (       a>  U R                  S   S S nX`R                  S'   X`R                   S'   UR                  5       n[        R                  U5      nU(       d!  [	        [        S5      U R                  -  5      eUR                  5       u  U l        n[        U R"                  5      U l        Uc  U R"                  n[        U5      U R"                  -
  U l        U R"                  (       a  U =R$                  S-  sl        Sn	[        U R$                  5       GH  nUR                  5       nUR                  S5      (       a3  U R&                  S   S S nX`R&                  S'   X`R                   U	S-
  '   M]  U(       d  UR                  U5          GO2USS  nUR                  S5      (       d  UR                  S5      (       a  SU-   nOkUR                  S5      (       a  S	U-   nOO[)        U R&                  5      S:X  a  UR                  U5          O[	        [        S
5      U R                  U4-  5      eU R&                  R                  U5         U	[)        U R                   5      :  a  Sn
OU R                   U	   n
U	S-  n	X:X  a  GMn  U
R                  S5      (       a  MQ  U R                   R+                  U	S-
  U5        GM     U R                  (       d\  U R                    HL  nUR                  S5      (       d  UR                  S	5      (       d  M1  U R                  R                  U5        MN     U R&                  (       d_  U R                    HO  nUR                  S5      (       d  UR                  S	5      (       d  M1  U R&                  R                  USS  5        MQ     SU R                  U R                  U R"                  U R$                  4-  U l        U R                  U R                   S'   U R-                  U5        g )Nr  r   r   r$   s   - s   ! r!   s     r   s   bad hunk #%d old text line %d   \ r  s   + r"   r   r.   s   @@ -%d,%d +%d,%d @@
)ro   r  contextdescr  r  r   r  r  r  r  r  r  r%   r  r  r9   r  r  r  r  r'   insertr  )rg   r  rH   aendr  r*   r  ubendhunkir   s              r+   r  hunk.read_context_hunk  s   KKM	dii(!!O"4t{{"BCCHHJT$++&<;;DI+	;;IINItyy!AA||F##
!"A||E""all5&9&91He$$1H%674;;:JJ  FFMM!IIQ! "$ KKM<<r
3BAFF2JIIbMAa !!O"4t{{"BCCHHJT$++&<;;DI+	;;IINItyy!AA||F## FF2JsOr
'(		%!)$
!"A||E""all5&9&91He$$1HTVV!
%674;;:JJ  FFMM!C		N*A		%(A
6\\$''II$$UQY2Q "T vvYY<<%%d););FFMM!$  vvYY<<%%d););FFMM!AB%(  -KKIIKKII	0
 
	 yy		!r.   c                    UR                  5       nUR                  S5      (       a7  [        R                  " U R                  U R
                  U R                  5        g UR                  U5        g )Nr  )ro   r%   r   
fixnewliner  r  r  r  )rg   r  r*   s      r+   r  hunk._fixnewline  sE    KKM<<!!$))TVVTVV<GGAJr.   c                    [        U R                  5      U R                  :H  =(       a"    [        U R                  5      U R                  :H  $ r]   )r'   r  r  r  r  rk   s    r+   r  hunk.complete	  s/    466{dii'DCK499,DDr.   c                   [        U[        U5      5      nU(       a  SnSn[        U R                  5      n[        US-
  5       H0  nU R                  US-      R	                  S5      (       a  US-  nM0    O   U(       dD  [        US-
  5       H2  nU R                  Xv-
  S-
     R	                  S5      (       a  US-  nM2    O   [        X65      n[        X55      nX[        U5      U-
   X%[        U5      U-
   U4$ XS4$ )Nr   r   r   )r  r'   r  r  r%   )	rg   r  r  fuzzr  topbothlenr  s	            r+   _fuzzithunk._fuzzit  s     4S"CCtyy>D4!8_99QU#..t441HC % taxAyya0;;DAAq	 ) d.Cd.CSX^,cC3.GLL{r.   c                
   U R                  U R                  U R                  X5      u  p4nU R                  U-   nU R                  U-   nU R
                  (       a  US:  a  US-  nU R                  (       a  US:  a  US-  nX6XG4$ )Nr   r   )r  r  r  r  r  r  r  )rg   r  r  r  r  r  r  r  s           r+   r  hunk.fuzzit'  ss    TVVTVVTC#;;$;;$99AMH99AMHc++r.   )	r  r  r  r  r  r  r  r  r  N)rt   ru   rv   rw   rh   r  r  r  r  r  r  r  ry   r^   r.   r+   r  r  O  s-    +0>kZE6	,r.   r  c                  0    \ rS rSrSrS rS rS rS rSr	g)	r  i3  zA binary patch file.c                ^    S U l         SU l        S/U l        X l        U R	                  U5        g )NFs   GIT binary patch
)textr>  r  _fname_read)rg   r  r#  s      r+   rh   binhunk.__init__6  s*    	
*+	

2r.   c                    U R                   S L$ r]   )r  rk   s    r+   r  binhunk.complete=  s    yy$$r.   c                    U R                   (       a&  [        U R                  SR                  U5      5      /$ U R                  /$ r0   )r>  applybindeltar  r2   )rg   r3   s     r+   r  binhunk.new@  s1    ::!$))SXXe_=>>		{r.   c                .   S n U" XR                   5      nU(       d!  [        [        S5      U R                  -  5      eUR	                  S5      (       a  [        USS  R                  5       5      nO<UR	                  S5      (       a$  [        USS  R                  5       5      nSU l        OM  / nU" XR                   5      n[        U5      S:  a  US	S nUS
::  a!  US:  a  [        U5      [        S5      -
  S-   nO[        U5      [        S5      -
  S-   n UR                  [        R                  " USS  5      S U 5        U" XR                   5      n[        U5      S:  a  M  [         R"                  " SR%                  U5      5      n[        U5      U:w  a-  [        [        S5      U R                  [        U5      U4-  5      eXl        g ! [         a<  n[        [        S5      U R                  [        R                  " U5      4-  5      eS nAff = f)Nc                f    U R                  5       nUR                  U5        UR                  S5      $ )Nr   )ro   r9   r  )r  r  r*   s      r+   getlinebinhunk._read.<locals>.getlineF  s'    AKKN88G$$r.   Ts"   could not extract "%s" binary datas   literal r   s   delta rs  r   r      Z   A   a   s&   could not decode "%s" binary patch: %sr.   s%   "%s" length is %d bytes, should be %d)r  r  r   r  r%   r  r  r>  r'   ordr9   r   	b85decode
ValueErrorr   forcebytestrzlib
decompressr2   r  )	rg   r  r  r(   r  decr*   r  r  s	            r+   r  binhunk._readE  s   	%
 2yy)D%;<t{{J  {++48??,-y))48??,-!
  r99%$i!mQq	ADyQ$YFSY&*FSY&+

4>>$qr(3BQ78 2yy)D $i!m sxx}-t9!:;;;D	401  	  %?@{{J$;$;A$>?@ s   +G 
H7HH)r  r>  r  r  N)
rt   ru   rv   rw   r   rh   r  r  r  ry   r^   r.   r+   r  r  3  s    %
)r.   r  c                    U SS  R                  S5      nUR                  S5      nUS:  a  UR                  S5      nUS:  a  U$ US U $ )Nrq  r   r    r   r   )r  r   )strr  r  s      r+   parsefilenamer  q  sN    ABwA	uA1uFF4Lq5HRa5Lr.   c                    / nU  H5  n[        US5      (       a  UR                  5       nUR                  U5        M7     U$ )a  reverse the signs in the hunks given as argument

This function operates on hunks coming out of patch.filterpatch, that is
a list of the form: [header1, hunk1, hunk2, header2...]. Example usage:

>>> rawpatch = b"""diff --git a/folder1/g b/folder1/g
... --- a/folder1/g
... +++ b/folder1/g
... @@ -1,7 +1,7 @@
... +firstline
...  c
...  1
...  2
... + 3
... -4
...  5
...  d
... +lastline"""
>>> hunks = parsepatch([rawpatch])
>>> hunkscomingfromfilterpatch = []
>>> for h in hunks:
...     hunkscomingfromfilterpatch.append(h)
...     hunkscomingfromfilterpatch.extend(h.hunks)

>>> reversedhunks = reversehunks(hunkscomingfromfilterpatch)
>>> from . import util
>>> fp = util.stringio()
>>> for c in reversedhunks:
...      c.write(fp)
>>> fp.seek(0) or None
>>> reversedpatch = fp.read()
>>> print(pycompat.sysstr(reversedpatch))
diff --git a/folder1/g b/folder1/g
--- a/folder1/g
+++ b/folder1/g
@@ -1,4 +1,3 @@
-firstline
 c
 1
 2
@@ -2,6 +1,6 @@
 c
 1
 2
- 3
+4
 5
 d
@@ -6,3 +5,2 @@
 5
 d
-lastline

rX  )r}   rX  r9   )r  newhunksrQ   s      r+   reversehunksr  |  s?    p H1m$$A  Or.   c                `  ^  " U4S jS5      nU" 5       n[        5       nUR                  SR                  U 5      5        UR                  S5        Sn[	        U5       H   u  pg UR
                  U   U   " X75        UnM"     AUR                  5       $ ! [         a    [        SXV4-  5      ef = f)a  patch -> [] of headers -> [] of hunks

If maxcontext is not None, trim context lines if necessary.

>>> rawpatch = b'''diff --git a/folder1/g b/folder1/g
... --- a/folder1/g
... +++ b/folder1/g
... @@ -1,8 +1,10 @@
...  1
...  2
... -3
...  4
...  5
...  6
... +6.1
... +6.2
...  7
...  8
... +9'''
>>> out = util.stringio()
>>> headers = parsepatch([rawpatch], maxcontext=1)
>>> for header in headers:
...     header.write(out)
...     for hunk in header.hunks:
...         hunk.write(out)
>>> print(pycompat.sysstr(out.getvalue()))
diff --git a/folder1/g b/folder1/g
--- a/folder1/g
+++ b/folder1/g
@@ -2,3 +2,2 @@
 2
-3
 4
@@ -6,2 +5,4 @@
 6
+6.1
+6.2
 7
@@ -8,1 +9,2 @@
 8
+9
c                     > \ rS rSrSrS rS rU 4S jrS rS r	S r
S	 r\\	\\S
.\	\\\
S.\\	\S.\\S.S\
0S.rSrg)parsepatch.<locals>.parseri  zpatch parsing state machinec                t    SU l         SU l        SU l        S U l        / U l        / U l        / U l        / U l        g )Nr   r.   )rC  rD  rF  r   r  rB  r  r  rk   s    r+   rh   #parsepatch.<locals>.parser.__init__  s:    DMDKDIDKDLDKDIDLr.   c                ~    U R                  / 5        Uu  p#pEn[        U5      U l        [        U5      U l        X`l        g r]   )
addcontextr  rC  rD  rF  )rg   limits	fromstartfromendtostarttoendrF  s          r+   addrange#parsepatch.<locals>.parser.addrange  s5    OOB7=4I	NDMg,DKIr.   c           
     
  > U R                   (       a  [        U R                  U R                  U R                  U R
                  U R                  U R                   UT5      nU R                  R                  R                  U5        U =R                  [        U R                  5      UR                  -   -  sl        U =R                  [        U R                  5      UR                  -   -  sl        / U l        / U l         Xl        g r]   )r  r:  r   rC  rD  rF  rB  r  r9   r'   re  r  r  )rg   r  r   r?  s      r+   r  %parsepatch.<locals>.parser.addcontext  s    yyKKMMKKIIKKII	 !!((+T[[!1AII!==s4;;/!''99 	"Lr.   c                    U R                   (       a  U R                   U l        / U l         U R                  (       a  U R                  / 5        Xl        g r]   )r  rB  r  r  )rg   r  s     r+   addhunk"parsepatch.<locals>.parser.addhunk  s3    ||"ll!yy#Ir.   c                ~    U R                  / 5        [        U5      nU R                  R                  U5        X l        g r]   )r  r   r  r9   )rg   r  r   s      r+   newfile"parsepatch.<locals>.parser.newfile  s.    OOBsALL"Kr.   c                    g r]   r^   r  s     r+   addother#parsepatch.<locals>.parser.addother  s    r.   c                <    U R                  / 5        U R                  $ r]   )r  r  rk   s    r+   finished#parsepatch.<locals>.parser.finished   s    OOB<<r.   )   context   file   hunk   range)r  r  r     other)r  r  r  )r  r  r  )r  r  r  r  r  )rB  r  rC  r   r  r  rF  rD  N)rt   ru   rv   rw   r   rh   r  r  r  r  r
  r  transitionsry   )r?  s   r+   parserr    sx    )			#&				  '  "	 ! ""	 ' "
 $.@*'
r.   r  r.   r   r  s   unhandled transition: %s -> %s)	r1   r   r2   rG   	scanpatchr  KeyErrorr  r  )originalchunksr?  r  prI   statenewstater   s    `      r+   r|  r|    s    XP
 P
d 	A	BHHSXXn%&GGAJE#B-	MM% *13
  ( 	::<  	!1U4EE 	s   $BB-c                   [        U 5      nSnUS:X  a  SX R                  5       -   4$ UnUS:  ap  U R                  SU5      nUS:X  a  [        [	        S5      XQU 4-  5      eUS-  nXCS-
  :  a%  XUS-    S:X  a  US-  nXCS-
  :  a  XUS-    S:X  a  M  US-  nUS:  a  Mp  U SU R                  5       X US R                  5       -   4$ )aj  turn a path from a patch into a path suitable for the repository

prefix, if not empty, is expected to be normalized with a / at the end.

Returns (stripped components, path in repository).

>>> pathtransform(b'a/b/c', 0, b'')
('', 'a/b/c')
>>> pathtransform(b'   a/b/c   ', 0, b'')
('', '   a/b/c')
>>> pathtransform(b'   a/b/c   ', 2, b'')
('a/b/', 'c')
>>> pathtransform(b'a/b/c', 0, b'd/e/')
('', 'd/e/a/b/c')
>>> pathtransform(b'   a//b/c   ', 2, b'd/e/')
('a//b/', 'd/e/c')
>>> pathtransform(b'a/b/c', 3, b'')
Traceback (most recent call last):
PatchApplicationError: unable to strip away 1 of 3 dirs from a/b/c
r   r.      /r  s*   unable to strip away %d of %d dirs from %sr   N)r'   r  r   rn  r   r   )r   r8   r   pathlenr  counts         r+   pathtransformr   L  s    * $iG	AzF[[]***E
!)IIdA7'?@&'  	
QA+o$1q5/T"9FA A+o$1q5/T"9
 !) 8??fABx'8888r.   c                   US:H  nUS:H  nU=(       a%    UR                   S:H  =(       a    UR                  S:H  nU=(       a%    UR                  S:H  =(       a    UR                  S:H  n	[	        XU5      u  pU(       + =(       a    U R                  U5      n[	        X$U5      u  pX:X  a  UnOU(       + =(       a    U R                  U5      nU(       + =(       a    U(       + =(       a    U(       + nUS UR                  S5      S-    nUS UR                  S5      S-    nU(       a@  UU:X  a:  UR                  U5      (       a$  UR                   S:X  a  UR                  S:X  a  SnSnX:H  =(       a    UR                  U5      nS nU(       d$  U(       a  U(       a  U(       a  UnOUnO	U(       a  UnU(       d2  U(       d  U(       a  UnO!UnOU(       d  UnO[        [        S5      5      e[        U5      nU(       a	  SUl        U$ U	(       a  S	Ul        U$ )
Nr   r   r  r   TFs&   undefined source and destination filesr   r   )r  r  r  r  r   r3  rfindr%   r  r   r   r   )r  
afile_orig
bfile_origr  r8   r   nullanullbr  r  abaser   goodabbaser   goodbr  abasedirbbasedirisbackupr#  r  s                         r+   makepatchmetar.  u  s   ,&E,&E:t{{a':DIINF:t{{a':DIINF F;LEI/'../E F;LE~	3gnnU3i4I4f*G ,u{{4(1,-H,u{{4(1,-H U##KK1IIN
 ~9%"2"25"9HEUEE!!$M"NOO	5	B I 
Ir.   c              #    ^	^
#    [         R                  " S5      n[        U 5      m
U
4S jn[        T
R                  S5       GH  nUR                  S5      (       d  UR                  S5      (       aa  S nU" X45      nT
R	                  5       nUR                  S5      (       a  T
R	                  5       nXVU/-  nOT
R                  U5        SU4v   M  UR                  S	5      (       a  S
m	SU" UU	4S j5      4v   M  UR                  S5      (       a  Sm	SU" UU	4S j5      4v   M  UR                  U5      nU(       a  SUR                  5       4v   GM  SU4v   GM     g7f)zlike patch.iterhunks, but yield different events

- ('file',    [header_lines + fromfile + tofile])
- ('context', [context_lines])
- ('hunk',    [hunk_lines])
- ('range',   (-start,len, +start,len, proc))
s'   @@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)c                   > U /n[        TR                  S5       H5  nU" U5      (       a  UR                  U5        M#  TR                  U5          U$    U$ )zscan lr while predicate holdsr.   )r  ro   r9   r  )firstr  r3   r(   r  s       r+   	scanwhilescanpatch.<locals>.scanwhile  sN    c*DwwT" + r.   r.   r   s   diff -r c                R    U R                  S S5      nU(       + =(       d    US   S;  $ )Nr   r   )r      diff)r&   )r(   r  s     r+   	notheaderscanpatch.<locals>.notheader  s)    JJtQ'u=!,= ==r.   r   r  r   )r   rW  r  c                &   > U R                  T5      $ r]   r  r*   css    r+   r  scanpatch.<locals>.<lambda>  s    R8Hr.   )r!   r"   )r!   r"   rW  r  c                &   > U R                  T5      $ r]   r  r9  s    r+   r  r;    s    Q\\"5Er.   r  r  N)	r   r   r  r  ro   r%   r  r  r  )rI   lines_rer2  r(   r6  r   r!  r"  rH   r:  r  s            @@r+   r  r    s/     zzEFH	BB	 R[[#&??+,,0L0L> t/F{{}H""6**V,,!6/!__T""Bi.HIII__\**$B9T+EFFFt$A
**n$5 's   E E$c                .   Sn U R                   R                  5       nU R                   n[        U5      nUR                  U5        [        U5      nUR                  U5        U$ ! [         a&    [        U R                   R	                  5       5      n Nif = f)ao  
Git patches can emit:
- rename a to b
- change b
- copy a to c
- change c

We cannot apply this sequence as-is, the renamed 'a' could not be
found for it would have been renamed already. And we cannot copy
from 'b' instead because 'b' would have been changed already. So
we scan the git patch for copy and rename commands so we can
perform the copies ahead of time.
r   )	rI   tellOSErrorr1   rH  r  r  r
  rG   )r  	firstliner  rI   gitlrr  s         r+   scangitpatchrC    s}     C$eejjlUU rNE	JJye$JGGCL  $beejjl#$s   &A$ $-BBc              #    #    SnSnSnSnS=pVSnSnSn	[        U 5      n
[        U
R                  S5       GH  nX8:X  Ga  U	(       d  UR                  S5      (       d1  U	SLa  UR                  S5      (       d  UR                  S5      (       a  SnU(       a)  US	   R	                  X5      (       a  UR                  5       nUR                  S5      (       a  [        XR                  5      nO*U	c  UR                  S5      (       a  S
n	[        XS-   X5      nUS-  nU(       a*  SnSXX=(       a    UR                  5       =(       d    S44v   SU4v   GOUR                  S5      (       GaS  [        R                  UR                  S5      5      nU(       d  GMc  UcQ  [        X5      nSU Vs/ s H$  oR                  S;   d  M  UR                  5       PM&     sn4v   UR                  5         SUR!                  S5      -   nSUR!                  S5      -   nU(       a}  US	   R	                  X5      (       dd  UR                  5       nSSUR                  -   SUR                  -   SUR                  5       44v   U(       a  US	   R	                  X5      (       d  Md  U(       d  [#        [%        S5      USS -  5      eS
nGO UR                  S5      (       aU  U
R                  5       nUR                  S5      (       d  U
R'                  U5        GM  S
nSn	[)        U5      n[)        U5      nOUR                  S5      (       a  U
R                  5       nUR                  S5      (       d  U
R'                  U5        GMC  U
R                  5       nU
R'                  U5        UR                  S5      (       d  U
R'                  U5        GM  S
nS
n	[)        U5      n[)        U5      nU(       d  GM  SnS
nUnSnGM     U(       aL  UR                  5       nSSUR                  -   SUR                  -   SUR                  5       44v   U(       a  MK  ggs  snf 7f)a,  Read a patch and yield the following events:
- ("file", afile, bfile, firsthunk): select a new target file.
- ("hunk", hunk): a new hunk is ready to be applied, follows a
"file" event.
- ("git", gitchanges): current diff is in git format, gitchanges
maps filenames to gitpatch records. Unique event.
r.   Nr   Fr      @s   ***************r   r  Tr  r  r   r      git)r   r   r   r   r$   s'   failed to synchronize metadata for "%s"r      +++s   ***)r  r  ro   r%   r   r   r  r   r  r   r  r  r  rC  r   r=  r  r  r   r  r  )rI   r   r   r  hunknumemitfiler  r  BFILEr  r  r  r  r   rH   rJ   l2l3s                     r+   	iterhunksrM     s     EEEGHJ EG	BB"++s#>Q\\$//u$6H)I)I||/00Bjn77EE^^%||/00B(?q||4F'G'G"GaK5qLG a1A	1ITJJJ1*\\*++AHHW-.A!)"0
&0&0DD<P4PHAFFHj   ""$AGGAJ&EAGGAJ&EZ^%>%>u%L%L^^%BGGOBGGOGGI	    Z^%>%>u%L%L %@AE!"IM  G\\&!!B==((GG!!$E!"%E\\&!!B==((BGGBK==!344GG!!$E!"%E7GHEGY $\ ^^$	JJJ *gs-   F)Q+QQC QE
Q'AQQc                6   S nSnU" U 5      nXS n U" U 5      nXS n SnU[        U 5      :  Gai  [        XUS-    5      nUS-  nUS-  (       Ga  SnSnUS-  (       a  [        XUS-    5      nUS-  nUS-  (       a  U[        XUS-    5      S-  -  nUS-  nUS	-  (       a  U[        XUS-    5      S
-  -  nUS-  nUS-  (       a  U[        XUS-    5      S-  -  nUS-  nUS
-  (       a  [        XUS-    5      nUS-  nUS-  (       a  U[        XUS-    5      S-  -  nUS-  nUS-  (       a  U[        XUS-    5      S
-  -  nUS-  nUS:X  a  SnXx-   n	X1Xy -  nO)US:w  a  XV-   n	X0XY -  nXV-  nO[        [        S5      5      eU[        U 5      :  a  GMi  U$ )zWApply a binary delta hunk
The algorithm used is the algorithm from git's patch-delta.c
c                |    Sn[         R                  " U 5       H  nUS-  n[        U5      S-  (       a  M  Us  $    U$ )Nr   r      )r   r   r  )binchunkr  rQ   s      r+   	deltahead applybindelta.<locals>.deltaheadl  s>    !!(+AFAFTMM , r.   r.   Nr   r   rP  r$   r   rq            r   i   s   unexpected delta opcode 0)r'   r  rn  r   )
rQ  r   rR  outr  r  cmdr  r  
offset_ends
             r+   r  r  g  s   
 C(A|H(A|H	A
c(m
(q1u%&	Q::FDTzX!a%01QTz#h1q512a77QTz#h1q512b88QTz#h1q512b88QTz8A./QTzHQ/0A55QTzHQ/0B66QqyJ**CAXJA))CHA'*F(GHHI c(m
J Jr.   c                *    [        U U[        UUUUUS9$ )a6  Reads a patch from fp and tries to apply it.

Returns 0 for a clean patch, -1 if any rejects were found and 1 if
there was any fuzz.

If 'eolmode' is 'strict', the patch content and patched file are
read in binary mode. Otherwise, line endings are ignored when
patching then normalized according to 'eolmode'.
r8   r   r  )
_applydiffr  )r   rI   r  r  r8   r   r  s          r+   	applydiffr]    s)     

	 	r.   c                    U(       a;  [         R                  " U R                  U R                  5       U5      nUS:w  a  US-  nU$ )Nr.   r  )r   	canonpathra  getcwd)rb  r   s     r+   _canonprefixra    s8    ##DIIt{{}fES=dNFMr.   c           	       ^^ [        UR                  T5      mUU4S jnSn	Sn
S n[        U5       GH  u  pUS:X  a&  U(       d  M  UR                  U5      nUS:  a  Sn
M0  M2  US:X  Ga  U(       a  XR	                  5       -  n	S nUu  nnnnU(       a@  U" UR
                  5      Ul        UR                  (       a  U" UR                  5      Ul        O[        X?UUTT5      nUR                  S:X  a  UR                  UR                  5        U(       GdA  UR                  S:X  a  UR                  UR
                  5        GM  Su  nnUR                  S	;   aE  UR                  UR                  5      S S
 u  nnUc!  [        [        S5      UR                  -  5      eUR                  (       a  UR                  nUR                  S:X  a  SnU(       d  U(       ay  UR                  S;   aA  UR                  UR
                  5      (       a!  [        [        S5      UR
                  -  5      eUR                  UR
                  UUUR                  5        GM%   U" U UX4US9nGM2  US:X  aJ  U HA  nU" UR                  5      nUR                  U5      u  nnUc  M.  UR                  UUU5        MC     GM  [(        R*                  " [        S5      U-  5      e   U(       a  XR	                  5       -  n	U	(       a  gU
$ ! [          a;  nU R#                  [$        R&                  " U5      S-   5        S nU	S-  n	 S nAGM	  S nAff = f)Nc                *   > [        U TS-
  T5      S   $ )Nr   )r   )r  r   r8   s    r+   pstrip_applydiff.<locals>.pstrip  s    Q	62155r.   r   r  r   r  r   r   rC  )r   r   r$   s   source file '%s' does not existr   r.   )r   r   r   s,   cannot create %s: destination already exists)r  r   rF     unsupported parser state: %sr  )ra  rb  rM  r  r   r   r   r.  r   r   r$  rn  r   r   r3  r)  
PatchErrorrV  r   r  r   Abort)r   rI   patcherr  r  r8   r   r  rd  rejectserrcurrent_filer  r  r  r   r   
first_hunkr  r   r   instr   s        ``                r+   r\  r\    s    ',,/F6 G
CL"2G$$V,CQw g--//#+1(E5*b /::!'

!3BJ"E:uf uu	!rzz*55I%NN277+'
d5500!&rzz!:2A!>JD$|3@ABJJN  7777Duu  #4uu <<B B 4!2 !gg	&  OOBGGT4D&r2wwO f_bjj)$__T2
d<
 MM$d3  ++a ?@5HIIS 'V %%''J3  
//5=>#1	s   	K::
L?/L::L?c                   Sn/ nUR                   n	U	(       a(  UR                  S[        R                  " U	5      -  5        SUSR	                  U5      U[        R                  " U5      4-  n
U R                  SU
-  5        [        R                  " U
S5      n U GH&  nUR                  5       nU R                  US-   5        UR                  S5      (       a+  [        R                  " U5      nSnUR                  U5        Mi  UR                  S	5      S
:  a5  SnW(       d  U R                  WS-   5        SnU R                  US-   5        M  UR                  S5      S
:  a  U R                  US-   5        M  UR                  S5      S
:  d  M  W(       d  U R                  WS-   5        SnU R                  US-   5        GM)     U(       a  [        R                   " XU5        UR#                  5       nU(       a+  [%        ['        S5      [        R(                  " U5      -  5      eU$ ! U(       a  [        R                   " XU5        f f = f)zpuse <patcher> to apply <patchname> to the working directory.
returns whether patch was applied with fuzz factor.Fs   -d %ss   %s %s -p%d < %sr   s   Using external patch tool: %s
s   rbr   s   patching file s	   with fuzzr   Ts   saving rejects to files   FAILEDs   patch command failed: %s)ra  r9   r   
shellquoter2   r   popenr  r  r%   r   parsepatchoutputrr  r   rV  r   r|  r   rn  r   explainexit)r   rb  ri  	patchnamer8   r  rc  r  argscwdrX  rI   r(   pfprinted_filecodes                   r+   _externalpatchrz  	  s    DD
))C
Hx223778
		$I&	  C HH/#56	U	#B9D;;=DGGD5L!011**40$		"<(A-#GGBJ'#'Lu%45:u%9%*#GGBJ'#'Lu%' * Z888:D#)*X-A-A$-GG
 	
 K Z8 s   C3H' 6H' '!Ic           
        Uc
  [        5       nUc  U R                  SS5      nUR                  5       [        ;  a"  [        R
                  " [        S5      U-  5      eUR                  5       n[        5       n [        US5      n [        XXX4US9n	X:w  a  UR                  5         UR                  UR                  5       5        UR                  5         U	S:  a  [        [        S5      5      eU	S:  $ ! [         a    Un N~f = f! X:w  a  UR                  5         UR                  UR                  5       5        UR                  5         f = f)Nr  s   eols!   unsupported line endings type: %srn  r[  r   s   patch failed to apply)rd  configr~   eolmodesr   rh  r   r  rz  	TypeErrorr]  r   updatern  )
r   r  patchobjr8   r   r  r  r  rI   r  s
             r+   patchbackendr  P	  s    }))Hf-}}h&kk!@AGKLLmmoGKE(D!G%
 >HHJW]]_%
Qw#A&>$?@@7N   >HHJW]]_%s   8C4 D 4DDAEc           	     6    [        XU5      n[        XX#XEU5      $ )zsuse builtin patch to apply <patchobj> to the working directory.
returns whether patch was applied with fuzz factor.)r_  r  )	r   rb  r  r8   r   r  r  rc  r  s	            r+   internalpatchr  n	  s!     Rz2GXfWMMr.   c	           	     6    [        XX#5      n	[        X	XEXgU5      $ r]   )r  r  )
r   rb  r  r  r  r8   r   r  r  r  s
             r+   	patchrepor  ~	  s!     "C/GXfWMMr.   c           
         U R                  SS5      nUc
  [        5       nU(       a  [        XXX5U5      $ [        XX#XEXg5      $ )a  Apply <patchname> 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.
s   uir  )r|  rd  rz  r  )	r   rb  rt  r8   r   r  r  rc  ri  s	            r+   patchr  	  sQ    * iix(G}g%

 	
 
)F7 r.   c           
        [        XR                  5      n[        X5      n[        US5       n[	        5       n[        U5       H  u  pUS:X  a  U	u  ppU(       aV  [        UR                  US-
  U5      S   Ul        UR                  (       a"  [        UR                  US-
  U5      S   Ul        O[        XZXX45      nUR                  UR                  5        UR                  S:X  a  UR                  UR                  5        M  M  US;  d  M  [        R                  " [        S5      U-  5      e   UsS S S 5        $ ! , (       d  f       g = f)Nrn  r  r   r   )r  rF  rf  )r9  ra  ra  rz  rd  rM  r   r   r   r.  rr  r   r   rh  r   )r   rb  	patchpathr8   r   r  rI   rf  r  r  r   r   rm  r  s                 r+   changedfilesr  	  s   II&G$'F	i	"%&r]ME/5,j+BGGUQYGJBGzz%2JJ	6&&
 '5B BGG$55I%KK

+ &//kk!$C"Du"LMM# +$ ) 
		s   CD>%D>>
Ec                      \ rS rSrSrg)GitDiffRequiredi	  r^   N)rt   ru   rv   rw   ry   r^   r.   r+   r  r  	  s    r.   r  c              #    #    U(       d!  U(       d  U R                   R                  5       nX   nX   n[        U UUUUUUUUU	S9
 Hu  u  pnnU
b  Uc   S5       eU
" UU5      nSR                  S U 5       5      nU(       a,  U(       d  [	        U5      S:  a  SR                  U5      S-   v   U(       d  Mq  Uv   Mw     g7f)a=  yields diff of changes to files between two nodes, or node and
working directory.

if node1 is None, use first dirstate parent instead.
if node2 is None, compare node1 with working directory.

losedatafn(**kwarg) is a callable run when opts.upgrade=True and
every time some change cannot be represented with the current
patch format. Return False to upgrade to git patch format, True to
accept the loss or raise an exception to abort the diff. It is
called with the name of current file being diffed as 'fn'. If set
to None, patches will always be upgraded to git format when
necessary.

prefix is a filename prefix that is prepended to all filenames on
display (used for subrepos).

relroot, if not empty, must be normalized with a trailing /. Any match
patterns that fall outside it will be ignored.

copy, if not empty, should contain mappings {dst@y: src@x} of copy
information.

if copysourcematch is not None, then copy sources will be filtered by this
matcher

hunksfilterfn, if not None, should be a function taking a filectx and
hunks generator that may yield filtered hunks.
)	ctx1ctx2r  changesopts
losedatafnpathfnr   copysourcematchNs-   fctx2 unexpectly None in diff hunks filteringr.   c              3  H   #    U  H  u  pS R                  U5      v   M     g7f)r.   Nr2   )r   hrangehliness      r+   r   diff.<locals>.<genexpr>
  s     Eu^V((us    "r   r   )rk  p1	diffhunksr2   r'   )rb  node1node2r  r  r  r  r  r   r  hunksfilterfnr  r  fctx1fctx2r  r  r  s                     r+   diffr  	  s     T   ";D;D$-'% c5 $
 !@?@!!%/ExxEuEEDCHqL**S/E))4J1%s   B0B?6	B?c
           
     d  ^ ^^^^^^^^^^ Uc  [         R                  nS n
U
" 5       mU(       d  TR                  TUS9n[        U[        5      (       a
  USS u  mmmO%UR
                  UR                  UR                  smmmT(       d  T(       d	  T(       d  / $ T R                  R                  (       a  [        nO[        nTR                  5       TR                  5       4 Vs/ s H  o(       d  M  U" U5      PM     snmTc:  0 mUR                  (       d  UR                  (       a  [        R                   " TTUS9mU	(       a5  TR"                  " 5        VVs0 s H  u  pU	" U5      (       d  M  X_M     snnm[%        T5      n[%        T5      n[%        T5      nT H-  nUT;  d  M  UR'                  U5        UR)                  U5        M/     T H  nUT;  d  M  UR'                  U5        M     [+        U5      m[+        U5      m[+        U5      m[	        TR"                  " 5       5       H  u  pUT;  d  M  TU	 M     [,        R.                  " T [	        UU-  U-  5      5      nTR1                  5       U4TR1                  5       U4/n[,        R2                  " T U5        UUUUUUUUU U4
S jnUR                  (       a7  UR                  (       d&   U4S jn[	        U" UR5                  SS9U5      5      $ U" US5      $ s  snf s  snnf ! [6         a    U" UR5                  S	S9S5      s $ f = f)
zYield diff of changes to files in the form of (`header`, `hunks`) tuples
where `header` is a list of diff headers and `hunks` is an iterable of
(`hunkrange`, `hunklines`) tuples.

See diff() for the meaning of parameters.
Nc                 F   ^^ 0 m[         R                  " 5       mUU4S jn U $ )Nc                   > UR                  U TR                  U 5      S9nU T;  a4  [        T5      S:  a  TTR                  5       	 UR	                  5       TU '   OTR                  U 5        TR                  U 5        U$ )N)filelog   )filectxr  r'   popleftr  r  r9   )r  r  r  cacheorders      r+   
getfilectx4diffhunks.<locals>.lrugetfilectx.<locals>.getfilectx.
  sg    ;;q%))A,;7D~u:?emmo.<<>aQLLOKr.   )collectionsdeque)r  r  r  s    @@r+   lrugetfilectx diffhunks.<locals>.lrugetfilectx*
  s#    !!#		 r.   )r  rp  c                0   >
 [        T
TTTTTT	TTU UT5      $ r]   )trydiff)r  losedatar  r   r  r  r  modifiedr  re  rb  revss     r+   difffndiffhunks.<locals>.difffn{
  s4    
 	
r.   c                6   > T(       a  T" U S9(       d  [         eg )N)r  )r  )r  r  s    r+   r  diffhunks.<locals>.losedata
  s    !r):)) *;r.   F)gitT)r   defaultoptsstatusr  listr  r  re  r   	debugflagr   r	   noder  upgrader
   
pathcopiesr   rd  r  rr  rz  r   
matchfilesrevprefetchfilesr   r  )rb  r  r  r  r  r  r  r  r   r  r  hexfuncr  r	  r~  modifiedsetaddedset
removedsetr  prefetchmatch
revmatchesr  r  r  r  r  re  r  s   ```   ```              @@@@@r+   r  r  
  s   & |  " J++d%+0'4  #*2A; % MMOO 	!% E'	ww'+yy{DIIK&@I&@dDMGDM&@ID|88t||$$T4u=D *.NXS9MNh-K5zHWJD= q!LLO  D= a 	 
 k"H8EZ G&d? S		 ' &&d;)J67M 
]#	]#J $
+
 
  ||DHH		5*
 tyyUy3X>?? dD!!Q J Ov  	5$)))-t44	5s*   %
L3LL1L$L  L/.L/c              #    #    U  H  nUR                  S5      nUR                  5       nUR                  S5      (       a  SnO2UR                  S5      (       a  SnO[        R                  " SU-  5      e[        R                  U5       H&  nUR                  S5      (       a  US4v   M!  XT4v   M(     X#:w  a  U[        U5      S	 S
4v   X!:w  d  M  U[        U5      S	 S4v   M     g	7f)z1yield tokens for a list of lines in a single hunkr   r!      diff.deletedr"      diff.inserted   unexpected hunk line: %sr       diff.tabN   diff.trailingwhitespacer.   )r  r%   r   ProgrammingErrortabsplitterfindallr'   )	hunklinesr(   	chompline	striplinelabeltokens         r+   diffsinglehunkr  
  s     KK(	$$&	??4  #E__T""$E(()Dt)KLL ((3E&&k**n$	 4 !S^-.0JKKI()3//) s   CC(C(c              #    #    [        5       n[        5       nU  H>  nUSS S:X  a	  XSS -  nM  USS S:X  a	  X#SS -  nM'  [        R                  " SU-  5      e   U(       a  U(       d  [        U 5       Sh  vN   g[        R                  [        U5      5      n[        R                  [        U5      5      nU Vs/ s H  ofS:X  a  UOUS-   PM     nnU Vs/ s H  ofS:X  a  UOUS-   PM     nnSR                  U5      n	SR                  U5      n
/ n/ n[        R                  " XXxS	9nU H  u  u  pnnnUS
:H  n[        R                  " SR                  XNU 5      5       H  nUR                  UU45        M     [        R                  " SR                  UUU 5      5       H  nUR                  UU45        M     M     SSU4SSU44 H  u  nnnSnU H  u  nnU(       a  UU4v   SnUR                  S5      nU(       aL  USS nUR                  S5      (       a  USS nU[        U5      S nUR                  5       nU[        U5      S n[        R                  U5       H'  nSUSS :X  a  SnOU(       a  US-   nOUS-   nUU4v   M)     U(       d  M  W(       a  US4v   WS4v   SnM     M     g GNBs  snf s  snf 7f)zEyield tokens for a list of lines in a single hunk, with inline colorsr   r   r!   Nr"   r  r   r.   )lines1lines2   !r  r  TFr     r    r  s   .changeds
   .unchangedr  )	bytearrayr   r  r  wordsplitterr  r   r2   r   	allblocksr  r9   r   r'   r  r  )r  r  r  r(   alblr  alnblnanbnatokensbtokensblocksa1a2b1b2btyperf  r  r   r  tokensnextisnewlineisendoflinechomp	endofline	endspacesmaybetabcurrentlabels                                  r+   diffsinglehunkinliner  
  s     	AA!9abMA!AY$abMA(()Dt)KLL  A!),,,			eAh	'B			eAh	'B35
62aU
1E	)2C
635
62aU
1E	)2C
6	#B	#BGG__RC<F#)R%4-(("))<=ENNGU+, >(("R))<=ENNGU+, >	 $* 
(	)"v $NGUuo% %../Kcr
>>%((!#2JE!#e*,/	!#e*,/	'//6HQqM)#.L',{':',}'<.. 7 {$&@AA #&& $7 %"- 	- 7
6s8   A5K7J98AK=J<KK/F(KK<
Kc              /  r  ^^#    UR                  S5      (       a  US   R                  (       a  [        mO[        m/ SQnS/nSn/ mUU4S jnU " U0 UD6 GHW  nUR	                  S5      n[        U5      n	[        U5       GH  u  pU(       a  UR                  S5      (       a  SnOU(       a  UR                  S5      (       d  S	nSnU(       d  U(       a  UR                  S
5      (       a  S	nUnU(       a  UnU(       a#  UnU
S-   U	:  a  US-  nTR                  U5        M  U" 5        Sh  vN   UR                  5       nU H;  u  nnUR                  U5      (       d  M  UU4v   X:w  a  U[        U5      S S4v     O   US4v   U
S-   U	:  d  GM  Sv   GM     U" 5        Sh  vN   GMZ     g N N7f)z@yields 2-tuples of (output, label) based on the output of func()r  )
)r5  s   diff.diffline)   copy   diff.extended)   renamer  )s   oldr  )s   newr  )s   deletedr  )s   indexr  )s
   similarityr  )r   s   diff.file_a)rG  s   diff.file_b)rE  s	   diff.hunkFc               3  L   >#    T(       a  T " T5       S h  vN   / TS S & g g  N7fr]   r^   )
dodiffhunk
hunkbuffers   r+   consumehunkbuffer$difflabel.<locals>.consumehunkbuffer  s(     !*---JqM -s   $"$r   rE  )r   r"   r!   rE  rW  T)r"   r!   r   Nr  r.   r   r.   )
r  worddiffr  r  r&   r'   r  r%   r9   r  )funcru  kwheadprefixestextprefixesheadr   r4   r3   	linecountr  r(   difflineprefixesbufferedliner  r   r  r  r  s                     @@r+   	difflabelr  
  s    	vvf~~"V*--)
#
L 	L D J
 t"r"E"J	 'GA??4(( D3! !  DHDT__\%B%B#H'#q59$ E)L!!,/ -... KKM	%-MFE ++F33(%00, $S^%5 6 :#   &.  +%q59$&&M (N %&&&U #6 / 	's0   D)F7-F3.0F7".F7F7(F5)F75F7c                 (    [        [        /U Q70 UD6$ )zBlike diff(), but yields 2-tuples of (output, label) for ui.write())r  r  )ru  r  s     r+   diffuir  I  s    T'D'B''r.   c              #    #    [        5       nUR                  " 5        VVs0 s H  u  pgXv_M	     nnn[        U5      [        U5      p[        X-   U-   5       H  nSnXpX;   a=  SnX;   a5  UR                  (       a$  X;   nX;   a  X;  a  SnUR	                  U5        O5SnO2X;   a-  SnUR                  (       a  X;   a  X   U	;   a  X8U      U:X  a  M{  XU4v   M     gs  snnf 7f)a
  generates tuples (f1, f2, copyop), where f1 is the name of the file
before and f2 is the the name after. For added files, f1 will be None,
and for removed files, f2 will be None. copyop may be set to None, 'copy'
or 'rename' (the latter two only if opts.git is set).Nr  r  )rd  r   rz  r  rr  )r  r  re  r   r  gonekrL  copytor  r  r  copyopf1f2s                  r+   
_filepairsr  N  s     
 5D#zz|,|tqad|F,u:s7|jH$w./B=By88B'BN!*!(_Bxx K	X-AY1,fn/ 0	 -s   C#CB4C#c                    U (       d  Sn [        U 5      n[        R                  " SU-  5      nUR                  U 5        [	        UR                  5       5      $ )Nr.   s   blob %d )r'   r   sha1r  r   digest)r  r*   r  s      r+   	_gitindexr  s  sA    D	AlQ&'AHHTNqxxz?r.   s   120000s   100755s   100644)r  r  r.   c              #    #    U	R                   (       a  S=pOSnSnS nS n[        R                  " UR                  5       5      n[        R                  " UR                  5       5      nU(       d  S n[	        XEXgU	5       GHO  u  nnnSnSnSnSnSnSnU(       a2  U" UU5      nU	R
                  (       d  U
(       a  UR                  U5      nU(       a2  U" UU5      nU	R
                  (       d  U
(       a  UR                  U5      nU	R                  (       a  SnO[        S	 UU4 5       5      nU
(       ay  U	R
                  (       dh  U(       dP  UU;   dJ  U(       d  U" U5      (       d6  U" U5      (       a  U(       a"  U(       d  U(       d  U(       a  U(       a  UU:w  a  U
" U=(       d    U5        U" U=(       d    U5      nU" U=(       d    U5      n/ nU	R
                  (       Ga  UR                  S
UUUU4-  5        U(       d  UR                  S[        U   -  5        OU(       d  UR                  S[        U   -  5        O[        U   [        U   n nUU :w  a(  UR                  SU-  5        UR                  SU -  5        Ubq  U	R                  (       a4  [        R                  " UU   UU   5      S-  n!UR                  SU!-  5        UR                  SUU4-  5        UR                  SUU4-  5        OU(       a  UR                  U" UU5      5        U(       ak  U	R
                  (       a3  U	R
                  (       aI  U	R                  (       a8  U	R                  (       d'  Ub  SnUb  Ub  UR!                  U5      (       d  SnO)SnO&Ub  UR#                  5       nUb  UR#                  5       nUUUUUU4n"UUUUUU4n#[%        U"U#UUU	5      v   GMR     g7f)zgiven input data, generate a diff and yield it in blocks

If generating a diff would lose data like flags or binary data and
losedatafn is not None, it will be called.

pathfn is applied to every path in the diff output.
r.   r   r   c                b    SR                  U Vs/ s H  nSU-  PM
     sn5      nSX04-  $ s  snf )Nr   s   -r %ss
   diff %s %sr  )r  r  r  revinfos       r+   r
  trydiff.<locals>.diffline  s5    ))t<tX^t<=|++ =s   ,c                >    U S L =(       d    U R                  5       S:H  $ r  )r  )r  s    r+   isemptytrydiff.<locals>.isempty  s    t|/tyy{a//r.   c                    U $ r]   r^   )r  s    r+   r  trydiff.<locals>.<lambda>  s    1r.   NFc              3  J   #    U  H  oc  M  UR                  5       v   M     g 7fr]   )isbinaryr  s     r+   r   trydiff.<locals>.<genexpr>  s     O~!~s   ##s   diff --git %s%s %s%ss   new file mode %ss   deleted file mode %ss   old mode %ss   new mode %sd   s   similarity index %d%%s
   %s from %ss   %s to %s    s     )noprefixr   datestrdater  r  r  r  r
  r9   _gitmodeshowsimilarityr   scorenobinaryindexcmpr   diffcontent)$rb  r  r  r  r  r  re  r   r  r  r  r  aprefixbprefixr
  r!  date1date2r  r  r  content1content2r  r  flag1flag2r   path1path2r   mode1mode2simdata1data2s$                                       r+   r  r    s3    , }}',0 TYY[)ETYY[)E$XgTJBr4(Exx:

2r4(Exx:

299FOu~OOFdhh d
 GENN  E u~28$rxR rxR 888MM'7E7E*JJ 1HUOCD5GH'uE>MM.5"89MM.5"89%**%mmDKeEK&>&DEMM-65/"ABMM+"?@MM(5$/0 TXX$--


    $UYYu-=-=$H&H   ::<  ::<ueUHe<ueUHe<%==I Ks   OOc                   U u  pVpxpUu  ppnnXu;   a  [        U	5      O[        R                  nX;   a  [        U5      O[        R                  nU(       a\  UR                  (       aK  UR                  (       d:  [
        R                  " X5      nU(       a  UR                  SUU4-  5        SU/44nOUR                  (       aO  UR                  S:  a?  UnUc  UnUR                  SUSUR                   USUR                   [        U   4-  5        [
        R                  " U	U
UUUUUUS9u  nnUR                  U5        XlUU4$ )a  diffs two versions of a file.

data1 and data2 are tuples containg:

    * ctx: changeset for the file
    * fctx: file context for that file
    * path1: name of the file
    * flag: flags of the file
    * content: full content of the file (can be null in case of binary)
    * date: date of the changeset

header: the patch header
binary: whether the any of the version of file is binary or not
opts:   user passed options

It exists as a separate function so that extensions like extdiff can wrap
it and use the file content directly.
s   index %s..%sNr   s   index %s..%s %s)r   r  )r  r   nullhexr  r0  r   b85diffr9   r1  r-  unidiffextend)rA  rB  r   r   r  r  r  r<  r:  r8  r6  r  r  r=  r;  r9  r7  index1index2r  r  flaguheaderss                          r+   r3  r3    s3   ( 27.Dx16.Dx$)MYx 7H7P7PF$)MYx 7H7P7PF$((4==}}X0MM/VV,<<=!88

QD|MM"1tzz*1tzz*TN  --	
% 	h&&r.   c                    Su  pp4nU  HG  u  pgp[        U[        R                  " U5      5      n[        X'U-   5      nX7-  nXH-  nU=(       d    U	nMI     XX4U4$ )N)r   r   r   r   F)r  r   colwidth)
statsmaxfilemaxtotaladdtotalremovetotalr   r  r  r  r  s
             r+   diffstatsumrS  H  sh    7H4Gxf
agx0034xQ'1  hV;;r.   c                l  ^^^^^	 [         R                  " S5      n/ m	Su  mmmmUUUUU	4S jnSnU  GHu  nUR                  S5      (       a  U" 5         SnSu  mmmUR                  S5      (       a&  [        R	                  U5      R                  S	5      mMe  UR                  S
5      (       a"  UR	                  U5      R                  S5      mM  M  UR                  S5      (       a  SnM  UR                  S5      (       a  U(       d  TS-  mM  UR                  S5      (       a  U(       d  TS-  mGM  UR                  S5      (       d  UR                  S5      (       a  SmGM3  UR                  S5      (       a  USS  mGMQ  UR                  S5      (       d  GMj  TSUSS  -  -  mGMx     U" 5         T	$ )Ns   ^diff .*-r [a-z0-9]+\s(.*)$)Nr   r   Fc                 @   > T(       a  TR                  TT TT45        g g r]   rY   )addsr%  r&  removesresultss   r+   	addresultdiffstatdata.<locals>.addresultZ  s     NNHdGX>? r.   Fr5  T)r   r   Fr   r$   s   diff -rr   s   @@r"   r!   r   s   Binary files   rename fromr   s	   rename tos    => %sr   )r   r   r%   r  r   r  )
r3   r   rY  r)   r(   rV  r%  r&  rW  rX  s
        @@@@@r+   diffstatdatar[  T  s}   ZZ78FG(9%HdGX@ @ H??7##K H&1#D'8/00 <<-33A6,,!==.44Q7 - __U##H__T""8AID__T""8qLG__011T__6
 6
 H__^,,BCyH__\**	DI--H3 4 KNr.   c           
       ^^ / n[        U 5      n[        U5      u  nmpVn[        [        T5      5      nU(       a  US:  a  SnX-
  U-
  S-
  mTS:  a  SmUU4S jn	U Ha  u  ppU(       a  SnOSX-   -  nSU	" U5      -  nSU	" U5      -  nUR	                  S	U
S
U[
        R                  " U
5      -
  -  UUUU4-  5        Mc     U(       a(  UR	                  [        S5      [        U5      XV4-  5        SR                  U5      $ )Nrp  rs  r   c                \   > TT::  a  U $ [        U T-  T-  [        [        U 5      5      5      $ r]   )r  r  bool)r  
graphwidthrP  s    r+   scalediffstat.<locals>.scale  s0    z!H 1z>X-s47|<<r.   s   Binr  r"   r!   s    %s%s |  %*s %s%s
r   s5    %d files changed, %d insertions(+), %d deletions(-)
r.   )	r[  rS  r'   r  r9   r   rM  r   r2   )r3   widthoutputrN  maxname	totaladdstotalremoves	hasbinary
countwidthr`  r%  rV  rW  r&  r  plusesminusesr_  rP  s                    @@r+   diffstatrk    s!   FE<G<N9GXy	S]#JZ!^
#g-1JB
= .3)ET^,Ed#w'"("3"3H"==>
	
 .3& GH5z934	

 88Fr.   c               /    #    [        U 0 UD6R                  5        H  nU(       a  US   S;   a  UR                  SS5      u  p4US-   S4v   [        R                  " SU5      nU(       a  UR                  S5      S4v   [        R                  " S	U5      nU(       a  UR                  S5      S
4v   OUS4v   Sv   M     g7f)zGlike diffstat(), but yields 2-tuples of (output, label) for
ui.write()
r  s   +-r   r   r.   s   \++r   s   diffstat.inserteds   -+s   diffstat.deletedr  N)rk  r   rsplitr   r   r  )ru  r  r(   namegraphrH   s         r+   
diffstatuirp    s     
 $%"%002DH%++dA.KD$;$$		'5)Awwqz#788		&%(Awwqz#677+ 3s   C Cr]   )r   r.   r  )Nr  )r.   Nr  r   )r   r.   Nr  r   )r   r.   )
NNNNNNNNNN)NNNNNNN)returnzIterator[tuple[Any, bytes]])P   )m
__future__r   r  
contextlibr   r   r   r  r   r  i18nr   r  r   r   r	    r
   r   r   r   r   r   r   r   r   r   r   r   r   r<  utilsr   r   r   r   TYPE_CHECKINGemailr   r   r1   r   r  r  r  rg  r  rn  r&   r   contextmanagerr   r   r   r
  r  r  r9  r_  r  r  r  r  r}  r  r   r:  rh  r  r  r  r  r  r|  r   r.  r  rC  rM  r  r]  ra  r\  rz  r  r  r  r  r  	Exceptionr  diffalloptsdiffoptsdifffeatureoptsr  r  r  r  r  r  r  r  r-  r  r3  rS  r[  rk  rp  r^   r.   r+   <module>r     s   #    	 	     
     

 ==


/0jj)*zzA 
''33 
@J  4sl-: -:`*Z( (* "  "F.* .*b/(Y /(d#, #,L*+/ *+\ **C
DjjKL/d dNM
 M
`kB kB\@Foda, a,H; ;|=@M`&9R:z0%f6dKN8v, CL\~.d ?HF 
N" HQN 
B4	i 	 ""**
 

		H^ 		C"L02D%RJ'Z(
"J 99=M>`6'r	<*Z-`r.   