
    6hX                       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Jr  S SK	J
r
Jr  S SKJrJrJrJrJrJr  S SKJrJr  SSKJrJrJr  \R4                  rS qS qS qS qSr S	 r!S
 r"S r# " S S5      r$S r%S r&S r' " S S5      r(g)    )annotationsN)_)binhex)errorpycompatrevlogsshpeerutilwireprotov1peer)hashutilprocutil   )	constantscontentstoremetadatastorec                    [        [        R                  " U5      R                  5       5      n[        R
                  R                  XS S USS  U5      $ )N   r   r   sha1digestospathjoin)reponamefileidpathhashs       F/usr/lib/python3/dist-packages/hgext/remotefilelog/fileserverclient.pygetcachekeyr    0   sA    8==&--/0H77<<2A,bAA    c                    [        [        R                  " U 5      R                  5       5      n[        R
                  R                  X!5      $ Nr   )r   r   r   s      r   getlocalkeyr$   5   s1    8==&--/0H77<<%%r!   c                :     " S SUR                   5      nX!l         g )Nc                     ^  \ rS rSr\R
                  S 5       r\R
                  S 5       rS rU 4S jr	U 4S jr
SrU =r$ )!peersetup.<locals>.remotefilepeer;   c                z   ^^ U R                  S5      (       d  [        R                  " S5      eUU4S jnTTS.U4$ )N   x_rfl_getfiles5   configured remotefile server does not support getfilec                   > U R                  SS5      u  p[        U5      (       a  [        R                  " TTU5      eU$ )N    r   )splitintr   LookupError)dcodedatar   nodes      r   decode?peersetup.<locals>.remotefilepeer.x_rfl_getfile.<locals>.decodeC   s8    WWUA.
t99++D$==r!   s   files   nodecapabler   Abort)selfr   r3   r4   s    `` r   x_rfl_getfile/peersetup.<locals>.remotefilepeer.x_rfl_getfile<   s>    << 011kkL  "D1699r!   c                l    U R                  S5      (       d  [        R                  " S5      eS nSU0U4$ )Ns   x_rfl_getflogheadss:   configured remotefile server does not support getflogheadsc                6    U (       a  U R                  S5      $ / $ )N   
)r-   )r0   s    r   r4   Dpeersetup.<locals>.remotefilepeer.x_rfl_getflogheads.<locals>.decodeS   s    )*qwwu~22r!   s   pathr7   )r:   r   r4   s      r   x_rfl_getflogheads4peersetup.<locals>.remotefilepeer.x_rfl_getflogheadsK   s>    << 566kk, 
3 T?F**r!   c                   US:w  a  g [         R                  U R                  5       ;  a  g [        U S5      (       d  g [         R                  U R
                  R                  ;  a  g UR                  S5      nU(       a  U/nO/ nUR                  [         R                  5        U R
                  R                  (       a;  SR                  U R
                  R                  5      nSU-   nUR                  U5        U R
                  R                  (       a;  SR                  U R
                  R                  5      nSU-   nUR                  U5        SR                  U5      US'   g )Ns	   getbundle
_localrepos
   bundlecapsr,   s   includepattern=s   excludepattern=   ,)r   NETWORK_CAP_LEGACY_SSH_GETFILEScapabilitieshasattrSHALLOWREPO_REQUIREMENTrD   requirementsgetappendBUNDLE2_CAPABLITYincludepatternr   excludepattern)r:   commandopts
bundlecapspatterns
includecap
excludecaps          r   _updatecallstreamopts7peersetup.<locals>.remotefilepeer._updatecallstreamoptsX   s   ,&99((*+ 4..11334 -0J(\

 i99:-- ::doo&D&DE/(:
!!*--- ::doo&D&DE/(:
!!*-"&))J"7Dr!   c                H   > U R                  X5        [        TU ]  " X40 UD6$ r#   )rV   super_sendrequest)r:   rP   argsrQ   	__class__s       r   rZ   .peersetup.<locals>.remotefilepeer._sendrequest   s&    &&w57'>>>r!   c                   > [        5       n[        US5      (       d&  U R                  U[        R                  " U5      5        [         TU ]  " U40 UD6$ )NrZ   )rY   rH   rV   r   byteskwargs_callstream)r:   rP   rQ   	supertyper\   s       r   r`   -peersetup.<locals>.remotefilepeer._callstream   sG    I9n55**7H4H4H4NO7&w7$77r!    )__name__
__module____qualname____firstlineno__r   	batchabler;   rA   rV   rZ   r`   __static_attributes____classcell__r\   s   @r   remotefilepeerr'   ;   sJ    		"	"	: 
#	: 
	"	"
	+ 
#
	+&	8P	?	8 	8r!   rl   rk   )uipeerrl   s      r   	peersetupro   :   s    M8 M8^ $Nr!   c                  :    \ rS rSrSrS rS rS rS
S jrS r	Sr
g	)cacheconnection   zThe connection for communicating with the remote cache. Performs
gets and sets by communicating with an external process that has the
cache-specific implementation.
c                J    S =U l         =U l        U l        S U l        SU l        g )NF)pipeopipeipipee
subprocess	connectedr:   s    r   __init__cacheconnection.__init__   s%    /33
3TZ$*r!   c                    U R                   (       a  [        R                  " [        S5      5      e[        R
                  " U5      u  U l        U l         U l        U l        SU l	        g )Ns   cache connection already openT)
rt   r   r9   r   r   popen4ru   rv   rw   rx   )r:   cachecommands     r   connectcacheconnection.connect   sI    ::++a @ABB>Foo?
;
DJ
DO r!   c                   S nU R                   (       a   U R                  R                  S5        U" U R                  5        S U l        U" U R                  5        S U l        U" U R
                  5        S U l         U R                  R                  5         S U l        SU l         g ! [         a     Nf = f! [         a     N+f = f)Nc                F     U R                  5         g ! [         a     g f = fr#   )close	Exception)pipes    r   tryclose'cacheconnection.close.<locals>.tryclose   s"    

 s    
  s   exit
F)rx   ru   writer   rt   rv   rw   communicate)r:   r   s     r   r   cacheconnection.close   s    	 >>

  + TZZ DJTZZ DJTZZ DJ ++- #DO!    s#   B& =B6 &
B32B36
CCc                    U R                   (       a?   U R                  R                  U5        U(       a  U R                  R                  5         g g g ! [         a    U R                  5          g f = fr#   )rx   ru   r   flushOSErrorr   )r:   requestr   s      r   r   cacheconnection.request   sW    >>

  )JJ$$&  
  

s   <A A/.A/c                    U R                   (       d  g  U R                  R                  5       S S nU(       d  U R                  5         U$ ! [         a    U R                  5          W$ f = f)N)rx   rt   readliner   r   )r:   results     r   receivelinecacheconnection.receiveline   s\    ~~	ZZ((*3B/F

   	JJL	s   4A
 
A('A()rx   rv   ru   rt   rw   NT)rd   re   rf   rg   __doc__rz   r   r   r   r   ri   rc   r!   r   rq   rq      s     

8
r!   rq   c                   U R                  5        n/ nU H,  nUR                  UR                  SXH   USS  S.5      5        M.     [        U5       HV  u  pXy   R	                  5       n
S Xy'   XH   nUSS  nU" [
        R                  " S[        U
5      U
4-  5      X5        U" 5         MX     S S S 5        g ! , (       d  f       g = f)Nr*   r6   s   %d
%s)commandexecutorrL   callcommand	enumerater   ioBytesIOlen)remotereceivemissingprogresstickmissedidmap	batchsizeefuturesmirfile_r3   s                r   _getfilesbatchr      s     
			!QANN$1ST7&K  f%DA
!!#AGJHEST7D2::i3q61+&=>LN & 
"	!	!s   BB44
Cc                   U R                  S5        SnU R                  nU R                  nU[        U5      :  a  Un	[	        [        U5      X-   5      n
U
nX9U
  H#  nUSS  nXK   nSX4-  nUR                  U5        M%     UR                  5         X9U
  H  nUSS  nXK   nU" XU5        U" 5         M     U[        U5      :  a  M  UR                  S5        UR                  5         g )N   x_rfl_getfilesr   r      %s%s
r?   )r`   _pipeo_pipeir   minr   r   )r   r   r   r   r   stepr   rt   ru   startend	missingid	versionidr   
sshrequests                  r   _getfiles_optimisticr      s     ()	AMMEMME
c&k/#f+u|,c*I!#$I#D"i%66JKK
# + 	  c*I!#$I#D5	2N	 + c&k/* 
KK	KKMr!   c                j  ^^^ U R                  S5        U R                  mU R                  nUUU4S jn[        R                  " US9nSUl        UR                  5         T H  n	U	SS  n
TU	   nU" XkU
5        U" 5         M     UR                  5         TR                  S5        TR                  5         g )Nr   c                 z   > T H$  n U SS  nTU    nSX4-  nTR                  U5        M&     TR                  5         g )Nr   r   )r   r   )r   r   r   r   r   r   rt   s       r   writer"_getfiles_threaded.<locals>.writer  sF    I!#$I#D"i%66JKK
#	  
 	r!   )targetTr   r?   )
r`   r   r   	threadingThreaddaemonr   r   r   r   )r   r   r   r   r   r   ru   r   writerthreadr   r   r   rt   s      ``       @r   _getfiles_threadedr     s     ()MMEMME ##62LL	cdO	YuI.	  	KK	KKMr!   c                  Z    \ rS rSrSrS rS rS rS rS r	S r
S	 r SS
 jrS rS rSrg)fileserverclienti0  z:A client for requesting files from the remote file server.c                H   UR                   nXl        X l         UR                  SS5      U l        U R                  (       a%  [        R
                  " U R                  5      U l        UR                  SS5      U l        UR                  SS5      U l        [        5       U l
        g )N   remotefilelogs   cacheprocesss   cacheprocess.includepaths   debug)rm   repoconfigcacheprocessr   
expandpath
configboolcacheprocesspasspathdebugoutputrq   remotecache)r:   r   rm   s      r   rz   fileserverclient.__init__3  s    WW	II&6H $0A0A BD %'MM9%
! ==)98D*,r!   c                4    Xl         X l        X0l        X@l        g r#   )	datastorehistorystore	writedatawritehistory)r:   r   r   r   r   s        r   setstorefileserverclient.setstoreE  s    "("(r!   c                t    U R                   R                  R                  U R                   R                  5      $ r#   )r   connectionpoolrK   fallbackpathry   s    r   _connectfileserverclient._connectK  s'    yy''++DII,B,BCCr!   c           	     *
   U R                   R                  (       d  U R                  5         U R                   nU R                  nU R                  n[        U5      nSU-  n0 nUR                  nU H4  u  p[        XU
5      nU R                  (       a  XiS-   -  nXkS-   -  nXU'   M6     UR                  U5        U R                  R                  [        S5      US9nUR                  S5        / n UR                  5       nU(       dQ  [        U5      nU H  nX;  d  M
  UR!                  U5        M     U R                  R#                  [        S5      5        O`US:X  a  OYUR%                  S	5      (       a0  UR'                  S
5      nUR)                  [+        US   5      5        M  UR!                  U5        M  [,        [        U5      -  qU[        U5      -
  nUR                  UUS9  U R                  R/                  SSUUUUS9  [0        R2                  " S5      n U(       Ga'  U R                  R4                  nSU R                  l         U R7                  5        nUR8                  nUR;                  [<        R>                  5      (       a  [A        U[B        5      (       d  [D        RF                  " S5      eU R                  RI                  SS5      nU R                  RK                  SS5      nUS:X  a  [L        nO[N        nU" UU RP                  UR(                  UUU5        OUR;                  S5      (       a  UR;                  S5      (       a  SnOSnU R                  RI                  SSU5      nU R                  RS                  S[        U5      -  5        [U        UU RP                  UR(                  UUU5        O[D        RF                  " S5      eSSS5        U R                  R/                  SSURV                  U-
  UU-
  S9   UU R                  l        S [        U5      SR[                  U5      4-  nUR                  U5        UR]                  5         UR_                  U R                  R`                  5        [0        R2                  " U5        g! , (       d  f       N= f! [X         a.    U R                  R/                  SSURV                  U-
  UU-
  S9  e f = f! UU R                  l        f = f! [0        R2                  " U5        f = f)!zTakes a list of filename/node pairs and fetches them from the
server. Files are stored in the local cache.
A list of nodes that the server couldn't find is returned.
If the connection fails, an exception is raised.
s   get
%d
r,   r?   s   downloading)totalr   s@   warning: cache connection closed early - falling back to server
   0s   _hits_   _r   r   s"   remote cache hit rate is %r of %r
)hitr   Fs"   remotefilelog requires ssh serverss   getfilessteps   getfilestypes   threadedr*   s   batchd   
   s	   batchsizes1   requesting %d files from remotefilelog server...
s>   configured remotefilelog server does not support remotefilelogNs   remotefilefetchlogs   Success
)fetched_filestotal_to_fetchs   Fail
s
   set
%d
%s
)1r   rx   r   r   r   r   namer    r   r   rm   makeprogressr   updater   setrL   warn
startswithr-   	incrementr.   fetchmisseslogr   umaskverboser   rn   r8   r   rF   
isinstance
_sshv1peerr   r9   	configintr   r   r   r   debugr   posr   r   completemarkrepor   )r:   fileidscacher   r   r   r   r   r   r   r   fullidprogressr   r   	missedsetparts	fromcacheoldumaskr   connr   r   getfilestype	_getfilesbatchdefaultr   s                              r   r   fileserverclient.requestN  s    ))LLN  NN	yyG&99HD 4F((%<'~%G &M   	g77''.(9'G))+IK	!&I$1i0 "' 6 D ##I..!-""3uQx=1MM)$- 2 	s6{"CK'		/2 	 	
 88E?W	 ''//"'E.D!%!>>%EE  $.fj#A#A&+kk$I'" !" $(77#4#4 0/$D ,077>> 0/,L  ,{:,>	,@	% & $ 3 3 ( 2 2 & % $ $^^,<==%~~h77/2/1(,(9(9 0,)I !GGMM!=?B6{!K + & $ 3 3 ( 2 2 & % ) #(++!C# a )j GGKK-$&.llY&>',y'8	    '.DGGO*c&k5::f;M-NNg& tyy~~.HHX] )v ! GGKK-!&.llY&>',y'8	     '.DGGO HHXsJ   /S: R) E9R4R) A6S: 
R&"R) )8S!!S$ $S77S: :Tc                   UR                  5       S S nU(       d)  [        R                  " [        S5      [        S5      5      e[	        U5      nUR                  U5      n[        U5      U:w  a7  [        R                  " [        S5      [        S5      [        U5      U4-  5      eU R                  R                  U[        U5      [        R                  " U5      5        g )Nr   s    error downloading file contents:s   connection closed earlys   only received %s of %s bytes)r   r   ResponseErrorr   r.   readr   r   addremotefilelognoder   zlib
decompress)r:   r   filenamer3   linesizer2   s          r   r   fileserverclient.receivemissing  s    }}s#%%56,-  4yyyt9%%5612c$i5FF 
 	++c$i!6	
r!   c                    U R                   (       aA  SU R                   U R                  R                  4-  nU R                  R	                  U5        g  " S S5      nU" 5       U l        g )Ns   %s %sc                  0    \ rS rSrS rS rSS jrS rSrg)	-fileserverclient.connect.<locals>.simplecachei  c                     / U l         SU l        g )NT)
missingidsrx   ry   s    r   rz   6fileserverclient.connect.<locals>.simplecache.__init__  s    &(DO%)DNr!   c                    g r#   rc   ry   s    r   r   3fileserverclient.connect.<locals>.simplecache.close  s    r!   c                    UR                  S5      nUS   S:w  a  g USS U l        U R                  R                  S5        g )Nr?   r   s   getr   r   r   )r-   r  rL   )r:   valuer   liness       r   r   5fileserverclient.connect.<locals>.simplecache.request  s>    !KK.EQx6)&+AbkDOOO**40r!   c                l    [        U R                  5      S:  a  U R                  R                  S5      $ g )Nr   )r   r  popry   s    r   r   9fileserverclient.connect.<locals>.simplecache.receiveline  s+    4??+a/#22155r!   )rx   r  Nr   )	rd   re   rf   rg   rz   r   r   r   ri   rc   r!   r   simplecacher    s    *1 r!   r  )r   r   _pathr   r   )r:   cmdr  s      r   r   fileserverclient.connect  sT    d//1E1EFFC$$S)   (  +}Dr!   c           	        [         (       a  S[        [         [        [        [        [        -
  5      [        [        5      -  S-  [        4-  nU R
                  (       a  U R                  R                  U5        U R                  R                  SUR                  SS5      [        [         [        [        S-  S9  U R                  R                  (       a  U R                  R                  5         g g )NsN   %d files fetched over %d fetches - (%d misses, %0.2f%% hit ratio) over %0.2fs
g      Y@s   remotefilelog.prefetch   %s   %%i  )remotefilelogfetchedremotefilelogfetchesremotefilelogfetchmissesremotefilelogfetchtime)fetchesfetchedr   float	fetchcostr   rm   r   r   replacer   rx   r   )r:   msgs     r   r   fileserverclient.close  s    7B g+,uW~=E	C S!GGKK)D%(%,%,)4'04'7   %%""$ &r!   c                   U R                   n/ nU HN  u  pxUS:X  d%  [        U5      S:X  d  UR                  U5      (       d  M2  UR                  U[	        U5      45        MP     U R
                  n	U R                  n
U(       a:  [        R                  " UR                  6 n	[        R                  " UR                  6 n
[        5       nU(       a   UR                  U	R                  U5      5        U(       a   UR                  U
R                  U5      5        [        U VVs/ s H"  u  pXR                   R                   :X  d  M   SPM$     snn5      nU(       aO  U VVs/ s H#  u  pXR                   R                   :w  d  M   X4PM%     nnnUR"                  R%                  SU-  SS9  U(       Ga=  [&        S-  q[&        S:  ae  [&        S	:  a[  [&        S:X  aA  U R"                  R)                  S
S5      nU(       a  U R"                  R+                  US-   5        U R-                  5         [/        U5       VVs/ s H  u  pxU[1        U5      4PM     nnn[2        [        U5      -  q[4        R4                  " 5       nU R7                  U5      nU(       a+  [8        R:                  " [=        S5      [        U5      -  5      e[>        [4        R4                  " 5       U-
  -  qU RA                  U5        ggs  snnf s  snnf s  snnf )z.downloads the given file versions to the caches   .hgtags*   NsD   remotefilelog not fetching %d null revs - this is likely hiding bugss   remotefilelog-ext)r   r         r   s   fetchwarningr?   s   unable to download %d files)!r   r   shallowmatchrL   r   r   r   r   unioncontentstoreshareddatastoresr   unionmetadatastoresharedhistorystoresr   r   
getmissingnullidrm   	develwarnr(  r   r   logstacktracesortedr   r)  timer   r   r9   r   r+  _lfsprefetch)r:   r   force	fetchdatafetchhistoryr   
idstocheckr   r   r   r   r  unusednullidsffetchwarningr   s                    r   prefetchfileserverclient.prefetch7  s    yy
HD 
"r7b=((..tSWo.   NN	(($668M8MNI(;;))L U
i22:>?l55jAB $.IJjf"		8H8H2HTJI
 %/%/EA29I9I3IZ   GG57>? ,   qLG "}2b=#'77>>(/$L $\E%9:""$:@:LM:Lhd4R/:LJMs:&GIIKEj1Jkk45JG  u,,Ig&/  J0 Ns   K+
K+
K1>K13K7c                H  ^
 [         (       a%  [        U R                  R                  S5      (       d  g [         R                  R                  U R                  5      (       d  g / nU R                  R                  R                  m
U H  u  p4[        U5      nU R                  R                  U5      nUR                  U5      [        R                  -  (       d  MT  UR                  U5      n[         R                  R                  U5      nUR                  5       n	T
R!                  U	5      (       a  M  UR#                  U5        M     [%        U5      S:  aM  U R                  R                  R&                  R)                  UT
5        [+        U
4S jU 5       5      (       d   eg g )Nlfslocalblobstorer   c              3  b   >#    U  H$  nTR                  UR                  5       5      v   M&     g 7fr#   )hasoid).0pstores     r   	<genexpr>0fileserverclient._lfsprefetch.<locals>.<genexpr>  s#     <8auyy))8s   ,/)_lfsmodrH   r   svfswrappercandownloadrJ  r   r   flagsr	   REVIDX_EXTSTOREDrawdatapointerdeserializerM  rL  rL   r   lfsremoteblobstore	readbatchall)r:   r   pointersr   r   r3   rlogtextrO  rM  rP  s             @r   r>  fileserverclient._lfsprefetch  s#   wgdiinn6IJJ**49955		00HDr7D99>>$'Dzz$&"9"999||D)OO//5eegyy~~OOA&   x=1IINN--77%H<8<<<<< r!   c           	         SS K nU R                  R                  SSSR                  S UR	                  5        5       5      5        g )Nr   r   s"   excess remotefilelog fetching:
%s
r!   c              3  N   #    U  H  n[         R                  " U5      v   M     g 7fr#   )r   sysbytes)rN  ss     r   rQ  1fileserverclient.logstacktrace.<locals>.<genexpr>  s      L3KaX&&q))3Ks   #%)	tracebackrm   r   r   format_stack)r:   rh  s     r   r;  fileserverclient.logstacktrace  s6    3HHL93I3I3KLL	
r!   )
r   r   r   r   r   r   r   rm   r   r   N)FTF)rd   re   rf   rg   r   rz   r   r   r   r   r   r   rG  r>  r;  ri   rc   r!   r   r   r   0  sC    D-$)D[z
&->%6 BGI'V=(
r!   r   ))
__future__r   r   r   r   r=  r	  mercurial.i18nr   mercurial.noder   r   	mercurialr   r   r	   r
   r   r   mercurial.utilsr   r    r   r   r   	sshv1peerr   r+  r(  r)  r   rS  r    r$   ro   rq   r   r   r   r   rc   r!   r   <module>rr     s    # 	 	     # 
  
 	


B
&
P$fB BJ>@>m
 m
r!   