
    	^cf                         d dl Z 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 d dlmZ ddlmZ d Zd	 Zd
 Zd Zd Zd Zd Ze j        d             ZddZd Zd Zd ZdS )    N)_)open)error
extensionshgutilwireprotov1peerwireprotov1server)urlutil   )contextc                 x    |                      dd          }|s!t          j        t          d                    |S )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      sJ    YY66F 
k6 
 
 	
 M    c                 H     | ||          }|                     d           |S )N   getannotate)append)origrepoprotoresults       r   _capabilitiesr   -   s*    T$F
MM.!!!Mr   c                    d}| j                             ddd          }t          j        | |          5 }|rt	          | j                   }	 |                    |          s|                    ||           n`# t          $ rS |                                 	 |                    ||           n$# t          $ r |                                 Y nw xY wY nw xY w|	                                 n# |	                                 w xY w|j
        |k    r|j        |j        fD ]}t          j                            |          s"t!          |d          5 }	|	                                }
d d d            n# 1 swxY w Y   t%          | j        j        dz             }||d          }|d|t%          |
          |
fz  z  }d d d            n# 1 swxY w Y   |S )Nr   r   s   serverbuildondemandTs   rb   /s   %s %d %s)r   
configboolr   annotatecontextr   
isuptodateannotate	Exceptionrebuildcloselastnode
revmappathlinelogpathospathexistsr   readlenvfsbase)r   r   r,   r(   r   buildondemandactxr   pfcontent
vfsbaselenrelpaths                r   _getannotater9   3   sr    FG&&/ M 
	 t	,	, K 	((Fv.. 2MM&&111 # # ##MM&&1111  # # #LLNNNNN## 




 =H$$ot'78 K Kw~~a(( !U^^ 'qffhhG' ' ' ' ' ' ' ' ' ' ' ' ' ' ' !566
JKK.-7CLL'*JJJ?K K K K K K K K K K K K K K K@ Ms   G+A87C-8CB.-C.CCCCC-CC-G-DAGE2&G2E66G9E6:AGGGc                  l    dt           j        v rd S  t          j        dd          t                     d S )Nr   s   path lastnode)r
   commandswireprotocommandr9    r   r   _registerwireprotocommandr>   ^   sF    *333H&~7GHH    r   c                 b    t                       t          j        t          dt                     d S )Ns   _capabilities)r>   r   wrapfunctionr
   r   r   s    r   serveruisetuprB   f   s+    -/?OOOOOr   c                 J   i }d}t          |           dz
  }d}dx}}||k     r| ||dz            }|dk    rK|dk    r<| |dz   |dz   t          |          z            ||<   |t          |          z  }d}dx}}n |dk    rd}n|dk    r||z  }n|dk    r||z  }|dz  }||k     |S )Nr   r   r       )r/   int)payloadr   ilstatevfspathsizechs           r   _parseresponserM   n   s    F	AGqAEGd
a%%QQY;;zz")!a%!a%#d))2C*C"DwSYY!$$$$!zz
!2	Q a%%  Mr   c                 @      G  fdd|j                   }||_         d S )Nc                   6    e Zd Zej        d fd	            ZdS )#peersetup.<locals>.fastannotatepeerNc                     |                      d          s$                    t          d                     dS ||pdd}|t          fS )Nr   s*   remote peer cannot provide annotate cache
NNr   s   paths   lastnode)capablewarnr   rM   )selfr,   r(   argsr   s       r   getannotatez/peersetup.<locals>.fastannotatepeer.getannotate   sS    <<// ,HIIJJJ!z!%HODD^++r   N)__name__
__module____qualname__r	   	batchablerX   rA   s   r   fastannotatepeerrP      sA        		"	, 	, 	, 	, 	, 
#	"	, 	, 	,r   r^   	__class__)r   peerr^   s   `  r   	peersetuprb      sF    , , , , , , ,4> , , , &DNNNr   c              #     K   | j         }|                    ddd          }t          j        d| ||          }|d         }t	          j        |i |          }	 |V  |                                 d S # |                                 w xY w)Nr   s
   remotepaths   defaultr   )r   r   r   get_unique_pull_pathr   ra   r'   )r   r   
