o ]Lb>@sddlmZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z mZddlmZe jZe jZdZe Zd d Zd d Zd dZddZeedddZddZdS))absolute_importN)_)open)error exthelperhttppeerutilwireprototypeswireprotov1peerwireprotov1server)lfutilsa This repository uses the largefiles extension. Please enable it in your Mercurial config file. c CsT|}t||}ttj|tj||j j d}zkz-| D]}| |q#|j d|t|j kr@tdtd|t||Wn7ty}z+|jtd||jftd|ri|ndWYd}~W|WdSd}~wwW|n|wWdn1swYtd|r|SdS)zcServer command for putting a largefile into a repository's local store and into the user cache.) createmoders$largefile contents do not match hashs,largefiles: failed to put %s into store: %s r N)mayberedirectstdior storepathrmakedirsospathdirnameatomictempfilestorer getpayloadwrite_fpseekhexsha1IOErrorrcloselinktousercacheuiwarnstrerrorr pushresgetvaluediscard)repoprotoshaoutputrtmpfpper-8/usr/lib/python3/dist-packages/hgext/largefiles/proto.pyputlfile$s:       r/csZt||}|sttd|t|dtdfdd}t j |dS)z\Server command for retrieving a largefile from the repository-local cache or user cache.s+requested largefile %s not present in cachesrbc3s&dVtD]}|Vq dS)Ns%d )r filechunkiter)chunkflengthr-r. generatorRs  zgetlfile..generator)gen) r findfilerAbortrrrfstatfilenor streamreslegacy)r&r'r(filenamer6r-r3r.getlfileBs   r>cCs$t||}|s tdStdS)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.s2 s0 )r r8r bytesresponse)r&r'r(r=r-r-r. statlfileZs   r@cs&|jGfddd|j}||_dS)NcsDeZdZfddZejddZddZddZejd d Z d S) z+wirereposetup..lfileswirerepositorycs6}|dr|jGfddd|j}||_|S)Ns largefilescseZdZfddZdS)zWwirereposetup..lfileswirerepository.commandexecutor..lfscommandexecutorcs|dkrd}||S)Nsheadsslheadsr-)selfcommandargsorig_callcommandr-r. callcommandqs zcwirereposetup..lfileswirerepository.commandexecutor..lfscommandexecutor.callcommandN)__name__ __module__ __qualname__rFr-rDr-r.lfscommandexecutorpsrJ)capablerF __class__)rAexecutorrJorig_commandexecutorrDr.commandexecutorks  z;wirereposetup..lfileswirerepository.commandexecutorcSs |j|S)N)heads batchable)rAr-r-r.lheadsys z2wirereposetup..lfileswirerepository.lheadscSst|jtjrE|jd||ddid}z|dd\}}|dD] }|jtd|q t |WSt yD|jtd |YdSwz|j d||d \}}|d kr\t td |t |WStyjYdSt yxt td |w)Nsputlfilez content-typezapplication/mercurial-0.1)datar(headers r Tsremote: s!unexpected putlfile response: %r r(rsputlfile failed:s&putlfile failed (unexpected response):) issubclassrLr_callsplit splitlinesr r!rint ValueError _callpushr ResponseErrorr)rAr(fdresdr)lretr-r-r.r/}s<     z4wirereposetup..lfileswirerepository.putlfilec ss|jd|d}|}zt|}Wnty&|ttd|Ynwtj ||dD]}|Vq.t |j t j rO| d}|rQ|ttd|dSdSdS)zs(   z4wirereposetup..lfileswirerepository.getlfilecSsdd}d|i}||fS)Nc Ss&zt|WSttjfyYdSw)N)r\r]urlerr httperror)rbr-r-r.decodes  zEwirereposetup..lfileswirerepository.statlfile..decodesshar-)rAr(rnresultr-r-r.r@s z5wirereposetup..lfileswirerepository.statlfileN) rGrHrIrPr rRrSr/r>r@r-rNr-r.lfileswirerepositoryjs  %rp)rPrL)r r&rpr-rNr. wirereposetupgs ^rqs _capabilitiescCs|||}|d|S)z$announce largefile server capabilityslargefiles=serve)append)origr&r'capsr-r-r. _capabilitiess  rucCst|r ttS|||S)zTWrap server command - largefile capable clients will know to call lheads instead)r islfilesrepor ooberrorLARGEFILES_REQUIRED_MSG)rsr&r'r-r-r.rQs   rQ) __future__rrmercurial.i18nrmercurial.pycompatr mercurialrrrrr r r r rlurlreqrxehr/r>r@rq wrapfunctionrurQr-r-r-r.s$   $  e