
    	^c                         d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
mZmZ ddlmZ e	j        Ze	j        ZdZ ej                    Zd Zd	 Zd
 Zd Ze                    ed          d             Zd ZdS )    N)_)open)error	exthelperhttppeerutilwireprototypeswireprotov1peerwireprotov1server   )lfutilsa   
This repository uses the largefiles extension.

Please enable it in your Mercurial config file.
c                 X   |                                 5 }t          j        | |          }t          j        t
          j                            |                     t          j        || j	        j
                  }	 |                                D ]}|                    |           |j                            d           |t          j        |j                  k    rt!          dt#          d                    |                                 t          j        | |           n# t           $ r}| j                            t#          d          ||j        fz             t/          j        d|r|                                nd          cY d}~|                                 cddd           S d}~ww xY w	 |                                 n# |                                 w xY w	 ddd           n# 1 swxY w Y   t/          j        d|r|                                nd          S )zcServer 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IOErrorr   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/   #   sj    
	!	!	#	# vc**bgood++,,,#DTZ5JKKK	%%''  AINN1fnUY////a#J!K!KLLLKKMMM"4---- 	 	 	GLLBCC
#$   ")76??$$$C       MMOOO-       	 . MMOOOOEMMOOOOO-              0 !!&%IV__%6%6%6cJJJs\   A'G6=B)D'&G'
F71AF2F7GG62F77G;G6G&&G66G:=G:c                 :   t          j        | |          }|s$t          j        t	          d          |z            t          |d          t          j                                                  d         fd}t          j
         |                      S )z\Server command for retrieving a largefile from the repository-local
    cache or user cache.s+   requested largefile %s not present in caches   rb   c               3   P   K   dz  V  t          j                  D ]} | V  d S )Ns   %d
)r   filechunkiter)chunkflengths    r.   	generatorzgetlfile.<locals>.generatorQ   sG      '** 	 	EKKKK	 	r   )gen)r   findfiler   Abortr   r   r   fstatfilenor	   streamreslegacy)r'   r(   r)   filenamer7   r5   r6   s        @@r.   getlfiler?   A   s     tS))H 
k<==C
 
 	
 	XuAXahhjj!!!$F     
 )iikk::::r   c                     t          j        | |          }|st          j        d          S t          j        d          S )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.   	statlfilerB   Y   s?     tS))H 4+F333'///r   c                 N    |j          G fdd|j                  }||_        d S )Nc                   f    e Zd Z fdZej        d             Zd Zd Zej        d             Z	dS )+wirereposetup.<locals>.lfileswirerepositoryc                                  }|                      d          r#|j         G fdd|j                  }||_        |S )Ns
   largefilesc                       e Zd Z fdZdS )Wwirereposetup.<locals>.lfileswirerepository.commandexecutor.<locals>.lfscommandexecutorc                 ,    |dk    rd} ||          S )Ns   headss   lheads )selfcommandargsorig_callcommands      r.   callcommandzcwirereposetup.<locals>.lfileswirerepository.commandexecutor.<locals>.lfscommandexecutor.callcommandp   s&    "h..&/G//>>>r   N)__name__
__module____qualname__rO   )rN   s   r.   lfscommandexecutorrH   o   s.        ? ? ? ? ? ? ?r   rS   )capablerO   	__class__)rK   executorrS   rN   orig_commandexecutors      @r.   commandexecutorz;wirereposetup.<locals>.lfileswirerepository.commandexecutorj   su    ++--H||M** 	8#+#7 ? ? ? ? ? ? ?); ? ? ? &8"Or   c                 6    | j                             |           S )N)heads	batchable)rK   s    r.   lheadsz2wirereposetup.<locals>.lfileswirerepository.lheadsx   s    :''---r   c                    t          | j        t          j                  r|                     d||ddi          }	 |                    dd          \  }}|                    d          D ]*}| j                            t          d          |           +t          |          S # t          $ r. | j                            t          d	          |z             Y dS w xY w	 |                     d||
          \  }}|dk    r"t          j        t          d          |          t          |          S # t          $ r Y dS t          $ r# t          j        t          d          |          w xY w)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):)
issubclassrU   r   _callsplit
splitlinesr!   r"   r   int
ValueError	_callpushr   ResponseErrorr   )rK   r)   fdresdr*   lrets           r.   r/   z4wirereposetup.<locals>.lfileswirerepository.putlfile|   s    $.(*;<< jj+-HI	 !   #		% 3 3IAv#..t44 8 8Q{^^Q7777q66M!   GLL#H!I!IC!OPPP11"&..bc."J"JKCczz#1122F   s88O   11!   -CDDc  s%   A'B$ $4CC AD2 2
E+?,E+c              3   $  K   |                      d|          }|                                }	 t          |          }nE# t          $ r8 |                     t          j        t          d          |                     Y nw xY wt          j	        ||          D ]}|V  t          | j        t          j                  rN|                    d          }|r9|                     t          j        t          d          |                     dS dS dS )z<returns an iterable with the chunks of the file with sha shas   getlfilera   s   unexpected response:)limitr   N)_callstreamreadlinerf   rg   _abortr   ri   r   r   r3   rb   rU   r   read)rK   r)   streamr6   r4   s        r.   r?   z4wirereposetup.<locals>.lfileswirerepository.getlfile   s<     %%ks%;;F__&&FV   '*A(B(BFKK     +F&AAA   $.(*;<< A KK+A.E,F,FNN      s   ? ?B Bc                     d }d|i}||fS )Nc                 \    	 t          |           S # t          t          j        f$ r Y dS w xY w)N   )rf   rg   urlerr	httperror)rl   s    r.   decodezEwirereposetup.<locals>.lfileswirerepository.statlfile.<locals>.decode   s>    q66M"F$45   
 11s    ++s   sharJ   )rK   r)   r{   results       r.   rB   z5wirereposetup.<locals>.lfileswirerepository.statlfile   s&       c]F6>!r   N)
rP   rQ   rR   rX   r
   r[   r\   r/   r?   rB   )rW   s   r.   lfileswirerepositoryrE   i   s        	 	 	 	 	 
	"	. 	. 
#	"	.#	 #	 #	J	 	 	. 
	"	" 	" 
#	"	" 	" 	"r   r}   )rX   rU   )r!   r'   r}   rW   s      @r.   wirereposetupr~   f   sZ    /\" \" \" \" \" \" \"t~ \" \" \"| *DNNNr   s   _capabilitiesc                 H     | ||          }|                     d           |S )z$announce largefile server capabilitys   largefiles=serve)append)origr'   r(   capss       r.   _capabilitiesr      s-     4eDKK#$$$Kr   c                 t    t          j        |          rt          j        t                    S  | ||          S )zTWrap server command - largefile capable clients will know to call
    lheads instead)r   islfilesrepor	   ooberrorLARGEFILES_REQUIRED_MSG)r   r'   r(   s      r.   rZ   rZ      s<     4   @&'>???4er   )r   mercurial.i18nr   mercurial.pycompatr   	mercurialr   r   r   r   r	   r
   r    r   ry   urlreqr   ehr/   r?   rB   r~   wrapfunctionr   rZ   rJ   r   r.   <module>r      sT   
			       # # # # # #                       		  YK K K<; ; ;0
0 
0 
0a* a* a*J "$455  65    r   