remotedestr
remotepathra   s         r   annotatepeerrh      s      	B?M:FFJ$_dB
KKA1J72r:&&D






s   A1 1Bc                 ,   |sdS |9t          |           5 }t          | |||          cddd           S # 1 swxY w Y   |i }| j        }g }|                                5 }|                    dt          |          z             |D ]A}|                    |                    d||                    |          d                     B|D ],}|	                                }	d |	
                                D             }	t          |	          D ]}
|
                    d          rd|
dz   v r|                    d	|
z             7|	|
         }|j        r'|                    d
t          |          |
fz             | j                            t           j                            |
                     |                     |
d          5 }|                    |           ddd           n# 1 swxY w Y   .	 ddd           dS # 1 swxY w Y   dS )z1download annotate cache from the server for pathsNs"   fastannotate: requesting %d files
r   rS   c                 >    i | ]\  }}t          j        |          |S r=   )r   pconvert).0r4   vs      r   
<dictcomp>zclientfetch.<locals>.<dictcomp>   s(    ;;;Aq!!1;;;r   s   fastannotate/s   /../r    s(   fastannotate: ignored malicious path %s
s%   fastannotate: writing %d bytes to %s
s   wb)rh   clientfetchr   commandexecutordebugr/   r   callcommandgetr   itemssorted
startswith	debugflagr0   makedirsr+   r,   dirnamewrite)r   pathslastnodemapra   r   resultsbatcherr4   r   rf   r,   r6   r5   s                r   ro   ro      s    |$ 	?4tUK>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	BG					 %7
7#e**DEEE 	 	ANN##"kooa.@.@AA      	% 	%FA;;;;;Aq		 % %'788 G4K= = HHDtK   D'< HHAw<<./   !!"'//$"7"7888XXdE** %aGGG$$$% % % % % % % % % % % % % % %!%		%% % % % % % % % % % % % % % % % % %sC   599!E*H	G-	!H	-G11H	4G15H		HHc                    | j                             ddd          }|dk    r|S g }|D ]c}	 t          |                     |                    |k    r|                    |           ?# t
          $ r |                    |           Y `w xY w|S )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   	configintr/   filer   r%   )r   r{   	thresholdr   r,   s        r   _filterfetchpathsr      s     !!/3JBOOIA~~F    	 499T??##y00d### 	  	  	 MM$	  Ms   ;A((B
	B
c                 :     G d d|j                   }||_         d S )Nc                       e Zd ZddZdS )(localreposetup.<locals>.fastannotaterepoNc                    t          | j                  }g }i }	 t          | |          D ]e}t          j        | |          5 }|                    |d          s|                    |           |j        ||<   d d d            n# 1 swxY w Y   f|rt          | |||           d S d S # t          $ r(}| j        
                    d|z             Y d }~d S d }~ww xY w)NF)stricts"   fastannotate: prefetch failed: %r
)r   r   r   r   r"   r#   r   r(   ro   r%   rq   )	rV   r{   ra   r   needupdatepathsr|   r,   r3   exs	            r   prefetchfastannotatez=localreposetup.<locals>.fastannotaterepo.prefetchfastannotate   sX   ((F OK
K-dE:: > >D 0t<< >#veDD >+22488804K-> > > > > > > > > > > > > > > # Jo{DIIIIIJ J K K KDrIJJJJJJJJJKs;   'B( 7B8B( B	B( B	B( (
C2CCrY   )rZ   r[   r\   r   r=   r   r   fastannotaterepor      s.        	K 	K 	K 	K 	K 	Kr   r   r_   )r   r   r   s      r   localreposetupr      sC    K K K K K4> K K K" &DNNNr   c                     t                       |                                rt          | |           t          t          j        vr&t          j                            t                     d S d S rY   )r>   localr   rb   r   wirepeersetupfuncsr   )r   r   s     r   clientreposetupr      sc    zz|| !r4    ---
$$Y///// .-r   rR   )
contextlibr+   mercurial.i18nr   mercurial.pycompatr   	mercurialr   r   r   r   r	   r
   mercurial.utilsr    r   r   r   r9   r>   rB   rM   rb   contextmanagerrh   ro   r   r   r   r=   r   r   <module>r      s       				       # # # # # #                          

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