
    6hp;                       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
  S SKJrJrJrJr  S SKJrJrJr  SSKJr  \R,                  (       d  S SKrS	 rS
 rS rS.S jrS rS rS/S jrS rS r S r!S r"S r#S r$\RJ                  \&\&4\RN                  \&\&40r(S r)S r*S r+S r, " S S\RZ                  5      r.S r/S0S jr0S r1S r2S  r3S! r4S.S" jr5S# r6S$ r7S% r8S& r9S' r:S( r;S) r<S0S* jr=S+ r>S, r?S- r@g)1    )annotationsN)_)hex)errorpycompatrevlogutil)hashutilstorageutil
stringutil   )	constantsc                <    [         R                  U R                  ;   $ )z>returns whether the repository is remotefilelog enabled or not)r   SHALLOWREPO_REQUIREMENTrequirements)repos    A/usr/lib/python3/dist-packages/hgext/remotefilelog/shallowutil.py	isenabledr   #   s    ,,0A0AAA    c                    [        [        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       r   getcachekeyr"   (   sA    8==&--/0H77<<2A,bAAr   c                    [        [        R                  " U 5      R                  5       5      n[        R
                  R                  X!5      $ Nr   )r   r    r!   s      r   getlocalkeyr%   -   s1    8==&--/0H77<<%%r   c                    U R                  SS5      nU(       d'  U(       a  g [        R                  " [        S5      5      e[        R
                  " U5      $ )N   remotefilelogs	   cachepaths4   could not find config option remotefilelog.cachepath)configr   Abortr   r	   
expandpath)ui
allowempty	cachepaths      r   getcachepathr.   2   sG    		*L9I++IJ  ??9%%r   c                    [        U R                  5      nU[        R                  :w  a+  [        R
                  R                  X R                  SU5      $ [        R
                  R                  X R                  S5      $ Ns   packs)r.   r+   r   FILEPACK_CATEGORYr   r   r   name)r   categoryr-   s      r   getcachepackpathr4   >   sR    TWW%I9...ww||Iyy(HEEww||Iyy(;;r   c                D    [         R                  R                  U SU5      $ r0   )r   r   r   )baser3   s     r   getlocalpackpathr7   F   s    77<<h11r   c                    0 nU(       d  U R                  S5      (       a%  U(       a  XS'   X#S'   [        R                  " X05      n U $ )zJreturns a string that matches the revlog contents in a
traditional revlog
   
s   copys   copyrev)
startswithr   packmeta)textcopyfromcopyrevmetas       r   createrevlogtextr@   J   sA     D4??7++$M&##D/Kr   c                    [         R                  " U 5      u  pU R                  S5      (       a  U R                  SS5      nXS-   S n U=(       d    0 U 4$ )z parse mercurial filelog metadatar9   r   N)r   	parsemetar:   index)r<   r?   sizess       r   rB   rB   X   sO    &&t,JDwJJw"EG}:2tr   c                     [         R                  " [        5      nU  H(  nUR                  5        H  u  p4X==   U-  ss'   M     M*     U$ )zAdds all the values of *dicts together into one dictionary. This assumes
the values in *dicts are all summable.

e.g. [{'a': 4', 'b': 2}, {'b': 3, 'c': 1}] -> {'a': 4, 'b': 5, 'c': 1}
)collectionsdefaultdictintitems)dictsresultdictkvs        r   sumdictsrP   a   sB     $$S)FJJLDAINI !  Mr   c                H    0 nU R                  5        H  u  p4XBX-   '   M     U$ )z;Returns ``dict`` with ``prefix`` prepended to all its keys.)rJ   )rM   prefixrL   rN   rO   s        r   
prefixkeysrS   n   s(    F

vz Mr   c                    U Vs/ s H  o3R                  5       PM     nn[        [        U6 US-   5      nU R                  " US-   S40 [        R
                  " U5      D6  g s  snf )N   _s
   _packsizes   
)
getmetricsrS   rP   logr   	strkwargs)r+   rR   storesrE   rK   rM   s         r   reportpackmetricsr[   v   sW    %+,V\\^VE,h&6DFF6M!5EH,>,>t,DE -s   A!c                    0 nSn[        U 5      nX2-
  S:  aV  XUS-    nUS-  n[        R                  " SX5      S   nUS-  nX%-   U:  a  [        S5      eXX%-    nXaU'   X%-  nX2-
  S:  a  MV  X#:w  a  [        S5      eU$ )a  parse datapack meta, bytes (<metadata-list>) -> dict

The dict contains raw content - both keys and values are strings.
Upper-level business may want to convert some of them to other types like
integers, on their own.

raise ValueError if the data is corrupted
r      r      !Hr   s%   corrupted metadata: incomplete buffers"   corrupted metadata: redundant data)lenstructunpack_from
ValueError)metabufmetadictoffsetbuflenkeymetalenvalues          r   _parsepackmetarj   |   s     HF\F
/Q
vz*!$$UG<Q?!f$EFF!12 /Q
 >??Or   c                R   Sn[        U =(       d    0 R                  5       5       H~  u  p#[        U5      S:w  a  [        R                  " SU-  5      e[        U5      S:  a  [        S[        U5      -  5      eX-  nU[        R                  " S[        U5      5      -  nX-  nM     U$ )aV  reverse of _parsepackmeta, dict -> bytes (<metadata-list>)

The dict contains raw content - both keys and values are strings.
Upper-level business may want to serialize some of other types (like
integers) to strings before calling this function.

raise ProgrammingError when metadata key is illegal, or ValueError if
length limit is exceeded
r   r   s   packmeta: illegal key: %si  s)   metadata value is too long: 0x%x > 0xfffer^   )sortedrJ   r_   r   ProgrammingErrorrb   r`   pack)rd   rc   rN   rO   s       r   _buildpackmetaro      s     GB--/0q6Q;(()E)IJJq6F?<s1vE  	6;;uc!f-- 1 Nr   c                R   0 nU =(       d    0 R                  5        H~  u  p#[        R                  U[        45      n[	        X45      (       d  [
        R                  " SU-  5      e[        U;   a'  U[        R                  :X  a  US:X  a  Mo  [        U5      nX1U'   M     [        U5      $ )zlike _buildpackmeta, but typechecks metadict and normalize it.

This means, METAKEYSIZE and METAKEYSIZE should have integers as values,
and METAKEYFLAG will be dropped if its value is 0.
s   packmeta: wrong type of key %sr   )rJ   _metaitemtypesgetbytes
isinstancer   rm   rI   r   METAKEYFLAGint2binro   )rd   newmetarN   rO   expectedtypes        r   buildpackmetary      s     GR&&(%))!eX6!**(()JQ)NOO,I)))a1f
A
 ) '""r   c                    [        U 5      nUR                  5        H1  u  p#U[        ;   d  M  [        [        U   ;   d  M$  [	        U5      X'   M3     U$ )zlike _parsepackmeta, but convert fields to desired types automatically.

This means, METAKEYFLAG and METAKEYSIZE fields will be converted to
integers.
)rj   rJ   rq   rI   bin2int)rc   rd   rN   rO   s       r   parsepackmetar|      sG     g&H 3.*;#;!!*HK ! Or   c                |    [        5       nU S:  a"  UR                  SU S-  5        U S-  n U S:  a  M"  [        U5      $ )z3convert a non-negative integer to raw binary bufferr         )	bytearrayinsertrs   )nbufs     r   rv   rv      s@    
+C
a%

1a$h	a a% :r   c                @    Sn[        U 5       H  nUS-  nX-  nM     U$ )z=the reverse of int2bin, convert a binary buffer to an integerr   r   )r   )r   xbs      r   r{   r{      s,    	As^	a	  Hr   c                      \ rS rSrSrSrg)BadRemotefilelogHeader   z@Exception raised when parsing a remotefilelog blob header fails. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r      s    Jr   r   c                   [         R                  nSn U R                  S5      nU SU nUR                  S5      (       a  UR                  S5      (       a  UR                  S5       H  nUR                  [        R                  5      (       a'  [        U[        [        R                  5      S 5      nMN  UR                  [        R                  5      (       d  Mt  [        U[        [        R                  5      S 5      nM     O[	        SU-  5      e[        U5      nUc  [	        S5      eUS	-   X!4$ ! [         a    [	        S5      ef = f)
zgiven a remotefilelog blob, return (headersize, rawtextsize, flags)

see remotefilelogserver.createfileblob for the format.
raise RuntimeError if the content is illformed.
N    s/   unexpected remotefilelog header: illegal format   vs   v1
rV   s$   unsupported remotefilelog header: %ss.   unexpected remotefilelog header: no size foundr   )r   REVIDX_DEFAULT_FLAGSrC   rb   r   r:   splitr   METAKEYSIZErI   r_   ru   )rawflagsrD   rC   headerrE   s         r   parsesizeflagsr      s6    ''ED
		% 
 %[FW%%\\%(<<	 5 566qY%:%:!;!=>?D\\)"7"788#i&;&;"<"> ?@E	 ) )7&@ 
 6{|$=
 	
 19d!!1  
$>
 	

s   D3 3E	c                   Uc  [        [        U5      5      nUS:X  a'  S[        R                  U [        R                  U4-  nU$ US:X  a$  U(       a  [
        R                  " S5      eSU -  nU$ [
        R                  " SU-  5      e)zreturn the header of a remotefilelog blob.

see remotefilelogserver.createfileblob for the format.
approximately the reverse of parsesizeflags.

version could be 0 or 1, or None (auto decide).
r   s   v1
%s%d
%s%dr   s!   fileblob v0 does not support flags   %ds   unknown fileblob version %d)rI   boolr   r   ru   r   rm   )rD   r   versionr   s       r   buildfileblobheaderr     s     d5k"!|"!!!!	&
 
 M 
A(()MNN M $$%Cg%MNNr   c                   [        U 5      u  pnX-   n0 nU[        U 5      :  a]  U R                  SUS-   5      nXUS-    nXS-   US-    nXS-   US-    n	XS-   US-    n
XS-   U nXX4XW'   US-   nU[        U 5      :  a  M]  U$ )Nr   P      (   <   r   )r   r_   rC   )r   re   rD   r   startmappingdividercurrentnodep1p2linknoder=   s               r   ancestormapr   /  s    (-F%MEG
#c(
))E52:.52:/"*-"*-
urz3
g. ";! #c(
 Nr   c                    [         R                  " U 5      nU(       d$  [        R                  " U 5        [	        SU -  5      eU$ )Ns   empty file: %s)r	   readfiler   removeOSError)r   rL   s     r   r   r   C  s6    ]]4 F 
		$'$.//Mr   c                    [         R                  (       a%  [        R                  " U [        R
                  5        [        R                  " U 5        g r$   )r   	iswindowsr   chmodstatS_IWUSRunlink)filepaths    r   
unlinkfiler   N  s)    
4<<(IIhr   c                b   [         R                  (       a  [        R                  " U [        R
                  5        [        R                  R                  U5      (       a;  [        R                  " U[        R
                  5        [        R                  " U5        [        R                  " X5        g r$   )
r   r   r   r   r   r   r   isfiler   rename)sourcedestinations     r   
renamefiler   U  s\     	&77>>+&&HH[$,,/IIk"IIf"r   c                   [         R                  R                  U 5      u  p4[         R                  R                  U5      (       d   [         R                  " U5        [        R                  " SU-  US9u  pV[         R                  " U5         [        R                  " US5      nUR                  U5        UR                  5         U(       a  SnO/[         R                  " S5      n	[         R                  " U	5        U	) n[        X`5        [         R                  " X5        g ! [
         a     Nf = f! [         a     [!        U5        e ! ["         a     e f = ff = f)Ns   .%s-)rR   dirs   wbi$  r   )r   r   r   existsmakedirsFileExistsErrortempfilemkstempcloser	   	posixfilewriteumaskr   r   	Exceptionr   r   )
r   contentreadonlydirnamefilenamefdtempfmodeoldumasks
             r   	writefiler   a  s   d+G77>>'""	KK  w'9wGHBHHRLNN4'			D xx{H HHX9D4
/  		0  	t 	  		sC   D! BD1 !
D.-D.1
E<EE
EEEEc                P   [        U 5      n 0 n0 n/ nU  H{  nU" U5       Vs/ s H  ofU ;   d  M
  UPM     nn[        U5      X5'   U H,  nUR                  U[        5       5      R                  U5        M.     U(       a  Mj  UR                  U5        M}     UR	                  5         / nU(       au  UR                  S5      nUR                  U5        XR;   aE  X%   n	U	 H;  n
X:   nUR                  U5        [        U5      S:X  d  M)  UR                  SU
5        M=     U(       a  Mu  U$ s  snf )zQTopologically sorts the nodes, using the parentfunc to find
the parents of nodes.r   )	set
setdefaultaddappendsortpopr   r_   r   )nodes
parentfuncchildmap	parentmaprootsr   pparentsresultschildrencchildparentss               r   	sortnodesr     s    JEHIE (m:mEz1m:7|	A35)--a0 wLLO  
JJLG
IIaLq={H(|##A&|$) LLA&  % N1 ;s
   	D#D#c                    U R                  U5      n[        U5      U:  a-  [        R                  " [	        S5      [        U5      U4-  5      eU$ )z=read n bytes from stream.read and abort if less was availables5   stream ended unexpectedly (got %d bytes, expected %d))readr_   r   r)   r   )streamr   rE   s      r   readexactlyr     sK    AA
1vzkkFG1vqk
 	
 Hr   c                n    [        U [        R                  " U5      5      n[        R                  " X5      $ r$   )r   r`   calcsizeunpack)r   fmtdatas      r   
readunpackr     s&    vvs34D==##r   c                    [        U [        R                  5      n[        R                  " [        R
                  U5      S   n[        X5      $ Nr   )r   r   FILENAMESIZEr`   r   FILENAMESTRUCT)r   rawlenpathlens      r   readpathr     s:    !7!78FmmI44f=a@Gv''r   c              #     #    [        U [        R                  5      n[        R                  " [        R
                  U5      S   n[        U5       H  n[        U [        R                  5      v   M!     g 7fr   )r   r   NODECOUNTSIZEr`   r   NODECOUNTSTRUCTrangeNODESIZE)r   r   	nodecountis       r   readnodelistr     sT     !8!89Fi77@CI9&)"4"455 s   A2A4c              #     #    [        U [        R                  5      n[        R                  " [        R
                  U5      S   n[        U5       H  n[        U 5      v   M     g 7fr   )r   r   PATHCOUNTSIZEr`   r   PATHCOUNTSTRUCTr   r   )r   r   	pathcountr   s       r   readpathlistr    sL     !8!89Fi77@CI9v s   A#A%c                     [         R                  " [        R                  " U 5      5      R                  nU$ ! [
         a     g f = fr$   )grpgetgrnamr   fsdecodegr_gidKeyError)	groupnamegids     r   getgidr    s=    ll8,,Y78??
 s   58 
AAc                    Uc  g  [         R                  " U SU5        [         R                  " U S5        g ! [         a+  nU(       a  U" [	        S5      X4-  5         S nAg  S nAg S nAff = f)N  s    unable to chown/chmod on %s: %s
)r   chownr   r   r   )r   r  warnexs       r   setstickygroupdirr    s`    
{G
r3
v G78D:EFF Gs   /6 
A+ A&&A+c                   SnU R                  SS5      nU(       a+  [        U5      nUc  U R                  [        S5      U-  5        Sn [        R
                  " U5      nU(       a:  UR                  S-  S:w  d  UR                  U:w  a  [        XU R                  5        g[        R                  " S5      n U/n[        R                  R                  U5      nU(       a  [        R                  R                  U5      (       d]  UR                  U5        [        R                  R                  U5      nU(       a&  [        R                  R                  U5      (       d  M]  [        U5       H  n [        R                   " U5        M     U H  n[        XU R                  5        M     [        R                  " U5        g! [         a     GNnf = f! ["         a     Mr  f = f! [        R                  " U5        f = f)zeCreates the given directory (if it doesn't exist) and give it a
particular group with setgid enabled.Nr'   s
   cachegroups!   unable to resolve group name: %s
r  r   )r(   r  r  r   r   r   r   st_modest_gidr  r   r   r   r   r   reversedmkdirr   )r+   r   r  r  str   missingdirss          r   mkstickygroupdirr    s    C		*M:IY;GGA;<yHI 
BWWT] 
JJF*bii3.>d1xxHfwwt$277>>$//t$77??4(D 277>>$// [)D *  Dd1   	7  * #  	sI   
G 8B(G# "G# 1G#G# 
GG
G G# G  G# #G;c                l     [         R                  " U R                  5       5      $ ! [         a     gf = f)N   unknown)r   	shortuserusernamer   )r+   s    r   getusernamer!    s0    ##BKKM22 s   #& 
33c                t    U R                  SS5      nU(       a  [        R                  R                  U5      $ g)Ns   pathss   defaultr  )r(   r   r   basename)r+   r   s     r   getreponamer$    s-    yy:.Hww))r   )F)NNr$   )A
__future__r   rG   r   r   r`   r   mercurial.i18nr   mercurial.noder   	mercurialr   r   r   r	   mercurial.utilsr
   r   r    r   r   r  r   r"   r%   r.   r4   r7   r@   rB   rP   rS   r[   rj   ro   ru   rI   r   rq   ry   r|   rv   r{   StorageErrorr   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r!  r$  r   r   r   <module>r,     s6   #  	       
 B
B
&
	&<2
F66 C:C:#*
KU// K""J6(	#"J"J$
(6G)Xr   