
    6hs                        S SK Jr  S SK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  S SKJr  SSKJr  S rS	 rS
 rS rS rS rS r\R0                  S 5       rSS jrS rS rS rg)    )annotationsN)_)error
extensionshgutilwireprotov1peerwireprotov1server)urlutil   )contextc                v    U R                  SS5      nU(       d  [        R                  " [        S5      5      eU$ )z)get the mainbranch, and enforce it is set   fastannotates
   mainbranchsF   fastannotate.mainbranch is required for both the client and the server)configr   Abortr   )uimasters     =/usr/lib/python3/dist-packages/hgext/fastannotate/protocol.py
_getmasterr      s:    YY6Fkk6
 	
 M    c                8    U " X5      nUR                  S5        U$ )N   getannotate)append)origrepoprotoresults       r   _capabilitiesr   -   s    $F
MM.!Mr   c                   SnU R                   R                  SSS5      n[        R                  " X5       nU(       aM  [	        U R                   5      n UR                  U5      (       d  UR                  Xw5        UR                  5         UR                  U:w  a  UR                  UR                  4 H  n[        R                  R                  U5      (       d  M)  [!        US5       n	U	R#                  5       n
S S S 5        [%        U R&                  R(                  S-   5      nXS  nUSU[%        W
5      U
4-  -  nM     S S S 5        U$ ! [         aG    UR                  5          UR                  Xw5         N! [         a    UR                  5           GNf = ff = f! UR                  5         f = f! , (       d  f       N= f! , (       d  f       U$ = f)Nr   r   s   serverbuildondemandTrb   /s   %s %d %s)r   
configboolr   annotatecontextr   
isuptodateannotate	Exceptionrebuildcloselastnode
revmappathlinelogpathospathexistsopenreadlenvfsbase)r   r   r-   r)   r   buildondemandactxr   pfcontent
vfsbaselenrelpaths                r   _getannotater;   3   s|    FGG&&/M 
	 	 	,(Fv..MM&1 


 ==H$oot'7'78ww~~a((!T]affhG # !56
K.-7CL'*JJJ 91 
-@ M3  ##MM&1  #LLNN## 

 #]7 
-	,@ Mss   G'E	;A-G(F29AG	F$E75F7FFFFFFF//G2
G <G
Gc                 p    S[         R                  ;   a  g [         R                  " SS5      " [        5        g )Nr   s   path lastnode)r
   commandswireprotocommandr;    r   r   _registerwireprotocommandr@   ^   s-    *333&&~7GHr   c                X    [        5         [        R                  " [        S[        5        g )Nr   )r@   r   wrapfunctionr
   r   r   s    r   serveruisetuprD   f   s    -Nr   c                   0 nSn[        U 5      S-
  nSnS=pVX#:  ai  XUS-    nUS:X  a;  US:X  a,  XS-   US-   [        U5      -    X'   U[        U5      -  nSnS=pVOUS:X  a  SnOUS:X  a  Xg-  nO
US:X  a  XW-  nUS-  nX#:  a  Mi  U$ )Nr   r   r       )r1   int)payloadr   ilstatevfspathsizechs           r   _parseresponserO   n   s    F	AGqAEG
%Q;z")a%!a%#d)2C"DSY!$$$!z
!	Q %  Mr   c                B   ^   " U 4S jSUR                   5      nX!l         g )Nc                  D   > \ rS rSr\R
                  SU 4S jj5       rSrg)#peersetup.<locals>.fastannotatepeer   Nc                   > U R                  S5      (       d  TR                  [        S5      5        gX=(       d    SS.nU[        4$ )Nr   s*   remote peer cannot provide annotate cache
NNr   s   paths   lastnode)capablewarnr   rO   )selfr-   r)   argsr   s       r   getannotate/peersetup.<locals>.fastannotatepeer.getannotate   s>    <<//HIJ!!%OD^++r   r?   N)__name__
__module____qualname____firstlineno__r	   	batchabler[   __static_attributes__rC   s   r   fastannotatepeerrR      s    		"	"	, 
#	,r   rd   	__class__)r   peerrd   s   `  r   	peersetuprh      s    ,4>> , &Nr   c              #     #    U R                   nUR                  SSS5      n[        R                  " SUU5      n[        R
                  " U0 U5      n Uv   UR                  5         g ! UR                  5         f = f7f)Nr   s
   remotepaths   default)r   r   r   get_unique_pull_path_objr   rg   r(   )r   r   
remotedest
remotepathrg   s        r   annotatepeerrm      si     	B?M:FJ11
J
 772r:&D




s   AA=A( A=(A::A=c                B   U(       d  gUc!  [        U 5       n[        XX#5      sSSS5        $ Uc  0 nU R                  n/ nUR                  5        nUR	                  S[        U5      -  5        U H5  nUR                  UR                  SXrR                  U5      S.5      5        M7     U GH,  nUR                  5       n	U	R                  5        VV
s0 s H  u  pz[        R                  " U5      U
_M     n	nn
[        U	5       H  nUR                  S5      (       a	  SUS-   ;   a  UR	                  SU-  5        M8  X   nUR                  (       a  UR	                  S	[        U5      U4-  5        U R                   R#                  [$        R&                  R)                  U5      5        U R!                  US
5       nUR+                  U5        SSS5        M     GM/     SSS5        g! , (       d  f       GN= fs  sn
nf ! , (       d  f       GM
  = f! , (       d  f       g= f)z1download annotate cache from the server for pathsNs"   fastannotate: requesting %d files
r   rV   s   fastannotate/s   /../r!   s(   fastannotate: ignored malicious path %s
s%   fastannotate: writing %d bytes to %s
s   wb)rm   clientfetchr   commandexecutordebugr1   r   callcommandgetr   itemsr   pconvertsorted
startswith	debugflagr2   makedirsr,   r-   dirnamewrite)r   pathslastnodemaprg   r   resultsbatcherr6   r   rvr-   r8   r7   s                 r   ro   ro      s   |$4tK>   	BG				7
7#e*DEANN##"ooa.@A  FA12;q!1$A;q	'788G4K= HHDtK '<<HHAw<./ !!"''//$"78XXdE*aGGG$ +*! "	  
 	  * <" +*= 
 	sC   G%BH#G7
5CH9G=	H%
G47H=
H	H
Hc                   U R                   R                  SSS5      nUS::  a  U$ / nU H5  n [        U R                  U5      5      U:  a  UR	                  U5        M5  M7     U$ ! [
         a    UR	                  U5         MY  f = f)zreturn a subset of paths whose history is long and need to fetch linelog
from the server. works with remotefilelog and non-remotefilelog repos.
r   s   clientfetchthreshold
   r   )r   	configintr1   filer   r&   )r   r|   	thresholdr   r-   s        r   _filterfetchpathsr      s     !!/3JBOIA~F	 499T?#y0d# 1  M  	 MM$	 s   /A%%BBc                :     " S SUR                   5      nX!l         g )Nc                      \ rS rSrSS jrSrg)(localreposetup.<locals>.fastannotaterepo   Nc                   [        U R                  5      n/ n0 n [        X5       HV  n[        R                  " X5       nUR                  USS9(       d  UR                  U5        UR                  XV'   S S S 5        MX     U(       a  [        XXR5        g g ! , (       d  f       M~  = f! [         a(  nU R                  R                  SU-  5         S nAg S nAff = f)NF)stricts"   fastannotate: prefetch failed: %r
)r   r   r   r   r#   r$   r   r)   ro   r&   rq   )	rY   r|   rg   r   needupdatepathsr}   r-   r5   exs	            r   prefetchfastannotate=localreposetup.<locals>.fastannotaterepo.prefetchfastannotate   s    (F OK
K-d:D 00<#veD+224804K- =< ;
 #{I #	 =<  KDrIJJKs.   $B' 5B4B' 
B$	B' '
C1CCr?   r]   )r^   r_   r`   ra   r   rc   r?   r   r   fastannotaterepor      s    	Kr   r   re   )r   r   r   s      r   localreposetupr      s    K4>> K" &Nr   c                    [        5         UR                  5       (       a  [        X5        [        [        R
                  ;  a$  [        R
                  R                  [        5        g g r]   )r@   localr   rh   r   wirepeersetupfuncsr   )r   r   s     r   clientreposetupr      sD    zz||r  ---
$$Y/ .r   rU   )
__future__r   
contextlibr,   mercurial.i18nr   	mercurialr   r   r   r   r	   r
   mercurial.utilsr    r   r   r   r;   r@   rD   rO   rh   contextmanagerrm   ro   r   r   r   r?   r   r   <module>r      s{    #  	   

 (VO2&  "-%`&&*0r   