
    6hC                       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
  SSKJr  \R                  r\R                  r\R                  rSrS\-   rS	\-   rS
rS\-   rS	\-   rSr\" \5      rS\-  rSrSrSrSr " S S5      r " S S5      rg)    )annotationsN   )nullrev)encodingerrorpycompatutil)
stringutils   -v2s	   rbc-namess   rbc-revss   -v1s   >4sI@      il        g?c                  X    \ rS rSrSrS r\S 5       rS rS r	S r
S rS	 rS
 rS rSrg)rbcrevs5   zLa byte string consisting of an immutable prefix followed by a mutable suffixc                .    Xl         [        5       U l        g N)_prefix	bytearray_rest)selfrevss     ?/usr/lib/python3/dist-packages/mercurial/branching/rev_cache.py__init__rbcrevs.__init__8   s    [
    c                B    [        U R                  5      nX[        -  -
  $ r   )lenr   _rbcrecsize)r   sizes     r   
len_prefixrbcrevs.len_prefix<   s    4<< k)**r   c                F    U R                   [        U R                  5      -   $ r   )r   r   r   r   s    r   __len__rbcrevs.__len__A   s    TZZ00r   c                    XR                   :  a/  [        [        [        R                  " U R
                  5      U5      $ [        [        [        R                  " U R                  5      XR                   -
  5      $ r   )r   unpack_from
_rbcrecfmtr	   bufferr   r   )r   	rbcrevidxs     r   unpack_recordrbcrevs.unpack_recordD   sR    &z4;;t||+DiPPDJJ'OO+ r   c                    U R                   S:  aW  [        5       nU R                  S U R                    US S & UR                  U R                  5        Xl        [        5       U l        g g )Nr   )r   r   r   extendr   )r   entiretys     r   make_mutablerbcrevs.make_mutableN   sQ    ??Q {H,,'89HQKOODJJ'!J$;DL r   c                B    U R                  5         U R                  US 2	 g r   )r/   r   )r   poss     r   truncaterbcrevs.truncateV   s    JJstr   c                   XR                   :  a  U R                  5         U R                  nXR                   -
  nU[        -   n[	        U R                  5      U:  a  U R                  R                  SU-  5        [        [        UUUU5      $ )N    )r   r/   r   r   r   r-   	pack_intor'   )r   r)   node	branchidxbufstart_offset
end_offsets          r   r7   rbcrevs.pack_intoZ   s|    &jj ??2!K/
tzz?Z' JJej01
 	
r   c                8    U R                   R                  U5      $ r   )r   r-   )r   	extensions     r   r-   rbcrevs.extendp   s    zz  ++r   c                <   XR                   :  ag  [        5       nU R                  U[        X R                   5       US S & UR	                  U R
                  XR                   -
  X R                   -
   5        U$ U R
                  XR                   -
  X R                   -
   $ r   )r   r   r   minr-   r   )r   beginendaccs       r   slicerbcrevs.slices   s~    ??"+C\\%#c??*CDCFJJ

5??2S??5JK Jzz%//1C//4IJJr   )r   r   N)__name__
__module____qualname____firstlineno____doc__r   propertyr   r#   r*   r/   r3   r7   r-   rF   __static_attributes__ r   r   r   r   5   sB    V! + +1'
,,Kr   r   c                      \ rS rSrSrSS jrS rSS jr\R                  S 5       r
S rS rS	 rS
 rSS jrS rS rSrg)revbranchcache~   aQ  Persistent cache, mapping from revision number to branch name and close.
This is a low level cache, independent of filtering.

Branch names are stored in rbc-names in internal encoding separated by 0.
rbc-names is append-only, and each branch name is only stored once and will
thus have a unique index.

The branch info for each revision is stored in rbc-revs as constant size
records. The whole file is read into memory, but it is only 'parsed' on
demand. The file is usually append-only but will be truncated if repo
modification is detected.
The record for each revision contains the first 4 bytes of the
corresponding node hash, and the record is only used if it still matches.
Even a completely trashed rbc-revs fill thus still give the right result
while converging towards full recovery ... assuming no incorrectly matching
node hashes.
The record also contains 4 bytes where 31 bits contains the index of the
branch and the last bit indicate that it is a branch close commit.
The usage pattern for rbc-revs is thus somewhat similar to 00changelog.i
and will grow with it but be 1/8th of its size.
c                   UR                   b   eXl        / U l        [        [	        5       5      U l        SU l        SU l        Sn  UR                  R                  [        5      n[        U5      U l        U(       a;  UR                  S5       Vs/ s H  n[        R                   " U5      PM     snU l        U R                  (       a   UR&                  R)                  SS[*        R,                  (       + S9nU(       d  UR                  [
        5       nU(       aO  UR                  R/                  [
        5      (       a+  [0        R2                  " [0        R4                  " U5      5      nOUR                  5       nS S S 5        O.UR                  [6        5       nUR                  5       nS S S 5        [        W5      U l        [?        [        U R
                  5      [@        -  [        URB                  5      5      U l"        U RD                  S:X  a  / U l        [        U R                  5      U l#        g ! [         a,    UR                  R                  [        5      nSnSU l         GNf = fs  snf ! [         a    U(       a  U R"                  U l         GNf = f! , (       d  f       N= f! , (       d  f       GN= f! [         a=  n	UR&                  R9                  S[:        R<                  " U	5      -  5         S n	A	GN<S n	A	ff = f)	Nr   FTr6   s   storages   revbranchcache.mmap)defaults(   couldn't read revision branch cache: %s
)$
filtername_repo_namesr   r   _rbcrevs_rbcsnameslen_force_overwritecachevfsread	_rbcnamesOSError_rbc_legacy_namesr   splitr   tolocal_branchinfo
branchinfoui
configboolr   	iswindowsis_mmap_safer	   r(   mmapread_rbc_legacy_revsdebugr
   forcebytestrrB   r   	changelog_rbcrevslen_rbcnamescount)
r   reporeadonlyv1_fallbackbndatabnusemmapfpdatainsts
             r   r   revbranchcache.__init__   sX   &&&
	, %	3	-++I6 "%VD39<<3F3FRH$$R(3F ;;! '',,* ( 2 22 - 
 #x0B"t}}'A'A('K'K#';;t}}R/@#AD#%779D	 10 '78B!wwy 9 ' +-s4>>/B
 q DK!$++.w  -
 ++,=>"(,%-  	3"&"2"2	3* 10 98  @ --d34 s   H2 &*I0  I+0I0 
A
J< A'J;J< J**J< 22I($I0 'I((I0 0"JJ
J'#J< *
J94J< <
L2K>>Lc                   SU l         U R                  S S 2	 SU l        [        U R                  R
                  5      U l        [        [        U R                  [        -  5      5      U l
        [        R                  " U S5        SU l        g )Nr   s   _namesreverseT)rY   rW   rn   r   rV   rl   rm   r   r   r   rX   r	   clearcachedpropertyrZ   r"   s    r   _clearrevbranchcache._clear   si    KKNtzz334	$*:*:[*H IJ  '78 $r   c                T    Xl         U R                  R                  U5        SU l        g )NT)rm   rX   r3   rZ   )r   revs     r   
invalidaterevbranchcache.invalidate   s"    s# $r   c                b    [        U R                  5       VVs0 s H  u  pX!_M	     snn$ s  snnf r   )	enumeraterW   )r   rbs      r   _namesreverserevbranchcache._namesreverse   s)    !*4;;!78!7!7888s   +c                <   U R                   R                  nU[        -  nU[        :X  a  UR	                  U5      $ [        U R                  5      U[        -   :  a  U R                  U5      $ UR                  U5      S[         nU R                  R                  U5      u  pV[        U[        -  5      nU(       a	  U[        -  nUS:X  a  O~XT:X  a   U R                  U   U4$ U R                   R                   R#                  SU-  5        U[        -   nU R                  R'                  U5        [)        U R*                  U5      U l        U R                  U5      $ ! [         a8    U R                   R                   R#                  S5        U R%                  5          NRf = f)zOReturn branch name and close flag for rev, using and updating
persistent cache.Ns       sR   referenced branch names not found - rebuilding revision branch cache from scratch
sP   history modification detected - truncating revision branch cache to revision %d
)rV   rl   r   r   rc   r   rX   rb   r8   _rbcnodelenr*   bool_rbccloseflag_rbcbranchidxmaskrW   
IndexErrorrd   rj   r{   r3   rB   rm   )	r   r~   rl   r)   reponode	cachenoder9   closer3   s	            r   rc   revbranchcache.branchinfo   sy    JJ((	+%	 '>'',, t}}	K 77##C(( >>#&|4#}}::9E	Y./**I#"{{9-u44 JJMM:<?@ !;.HMM""8,"4#3#3X>D $$%  

##J s   E ?FFc                z   U R                   R                  nUR                  U5      u  p4X0R                  ;   a  U R                  U   nO>[	        U R
                  5      nU R
                  R                  U5        XPR                  U'   UR                  U5      nU(       a	  U[        -  nU R                  XU5        X44$ )z7Retrieve branch info from changelog and update _rbcrevs)
rV   rl   rc   r   r   rW   appendr8   r   _setcachedata)r   r~   rl   r   r   r9   r   s          r   rb   revbranchcache._branchinfo  s    JJ((	'',"""**1-IDKK(IKKq!$-q!>>#&&I3)4xr   c                   UR                   u  p4X0R                  ;   a  U R                  U   nO>[        U R                  5      nU R                  R	                  U5        XPR                  U'   U(       a	  U[
        -  nU R                  XR                  R                  R                  U5      U5        S[        U 5      ;   a  U ? gg)z%add new data information to the cacherc   N)rc   r   r   rW   r   r   r   rV   rl   r8   vars)r   r~   changelogrevisionbranchr   r9   s         r   setdatarevbranchcache.setdata-  s    )44'''**62IDKK(IKKv&)2v&&I3

 4 4 9 9# >	J 4:% &r   c                   U[         :X  a  gU[        -  nU R                  R                  XBU5        [	        U R
                  U5      U l        U R                  R                  5       nU(       a  UR                  SU R                  5        gg)z:Writes the node's branch data to the in-memory cache data.Ns   write-revbranchcache)
r   r   rX   r7   rB   rm   rV   currenttransactionaddfinalizewrite)r   r~   r8   r9   r)   trs         r   r   revbranchcache._setcachedataC  sl    '>+%		;t//5ZZ**,NN2DJJ? r   Nc                   U R                   nSnSn U R                  (       d#  U R                  [        U R                  5      :  a"  UR                  SS9nSnU R                  U5        U R                  [        -  nU R                  (       d  U[        U R                  5      :w  a%  SnUc  UR                  SS9nU R                  X%5        Ub  UR'                  5         gg! [        [        R                  [        R                  4 a>  nUR                  R!                  SU["        R$                  " U5      4-  5         SnANwSnAff = f! Ub  UR'                  5         f f = f)z!Save branch cache if it is dirty.Nr   F)waits    namess+   couldn't write revision branch cache%s: %s
)rV   rZ   rn   r   rW   wlock_writenamesrm   r   rX   
_writerevsr^   r   Abort	LockErrorrd   rj   r
   rk   release)r   r   ro   r   stepstartrw   s          r   r   revbranchcache.writeO  s+   zz	 $$(;(;c$++>N(N


.   & $${2E$$T]]1C(C= JJEJ2E,   ! eoo6 	GGMM?00678 	   !s*   B8C )E4E<E	 EE	 	Ec                  ^ SnU R                   (       a  SU l        SU l         U R                   (       d  U R                  S:w  a  UR                  R	                  [
        S5      nUR                  5       nX0R                  :X  a  UR                  S5        O_UR                  5         U R                   (       a  SnOUS:  a  SnOSnUR                  R                  U[
        -  5        SU l        SU l        U R                  S:X  a>  UR                  R                  [        SS	9  UR                  R	                  [
        S
5      nU R                  U R                  S n[        R                   mSR#                  U4S jU 5       5      nUR                  U5        UR                  5       U l        Ub  UR                  5         [%        U R                  5      U l        g! Ub  UR                  5         f f = f)z,write the new branch names to revbranchcacheNr   s   abr6   s   resetting content of %s
s   %s changed - rewriting it
s   %s is missing - rewriting it
T)ignoremissing   wbc              3  4   >#    U  H  nT" U5      v   M     g 7fr   rO   ).0r   
from_locals     r   	<genexpr>-revbranchcache._writenames.<locals>.<genexpr>  s     ;UjmmUs   )rZ   rY   rn   r[   openr]   tellr   r   rd   rj   rm   
unlinkpathrX   rW   r   	fromlocaljoinr   )r   ro   fcurrent_sizedbgnamesrv   r   s          @r   r   revbranchcache._writenamesl  s     !"D"#D	$$(;(;q(@MM&&y%8 vvx#5#55GGENGGI,,:%)<?GGMM#	/2*+D''(D$""a'(((FMM&&y%8KK 3 3 56E!++J::;U;;DGGDM!"D}	!$++. }	 s   F	G G1c                J   [        [        UR                  5      [        U R                  5      [        -  5      nU[        -  nU R
                  (       a  Sn[        U[        -  -  nUR                  R                  [        S5       n SSS5        UR                  R                  [        S5       nUR                  S[        R                  5        UR                  5       nXb:  a  SnXb:w  a  U[        -  n[        XF5      U-
  n[        XF5      U-
  U:  a'  SnS[        -  n	UR                  R                  U	5        OzUS:  aC  Sn	XU-
  U[        4-  n	XF:  a  Sn
XU-
  -  n
X-  n	U	S-  n	UR                  R                  U	5        O1X$:X  d   eS	n	U	[        Xb-
  4-  n	UR                  R                  U	5        US:  a<  UR                  U5        UR!                  U R                  R#                  X$5      5        ObUR%                  5         UR                  R                  [        S
SS9 nUR!                  U R                  R#                  X$5      5        SSS5        SSS5        X0l        SU l        g! , (       d  f       GN= f! , (       d  f       N6= f! , (       d  f       N?= f)z$write the new revs to revbranchcacher   s   a+bNs   r+bs   resetting content of cache/%s
s(   overwriting %d bytes from %d in cache/%ss    leaving (%d trailing bytes)   
s,   cache/%s contains %d unknown trailing bytes
r   T)
atomictempF)rB   r   rl   rX   r   rZ   r[   r   seekosSEEK_ENDr   REWRITE_RATIOmaxrd   rj   r   rF   r   rm   )r   ro   r   r   rD   r   r   	thresholdoverwrittenr   extrarev_files               r   r   revbranchcache._writerevs  s7   3t~~&DMM(:k(IJ[   E u34]]&1Q 2]]&1QFF1bkk"668L#$(=8	!#4u<*U2y@E<xGCGGMM#& 1_EC50%BBC) ?!335LCGGMM#& !<'<JCHl&:;;CGGMM#&qyu++E78	]]''# (  NN4==#6#6u#BCE 2P   %W 21H E 21s1   I10E8J(+JJ1
J 
J	J
J")rZ   rW   rn   rX   rm   rY   rV   rc   )T)r   r   )rH   rI   rJ   rK   rL   r   r{   r   r	   propertycacher   rc   rb   r   r   r   r   r   rN   rO   r   r   rQ   rQ   ~   sX    ,F/R%%
 
9 9+%Z  ,
@ :#/J6&r   rQ   )
__future__r   r   structr8   r    r   r   r   r	   utilsr
   calcsizer7   r&   _rbcversionr]   rX   _rbc_legacy_versionr_   ri   r'   r   
_rbcminincr   r   r   r   r   rQ   rO   r   r   <module>r      s   
 # 	   ??	   ;&	$  #66 !44 
z"+
  FK FKRI& I&r   