
    6hAH                    D   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rS SKJ	r	  S SK
Jr  S SKJrJrJr  S SKJr  SSKJr  \R*                  " S	5      rSrS
r\rSrSrS
rSrSr " S S5      r " S S5      r  " S S5      r! " S S\!5      r" " S S\!5      r# " S S5      r$g)    )annotationsN)_)hex)policyutilvfs)hashutil   )shallowutilosutil   i    g?c                  2    \ rS rSrS rS rS rS rS rSr	g)	_cachebackedpacks7   c           
         [        U5      U l        [        R                  " U5      U l        S U l        [        [        [        U[        U5      5      5      5       H  nU R                  X   5        M     g N)set_packsr   lrucachedict	_lrucache	_lastpackreversedrangeminlen_movetofront)selfpacks	cachesizeis       >/usr/lib/python3/dist-packages/hgext/remotefilelog/basepack.py__init___cachebackedpacks.__init__8   sW    %j**95 %Is5z :;<Aeh' =    c                "    SU R                   U'   g )NT)r   r   packs     r"   r   _cachebackedpacks._movetofrontB   s    #tr%   c                d    U R                   b#  U R                  U R                   5        S U l         g g r   )r   r   r   s    r"   _registerlastpackusage(_cachebackedpacks._registerlastpackusageF   s*    >>%dnn-!DN &r%   c                |    U R                  5         U R                  U5        U R                  R                  U5        g r   )r,   r   r   addr'   s     r"   r/   _cachebackedpacks.addK   s.    ##% 	$r%   c              #     #    U R                  5         U R                   H  nXl        Uv   M     U R                   Vs1 s H  oiM     nnU R                  U-
   H  nXl        Uv   M     S U l        g s  snf 7fr   )r,   r   r   r   )r   r(   cachedpackss      r"   __iter___cachebackedpacks.__iter__S   sp     ##% NND!NJ # )-7t7KK+-D!NJ .
  8s   <A8A3	/A8)r   r   r   N)
__name__
__module____qualname____firstlineno__r#   r   r,   r/   r3   __static_attributes__ r%   r"   r   r   7   s    ($"
r%   r   c                  X    \ 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
)basepackstoree   d   c                   Xl         X l        SU l        / nU R                  5        H*  u  n  n U R	                  U5      nUR                  U5        M,     [        X0R                  5      U l        g ! [
         aH  n[        USS 5      [        R                  :w  a  UR                  [        S5      XG4-  5         S nAM  S nAff = f)Nr   errnos   unable to load pack %s: %s
)uipathlastrefresh_getavailablepackfilessortedgetpack	Exceptiongetattrr@   ENOENTwarnr   appendr   DEFAULTCACHESIZEr   )r   rA   rB   r   filepath__r(   exs           r"   r#   basepackstore.__init__i   s    	  $ A A CHb"||H- LL !D  'u.C.CD
  
 2w-=GGA=>(OP
s   A//
C9=B<<Cc              #    #    [        U R                  5      n[        U R                  5      n[        5       n[        R
                  " [        5      n[        R
                  " [        5      n [        R                  U R                  SS9 H  u  pgnSn	Xa* S U R                  :X  a  USU*  n	OXb* S U R                  :X  a  USU*  n	U	(       d  MD  XI==   UR                  -  ss'   XY   R                  UR                  5        X;   a>  [        R                  R                  U R                  U	5      [!        XY   5      XI   4v   M  UR#                  U	5        M     g! [$         a     gf = f7f)zFor each pack file (a index/data file combo), yields:
  (full path without extension, mtime, size)

mtime will be the mtime of the index/data file (whichever is newer)
size is the combined size of index/data file
T)statN)r   INDEXSUFFIX
PACKSUFFIXr   collectionsdefaultdictintlistr   listdirrB   st_sizerJ   st_mtimeosjoinmaxr/   FileNotFoundError)
r   indexsuffixlenpacksuffixlenidssizesmtimesfilenametyperQ   ids
             r"   _getavailablepackfiles$basepackstore._getavailablepackfiles   s;     T--.DOO,e'',((.	(.tyyt(L$O,-1A1AA!"2N?3Bno.$//A!/M>2B
 2I-IJ%%dmm4yGGLLB7
O!I  ) )M* ! 		s2   A)E*,AE BE E*
E'$E*&E''E*c              #     #    / nU R                  5        H  u  p#nUR                  X4U45        M     [        USS9nU H  u  p4nX#U4v   M     g7f)zLike `_getavailablepackfiles`, but also sorts the files by mtime,
yielding newest files first.

