
    6h!                        S SK Jr  S SKrS SKJr  S SKJrJrJrJ	r	J
r
JrJr  SSKJr  \	R                  r\	R                   rSr\R                  " 5       rS rS	 rS
 rS r\R/                  \S5      S 5       rS rg)    )annotationsN)_)error	exthelperhttppeerutilwireprototypeswireprotov1peerwireprotov1server   )lfutilsa   
This repository uses the largefiles extension.

Please enable it in your Mercurial config file.
c                P   UR                  5        n[        R                  " X5      n[        R                  " [
        R                  R                  U5      5        [        R                  " X@R                  R                  S9n UR                  5        H  nUR                  U5        M     UR                  R                  S5        U[        R                  " UR                  5      :w  a  [!        S[#        S5      5      eUR%                  5         [        R&                  " X5         UR5                  5          SSS5        [.        R0                  " SW(       a  UR3                  5       5      $ S5      $ ! [          a  nU R(                  R+                  [#        S5      X'R,                  4-  5        [.        R0                  " SU(       a  UR3                  5       OS5      s SnAUR5                  5         sSSS5        $ SnAff = f! UR5                  5         f = f! , (       d  f       N= f)z_Server command for putting a largefile into a repository's local store
and into the user cache.)
createmoder   s$   largefile contents do not match hashs,   largefiles: failed to put %s into store: %s
r       N)mayberedirectstdior   	storepathr   makedirsospathdirnameatomictempfilestorer   
getpayloadwrite_fpseekhexsha1OSErrorr   closelinktousercacheuiwarnstrerrorr	   pushresgetvaluediscard)repoprotoshaoutputr   tmpfppes           8/usr/lib/python3/dist-packages/hgext/largefiles/proto.pyputlfiler/   $   s    
	!	!	#v*bggood+,##DZZ5J5JK	%%'A (IINN1fnnUYY//a#J!KLLKKM""4- MMO- 
$0 !!!&V__%6JJcJJ  	GGLLBC

#$ "))6??$C  MMO- 
$	#	 MMO- 
$	#sP   A2HB"E2'H2
G?<AG:G?H H:G??HHH
H%c                8  ^^ [         R                  " X5      nU(       d"  [        R                  " [	        S5      U-  5      e[        US5      m[        R                  " TR                  5       5      R                  mUU4S jn[        R                  " U" 5       S9$ )zXServer command for retrieving a largefile from the repository-local
cache or user cache.s+   requested largefile %s not present in cacherbc               3  \   >#    ST-  v   [         R                  " T 5       S h  vN   g  N7f)Ns   %d
)r   filechunkiter)flengths   r.   	generatorgetlfile.<locals>.generatorT   s%     %%a(((s   !,*,)gen)r   findfiler   Abortr   openr   fstatfilenost_sizer	   streamreslegacy)r'   r(   r)   filenamer6   r4   r5   s        @@r.   getlfilerA   B   sw     t)Hkk<=C
 	

 	XtAXXahhj!))F) ))ik::r   c                    [         R                  " X5      nU(       d  [        R                  " S5      $ [        R                  " S5      $ )a;  Server command for checking if a largefile is present - returns '2
' if
    the largefile is missing, '0
' if it seems to be in good condition.

    The value 1 is reserved for mismatched checksum, but that is too expensive
    to be verified on every stat and must be caught be running 'hg verify'
    server side.s   2
s   0
)r   r9   r	   bytesresponse)r'   r(   r)   r@   s       r.   	statlfilerD   [   s7     t)H++F33''//r   c                Z   ^ UR                   m " U4S jSUR                  5      nX!l        g )Nc                  v   > \ rS rSrU 4S jr\R                  S 5       rS rS r	\R                  S 5       r
Srg)	+wirereposetup.<locals>.lfileswirerepositoryk   c                   >^ T" 5       nU R                  S5      (       a*  UR                  m " U4S jSUR                  5      nX!l        U$ )Ns
   largefilesc                  "   > \ rS rSrU 4S jrSrg)Wwirereposetup.<locals>.lfileswirerepository.commandexecutor.<locals>.lfscommandexecutorq   c                $   > US:X  a  SnT" X5      $ )Ns   headss   lheads )selfcommandargsorig_callcommands      r.   callcommandcwirereposetup.<locals>.lfileswirerepository.commandexecutor.<locals>.lfscommandexecutor.callcommandr   s    "h.&/G/>>r   rN   N)__name__