This is desirable, since it is more likely newer packfiles have more
desirable data.
T)reverseN)rg   rJ   sorted)r   filesrB   mtimesizes        r"   rD   *basepackstore._getavailablepackfilessorted   s[      !%!<!<!>DLL%t,- "?ud+!&Et## "'s   AAc                V    SnSnU R                  5        H  u    p4X-  nUS-  nM     X4$ )a$  Returns the total disk size (in bytes) of all the pack files in
this store, and the count of pack files.

(This might be smaller than the total size of the ``self.path``
directory, since this only considers fuly-writen pack files, and not
temporary files or other detritus on the directory.)
r   r
   )rg   )r   	totalsizecountrM   rn   s        r"   gettotalsizeandcount"basepackstore.gettotalsizeandcount   sA     	 779LBIQJE : r%   c                0    U R                  5       u  pUUS.$ )z+Returns metrics on the state of this store.)s   numpackss   totalpacksize)rs   )r   rn   rr   s      r"   
getmetricsbasepackstore.getmetrics   s"    //1"
 	
r%   c                    [        5       er   NotImplementedError)r   rB   s     r"   rE   basepackstore.getpack       !##r%   c                    UnU R                    H  nUR                  U5      nU(       a  M  Us  $    U(       a(  U R                  5        H  nUR                  U5      nM     U$ r   )r   
getmissingrefresh)r   keysmissingr(   s       r"   r~   basepackstore.getmissing   sY    JJDoog.G 7  //'2 ' r%   Nc                L    U R                    H  nUR                  U5        M     g r   )r   
markledger)r   ledgeroptionsr(   s       r"   r   basepackstore.markledger   s    JJDOOF# r%   c                    SU l         g)zvTells the store that there may be new pack files, so the next time it
has a lookup miss it should check for new files.r   N)rC   r+   s    r"   markforrefreshbasepackstore.markforrefresh   s     r%   c                ~   [         R                   " 5       n/ nXR                  [        -   :  a  Xl        U R                   Vs1 s H  o3R                  iM     nnU R                  5        HK  u  n  nXT;  d  M  U R                  U5      nUR                  U5        U R                  R                  U5        MM     U$ s  snf )zlChecks for any new packs on disk, adds them to the main pack list,
and returns a list of just the new packs.)	timerC   REFRESHRATEr   rB   rD   rE   rJ   r/   )r   nownewpacksppreviousrL   rM   newpacks           r"   r   basepackstore.refresh   s     iik !!K//"(,

3
1
H3$($E$E$G "b+"ll84GOOG,JJNN7+	 %H  4s   B:)rC   r   rB   rA   r   )r5   r6   r7   r8   rK   r#   rg   rD   rs   rv   rE   r~   r   r   r   r9   r:   r%   r"   r<   r<   e   s<    E6$L$ 
$ $
r%   r<   c                  $    \ rS rSrSrS/rS rSrg)versionmixini  Nr   c                    XR                   ;   a3  U R                  c  Xl        g U R                  U:w  a  [        SU-  5      eg [        SU-  5      e)Ns   inconsistent version: %ds   unsupported version: %d)SUPPORTED_VERSIONSVERSIONRuntimeError)r   versions     r"   _checkversionversionmixin._checkversion  sR    ---||#&("#>#HII ) 9GCDDr%   )r   )r5   r6   r7   r8   r   r   r   r9   r:   r%   r"   r   r     s    GEr%   r   c                      \ rS rSrSrS/rS r\R                  S 5       r	\R                  S 5       r
S rS rSS
 jrS rS rS rSrg	)basepacki  i  @r   c                   Xl         XR                  -   U l        XR                  -   U l        [
        R                  " U R                  5      R                  U l        [
        R                  " U R                  5      R                  U l	        S U l
        S U l        U R                  5         [        R                  " SU R                  S [         5      S   nU R!                  U5        [        R                  " SU R                  S ["         5      u  p#U R!                  U5        SU-  (       a  [%        [&        U5      U l        g [%        [*        U5      U l        g )N   !Br      !BB   )rB   rS   packpathrR   	indexpathr[   rQ   rY   	indexsizedatasize_index_data
freememorystructunpackPACKVERSIONSIZEr   INDEXVERSIONSIZEindexparamsLARGEFANOUTPREFIXparamsSMALLFANOUTPREFIX)r   rB   r   configs       r"   r#   basepack.__init__  s    	. 0 00088.66
--tzz2B?'CDQG7# --<M=M0NO7#%&7ADK%&7ADKr%   c                   U R                   nU R                  [        [        UR                  -    n/ n[	        SUR
                  5       H8  nUS-  n[        R                  " SX%US-    5      S   nUR                  U5        M:     U$ )Nr         !I)	r   r   FANOUTSTART
fanoutsizer   fanoutcountr   r   rJ   )r   r   	rawfanoutfanouttabler!   locfanoutentrys          r"   _fanouttablebasepack._fanouttable0  s    KKkF<M<M.MN	q&,,-Aa%C --ysQw/GHKK{+ . r%   c                    [         R                  " SU R                  U R                  R                  S-
  5      S   nU R                  R                  XR
                  -  -   $ )N   !Q   r   )r   unpack_fromr   r   