__module____qualname____firstlineno__rS   __static_attributes__)rR   s   r.   lfscommandexecutorrK   q   s    ? ?r   rZ   )capablerS   	__class__)rO   executorrZ   rR   orig_commandexecutors      @r.   commandexecutor;wirereposetup.<locals>.lfileswirerepository.commandexecutorl   sE    +-H||M**#+#7#7 ?);); ? &8"Or   c                8    U R                   R                  U 5      $ )N)heads	batchable)rO   s    r.   lheads2wirereposetup.<locals>.lfileswirerepository.lheadsz   s    ::''--r   c                   [        U R                  [        R                  5      (       aq  U R                  SUUSS0S9n UR	                  SS5      u  pEUR                  S5       H(  nU R                  R                  [        S5      U5        M*     [        U5      $  U R                  SX!S
9u  puUS:X  a   [        R                  " [        S5      U5      e[        U5      $ ! [         a*    U R                  R                  [        S	5      U-  5         gf = f! [         a     g[         a!    [        R                  " [        S5      W5      ef = f)Ns   putlfilezcontent-typezapplication/mercurial-0.1)datar)   headers   
r   Ts   remote: s!   unexpected putlfile response: %r
r)   r   s   putlfile failed:s&   putlfile failed (unexpected response):)
issubclassr\   r   _callsplit
splitlinesr!   r"   r   int
ValueError	_callpushr   ResponseErrorr   )rO   r)   fdresdr*   lrets           r.   r/   4wirereposetup.<locals>.lfileswirerepository.putlfile~   s<    $..(*;*;<<jj+-HI	 !  #		% 3IA#..t4Q{^Q7 5q6M"&..b."JKCcz#1112F  s8O " GGLL#H!IC!OP  ! --CDc s%   AC AD 1DD
E"*Ec              3    #    U R                  SUS9nUR                  5       n [        U5      n[        R                  " X#S9 H  nUv   M	     [        U R                  [        R                  5      (       aI  UR                  S5      nU(       a0  U R	                  [
        R                  " [        S5      U5      5        ggg! [         a2    U R	                  [
        R                  " [        S5      U5      5         Nf = f7f)z<returns an iterable with the chunks of the file with sha shas   getlfilerj   s   unexpected response:)limitr   N)_callstreamreadlinero   rp   _abortr   rr   r   r   r3   rk   r\   r   read)rO   r)   streamr5   chunks        r.   rA   4wirereposetup.<locals>.lfileswirerepository.getlfile   s     %%ks%;F__&FV ++FA B $..(*;*;<<AKK++A.E,FN  =  ''*A(BFKs(   !D C BD 9C=:D <C==D c                    S nSU0nX24$ )Nc                Z     [        U 5      $ ! [        [        R                  4 a     gf = f)N   )ro   rp   urlerr	httperror)ru   s    r.   decodeEwirereposetup.<locals>.lfileswirerepository.statlfile.<locals>.decode   s/    q6M"F$4$45 
 s   
 **s   sharN   )rO   r)   r   results       r.   rD   5wirereposetup.<locals>.lfileswirerepository.statlfile   s     c]F>!r   rN   N)rU   rV   rW   rX   r_   r
   rc   rd   r/   rA   rD   rY   )r^   s   r.   lfileswirerepositoryrG   k   sG    	 
	"	"	. 
#	.#	J	. 
	"	"	" 
#	"r   r   )r_   r\   )r!   r'   r   r^   s      @r.   wirereposetupr   h   s)    //\"t~~ \"| *Nr   _capabilitiesc                8    U " X5      nUR                  S5        U$ )z$announce largefile server capabilitys   largefiles=serve)append)origr'   r(   capss       r.   r   r      s      DKK#$Kr   c                |    [         R                  " U5      (       a  [        R                  " [        5      $ U " X5      $ )zPWrap server command - largefile capable clients will know to call
lheads instead)r   islfilesrepor	   ooberrorLARGEFILES_REQUIRED_MSG)r   r'   r(   s      r.   rb   rb      s2     4  &&'>??r   )
__future__r   r   mercurial.i18nr   	mercurialr   r   r   r   r	   r
   r    r   r   urlreqr   ehr/   rA   rD   r   wrapfunctionr   rb   rN   r   r.   <module>r      s    # 	    		  K<;2
0a*J "O4 5r   