indexstartINDEXENTRYLENGTH)r   	nodecounts     r"   	_indexendbasepack._indexend;  sT    &&4;; 6 6 :

	 {{%%	4I4I(IIIr%   c                n   U R                   (       aO  U R                  U R                  :  a  gU R                   R                  5         U R                  R                  5         [        U R                  S5       n[        R                  " UR                  5       S[        R                  S9U l         SSS5        [        U R                  S5       n[        R                  " UR                  5       S[        R                  S9U l        SSS5        SU l        g! , (       d  f       Nl= f! , (       d  f       N'= f)zUnmap and remap the memory to free it up after known expensive
operations. Return True if self._data and self._index were reloaded.
Frbr   )accessNT)r   _pagedin
MAXPAGEDINcloser   openr   mmapfilenoACCESS_READr   )r   indexfpdatafps      r"   r   basepack.freememoryB  s     ;;}}t.KKJJ $..$'7)) !D,<,<DK (
 $--&&6==?Ad>N>NODJ '  ('
 '&s   78D8D&
D#&
D4c                    [        5       er   ry   )r   r   s     r"   r~   basepack.getmissingY  r|   r%   Nc                    [        5       er   ry   )r   r   r   s      r"   r   basepack.markledger\  r|   r%   c                    [        5       er   ry   )r   r   s     r"   cleanupbasepack.cleanup_  r|   r%   c                    [        5       er   ry   r+   s    r"   r3   basepack.__iter__b  r|   r%   c                    [        5       er   ry   r+   s    r"   iterentriesbasepack.iterentriese  r|   r%   )	r   r   r   r   r   r   r   r   rB   r   )r5   r6   r7   r8   r   r   r#   r   propertycacher   r   r   r~   r   r   r3   r   r9   r:   r%   r"   r   r     sk     JB. 
  
J J.$$$$$r%   r   c                  X    \ rS rSrSS jrS rS rS rS rSS jr	S	 r
S
 rS rS rSrg)mutablebasepackii  c                >   U R                  U5        SU l        [        R                  " U5      nSUl        X@l        0 U l        [        R                  " X5        UR                  U R                  S-   S9u  U l        U l        UR                  U R                  S-   S9u  U l        U l        [         R"                  " U R                  S5      U l        [         R"                  " U R                  S5      U l        [$        R&                  " 5       U l        SU l        UR-                  UR/                  U R                  5      5        UR-                  UR/                  U R                  5      5        [0        R2                  " SU R4                  5      nU R7                  U5        g )Ns   GZi$  s   -tmp)suffixzwb+Fr   )r   _compressorvfsmodr   
createmodeopenerentriesr   mkstickygroupdirmkstemprS   packfpr   rR   idxfpidxpathr[   fdopenr	   sha1sha_closed_fixfilemoder\   r   r(   r   writeraw)r   rA   packdirr   r   
versionbufs         r"   r#   mutablebasepack.__init__j  s8   7# G$!$$R1%+^^??W, &4 &
"T] $*>>##g- $2 $
 
DL iiU3YYtzz51
==?
 	FKK67FKK56
 [[5
j!r%   c                    U $ r   r:   r+   s    r"   	__enter__mutablebasepack.__enter__  s    r%   c                L    Uc  U R                  5         g U R                  5         g r   )r   abort)r   exc_type	exc_value	tracebacks       r"   __exit__mutablebasepack.__exit__  s    JJLJJLr%   c                $    U R                  5         g r   )_cleantemppacksr+   s    r"   r   mutablebasepack.abort  s    r%   c                p    U R                   R                  U5        U R                  R                  U5        g r   )r   writer   update)r   datas     r"   r   mutablebasepack.writeraw  s$    $r%   Nc                >   U R                   (       a  g  [        U R                  R                  5       5      nU R                  R                  5         U R                  5         [        U R                  5      S:X  a  U R                  5         SU l         g U R                  R                  U R                  X R                  -   5         U R                  R                  U R                  X R                  -   5        SU l         U R                  R%                  U5      nU(       a  UR'                  U5        U$ ! [          a@  n U R                  R#                  X R                  -   5        Ue! [          a     Uef = fS nAff = f! [          a    U R                  5         e f = f)Nr   T)r   r   r   digestr   r   
writeindexr   r   r  r   renamer   rS   r   rR   rF   unlinkr\   
addcreated)r   r   r   rN   results        r"   r   mutablebasepack.close  sO   <<	dhhoo'(CKKOO4<< A%$$&#KKt}}cOO.CD	""4<<7G7G1GH !!#&f%#  KK&&s__'<=
 	 !  	  	  "	sN   A=F  2F  2D3 3
E=>'E'%E8'
E51E84E55E88E==F   Fc                     U R                   R                  U R                  5         U R                   R                  U R                  5        g ! [         a     N3f = f! [         a     g f = fr   )r   r  r   rF   r   r+   s    r"   r  mutablebasepack._cleantemppacks  s_    	KKt}}-	KKt||,  		  		s"   %A %A 
AA
A+*A+c                   [        U R                  5      [        :  nU(       a  [        [        U R
                  5      nO[        [        U R
                  5      n[        /UR                  -  n0 nSn[        U R                  5       H]  nXPR                  -  nXtU'   US-  n[        R                  " UR                  US UR                   5      S   nX8   [        :X  d  MY  XsU'   M_     Sn	Sn
U H-  nU[        :w  a  UOU
nUn
U	[        R                  " SU5      -  n	M/     [        R                  " S[        U R                  5      5      nU R!                  US[        U	5      -   5      nU R#                  U5        U R$                  R'                  U	5        U R$                  R'                  U5        U R$                  R'                  U5        U R$                  R)                  5         g )Nr   r
   r%   r   r   r   )r   r   SMALLFANOUTCUTOFFr   r   r   r   EMPTYFANOUTr   rk   r   r   r   fanoutstructfanoutprefixr(   createindex_writeheaderr   r  r   )r   largefanoutr   r   	locationsrr   nodelocation	fanoutkeyrawfanouttablelastoffsetrawentrieslengthrawindexs                 r"   r  mutablebasepack.writeindex  s   $,,'*;; !2DLLAF !2DLLAF"mf&8&88 	4<<(D444H&dOQJE ##T*?F,?,?%@I %4)1I& ) !F%4V$FDfkk%88N "
 ";;uc$,,.?@ ##Iq3~3F/FG&!

(

)*

"

r%   c                    [        5       er   ry   )r   nodelocationsindexoffsets      r"   r  mutablebasepack.createindex  r|   r%   c                    SnUR                   [        :X  a  SnU R                  R                  [        R
                  " SU R                  U5      5        g )Nr   r   r   )r  r   r   r  r   r(   r   )r   r   r   s      r"   r  mutablebasepack._writeheader  s@    
 ##'88F

VT\\6BCr%   )	r   r   r   r   r   r   r   r   r   )r   r   )r5   r6   r7   r8   r#   r   r  r   r   r   r  r  r  r  r9   r:   r%   r"   r   r   i  s8     "D#J)V$Dr%   r   c                      \ rS rSrSrS rSrg)r   i  )r  r  r   r   r   c                   Xl         U[        :X  a  SU l        O U[        :X  a  SU l        O[	        SU-  5      eSUS-  -  U l        U R
                  S-  U l        [        U R                  -   U l        U =R                  S-  sl        g )Nr   s   !Hs   invalid fanout prefix size: %sr   r   r   )	r  r   r  r   
ValueErrorr   r   r   r   )r   
prefixsizer   s      r"   r#   indexparams.__init__  s    &
 ** %D,, %D>KLL a0 **Q.%71r%   )r   r  r   r  r   N)r5   r6   r7   r8   	__slots__r#   r9   r:   r%   r"   r   r     s    Ir%   r   )%
__future__r   rT   r@   r   r[   r   r   mercurial.i18nr   mercurial.noder   	mercurialr   r   r   r   mercurial.utilsr	    r   	importmodr   r   r   r   r  r   r   r  r   r   r<   r   r   r   r   r:   r%   r"   <module>r;     s    "    	     
 % 			(	#
   
     
 + +\Z ZzE E T$| T$nYDl YDx r%   