
    6h?V                       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	  SSKJ
r   " S S	\5      rS
 rS rS rS r " S S5      rS rS rS-S jrSr\R.                  " S5      r\R.                  " S5      r " S S5      rS rS rS rS r\R.                  " S5      rSr Sr!S r"S r# " S S \5      r$S! r%S" r&S# r'S.S$ jr(S% r)S& r*S' r+S( r,S) r-S* r.S+ r/S, r0g)/    )annotationsN   )hex)errorrequirementsutil   )docketc                      \ rS rSrS rSrg)NodeMap   c                4    [         R                  " SU-  5      e)Ns   unknown node: %s)r   RevlogError)selfxs     ?/usr/lib/python3/dist-packages/mercurial/revlogutils/nodemap.py__missing__NodeMap.__missing__   s     3a 788     N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    9r   r   c                     g)zjhook point for test

This let tests to have things happens between the docket reading and the
data readingNr   r   r   r   test_race_hook_1r      s    
 	r   c                    [         R                  U R                   ;  a  g[         R                  U R                   ;   a  gU R                  5       n[	        SXR
                  5        [	        SXR                  R                  R                  5        g)zgThe stream clone might needs to remove some file if persisten nodemap
was dropped while stream cloning
N)	r   REVLOGV1_REQUIREMENTNODEMAP_REQUIREMENT
unfiltereddelete_nodemap	changelogmanifestlog
_rootstore_revlog)repounfis     r   post_stream_cleanupr)   %   sh     ((0A0AA''4+<+<<??D4~~.4//::BBCr   c                   U R                   c  gU R                  R                  U R                   5      nU(       d  gSn[        R	                  XU[        R
                  -    5      u  nU[        :w  a  gU[        R
                  -  n[        R	                  XU[        R
                  -    5      nUu  pVpxn	U[        R
                  -  n[        XX%-    5      n
X%-  nXjl	        XX)-    U
l
        Xzl        Xl        [        X
5      nU R                  R                  R                  S5      n[!        5          U R                  U5       nU(       aL  U R                  R#                  U5      (       a,   [$        R&                  " [$        R(                  " X5      5      nOUR-                  U5      nSSS5        [1        W5      U:  a  gX4$ ! [*         a    Sn N)f = f! , (       d  f       N3= f! [.         a     gf = f)z'read the nodemap for a revlog from diskNr      persistent-nodemap.mmapr   )_nodemap_fileopenertryread	S_VERSIONunpacksizeONDISK_VERSIONS_HEADERNodeMapDockettip_revtip_nodedata_lengthdata_unused_rawdata_filepathoptionsgetr   is_mmap_safer   buffermmapread
ValueErrorreadFileNotFoundErrorlen)revlogpdataoffsetversionheadersuid_sizer5   r7   r8   tip_node_sizer
   filenameuse_mmapfddatas                  r   persisted_datarN   2   s   #MM!!&"6"67EF!!%)..1H"IJJW. 
innFooeVhmm-CDEGAH>H{
hmmF5&*;<=F
FNV%;<FO$$ 0H}}$$(()CDH]]8$FMM66x@@;;t}}R'EFD
 ww{+ % 4y;< " D	 %$  sT   2G& (G,*GG(G& GGGG
G#G& #G& &
G32G3c                   ^ TR                   (       a  gTR                  c  gSTR                  -  nU R                  U5      (       a  gU R                  UU4S j5        U R	                  UU4S j5        g)zInstall whatever is needed transaction side to persist a nodemap on disk

(only actually persist the nodemap if this is relevant for this revlog)
Ns   nm-revlog-persistent-nodemap-%sc                   > [        U TSS9$ )NT)pendingpersist_nodemaptrrC   s    r   <lambda>*setup_persistent_nodemap.<locals>.<lambda>l   s    FD Ir   c                   > [        U T5      $ NrR   rT   s    r   rV   rW   n   s    ?2v+Fr   )_inliner,   hasfinalize
addpendingaddfinalize)rU   rC   callback_ids    ` r   setup_persistent_nodemapr_   ]   se    
 ~~# 5v7K7KKK	~~k""MMI NN; FGr   c                  B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)_NoTransactionq   zCtransaction like object to update the nodemap outside a transactionc                    0 U l         g rY   
_postcloser   s    r   __init___NoTransaction.__init__t   s	    r   c                     X R                   U'   g rY   rd   )r   r^   callback_funcs      r   addpostclose_NoTransaction.addpostclosew   s    '4$r   c                    g rY   r   r   argskwargss      r   registertmp_NoTransaction.registertmpz       r   c                    g rY   r   rn   s      r   	addbackup_NoTransaction.addbackup}   rs   r   c                    g rY   r   rn   s      r   add_NoTransaction.add   rs   r   c                    g rY   r   rn   s      r   addabort_NoTransaction.addabort   rs   r   c                    g rY   r   )r   ro   s     r   _report_NoTransaction._report   rs   r   rd   N)r   r   r   r   __doc__rg   rk   rq   ru   rx   r{   r~   r   r   r   r   ra   ra   q   s(    M5r   ra   c                    U R                   (       a  gU R                  c  g[        5       n[        X5        [	        UR
                  5       H  nUR
                  U   " S5        M     g)zupdate the persistent nodemap right now

To be used for updating the nodemap on disk outside of a normal transaction
setup (eg, `debugupdatecache`).
N)rZ   r,   ra   rS   sortedre   )rC   notrks      r   update_persistent_nodemapr      sQ     ~~#DD!DOO$4  %r   c                B   UR                   n[        R                  " SU-  5      nUR                  R	                  UR
                  5      nUR                  R                  U5       H6  nUR                  U5      (       d  M  UR                  R                  U5        M8     g)z.Delete nodemap data on disk for a given revlogs"   (^|/)%s(-[0-9a-f]+\.nd|\.n(\.a)?)$N)
radixrecompiler-   dirname
_indexfilelistdirmatchsvfs	tryunlink)rU   r'   rC   prefixpatterndirpathfs          r   r"   r"      ss    \\Fjj?&HIGmm##F$5$56G]]""7+==II" ,r   c           	     
  ^^^^ [        UR                  5      S::  a  g[        USS5      (       a  [        R                  " S5      eUR
                  c0  U(       a  [        U5      Ul        OSn[        R                  " U5      e[        UR                  S5      nUR                  n[        UR                  S5      nUR                  R                  R                  S	5      nSn	U(       Ga}  UGby  UR                  R                  5       n
UR                  R                  5       u  nnn	U
R                  [        U	5      -   nU
R                  U-   nX:w  a  Sn	GOXS
-  ::  a  Sn	GO[!        X5      mU R#                  TU
R                  5        UR                  TS5       nUR%                  U
R                  5        UR'                  U	5        U(       a  U(       a[  UR                  R)                  T5      (       a;  UR+                  5         [,        R.                  " [,        R0                  " X5      5      nO"UR%                  S5        UR3                  U5      nSSS5        Xl        Xl        U	GcE  [5        5       n
[!        X5      m[        UR                  S5      (       a  UR                  R7                  5       n	O[9        UR                  5      n	UR                  R:                  mUU4S jnST-  nU R=                  UU5        UR                  TS5       nUR'                  U	5        U(       an  U(       ae  UR                  R)                  T5      (       aE  UR+                  5         [,        R.                  " [,        R0                  " U[        U	5      5      5      nOU	nSSS5        [        U	5      U
l        UR?                  5       W
l         URC                  U
R@                  5      U
l"        UR
                  nU(       a  US-  nU RG                  U5        OU RI                  U5        UR                  USSS9 nUR'                  U
RK                  5       5        SSS5        Xl        U(       a  UR                  RM                  U
W5        [O        X5      mT(       a@  [        USUR                  5      mUU4S jnSUR
                  -  nU RQ                  UU5        gg! , (       d  f       GN= f! , (       d  f       GNV= f! , (       d  f       N= f)z-Write nodemap data on disk for a given revlogr   Nfilteredrevsr   z.cannot persist nodemap of a filtered changelogz?calling persist nodemap on a revlog without the feature enablednodemap_data_incrementalupdate_nodemap_datar+   
   s   r+nodemap_data_allc                   > T" T5        g rY   r   )rU   datafiler   s    r   abortck persist_nodemap.<locals>.abortck   s    hr   s	   delete-%ss   w+s   .a   wT)
atomictemp_realopenerc                :   > T H  nTR                  U5        M     g rY   )r   )rU   oldfileoldsrealvfss     r   cleanup persist_nodemap.<locals>.cleanup  s    !!'*  r   s   revlog-cleanup-nodemap-%s))rB   indexgetattrr   ProgrammingErrorr,   get_nodemap_filehasattr_nodemap_docketr-   r:   r;   copyr   r7   r8   r9   rx   seekwriter<   flushr   r=   r>   r@   r4   r   persistent_datar   r{   tiprevr5   noder6   rq   ru   	serializer   _other_rawdata_filepathrk   )rU   rC   rQ   forcemsgcan_incrementalondisk_docket	feed_datarK   rM   target_docket
src_docketdata_changed_count
new_length
new_unusedrL   new_datar   r^   	file_pathfpr   r   r   r   r   s                         @@@@r   rS   rS      s   
6<<Av~r**$$<
 	
 ##3F#;F SC((--fll,FGO**M&;<I}}$$(()CDHD=4..335
 LL113		
"..T:
"..1CC
&DO,D(?H FF8]667x/2112FMM$>$>x$H$H
#';;t}}R/L#M
#%77:#6 0 )3%(2%|%$V;6<<!344<<002D"6<<0D MM++		  #X- 	K)]]8U+rHHTN : :8 D DHHJ#{{4==SY+GHH#H , %(I!"MMOM#[[)>)>?M $$IU	
y!
Y	y$4	8B
((*+ 
9*((A #69D&-?	+ 3V5I5II
W-  0/D ,+( 
9	8s&   B8SBS(2 S:
S%(
S7:
Tz>Bz>BQQQQc                  :    \ rS rSrSrS
S jrS rS rS rS r	S	r
g)r4   i2  zumetadata associated with persistent nodemap data

The persistent data may come from disk or be on their way to disk.
Nc                x    Uc  [         R                  " 5       nXl        S U l        S U l        S U l        SU l        g )Nr   )
docket_modmake_uiduidr5   r6   r7   r8   )r   r   s     r   rg   NodeMapDocket.__init__8  sB    ;%%'C   
   r   c                    [        U R                  S9nU R                  Ul        U R                  Ul        U R                  Ul        U R
                  Ul        U$ )N)r   )r4   r   r5   r6   r7   r8   )r   news     r   r   NodeMapDocket.copyT  sE    )ll}}****
r   c                    U R                   UR                   :  a  gU R                   UR                   :  a  gU R                  UR                  :  a  gU R                  UR                  :  a  gg)Nr	   r   r   r7   r   others     r   __cmp__NodeMapDocket.__cmp__\  sY    88eii88eii 1 11 1 11r   c                t    U R                   UR                   :H  =(       a    U R                  UR                  :H  $ rY   r   r   s     r   __eq__NodeMapDocket.__eq__g  s+    xx599$N)9)9U=N=N)NNr   c                   / nUR                  [        R                  [        5      5        [	        U R
                  5      U R                  U R                  U R                  [	        U R                  5      4nUR                  [        R                  " U6 5        UR                  U R
                  5        UR                  U R                  5        SR                  U5      $ )z9return serialized bytes for a docket using the passed uidr   )appendr/   packr2   rB   r   r5   r7   r8   r6   r3   join)r   rM   rG   s      r   r   NodeMapDocket.serializej  s    INN>23MLL
 	HMM7+,DHHDMM"xx~r   )r7   r8   r6   r5   r   rY   )r   r   r   r   r   rg   r   r   r   r   r   r   r   r   r4   r4   2  s!    
8	Or   r4   c                :    U R                   nSX!R                  4-  $ )z9The (vfs relative) nodemap's rawdata file for a given uids   %s-%s.nd)r   r   )rC   r
   r   s      r   r9   r9   {  s    \\F&**---r   c                z   U R                   n[        R                  " SU-  5      n[        X5      nU R                  R                  U5      nU R                  R                  U5      n/ nU R                  R                  U5       H3  nUR                  U5      (       d  M  X:w  d  M"  UR                  U5        M5     U$ )Ns   (^|/)%s-[0-9a-f]+\.nd$)
r   r   r   r9   r-   basenamer   r   r   r   )	rC   r
   r   r   new_file_pathnew_file_namer   othersr   s	            r   r   r     s    \\Fjj3f<=G%f5MMM**=9Mmm##M2GF]]""7+== 2MM! , Mr   c                .    [        U 5      n[        U5      $ )zAreturn the persistent binary form for a nodemap for a given index)_build_trie_persist_trie)r   tries     r   r   r     s    uDr   c                V    [        XU5      u  pEU[        R                  -  [        XRS94$ )zGreturn the incremental update for persistent nodemap from a given index)existing_idx)_update_trieS_BLOCKr1   r   )r   rootmax_idxlast_revchanged_blockr   s         r   update_persistent_datar     s/    &uH=M$d1 r   z>llllllllllllllllr   c                    U [         -   * $ )zReturn the number used to represent the rev in the tree.

(or retrieve a rev number from such representation)

Note that this is an involution, a function equal to its inverse (i.e.
which gives the identity when applied to itself).
)
REV_OFFSET)revs    r   _transform_revr     s     :r   c                    [        U S5      $ )z/turn an hexadecimal digit into a proper integer   )int)	hex_digits    r   _to_intr     s    y"r   c                  2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )Blocki  zKrepresent a block of the Trie

contains up to 16 entry indexed from 0 to 15c                0   > [         TU ]  5         S U l        g rY   )superrg   	ondisk_id)r   	__class__s    r   rg   Block.__init__  s    r   c                @   ^  [        U 4S j[        S5       5       5      $ )Nc              3  F   >#    U  H  nTR                  U5      v   M     g 7frY   )r;   ).0ir   s     r   	<genexpr>!Block.__iter__.<locals>.<genexpr>  s     3ADHHQKKs   !r   )iterrangerf   s   `r   __iter__Block.__iter__  s    3r333r   )r   )	r   r   r   r   r   rg   r  r   __classcell__)r   s   @r   r   r     s    4
4 4r   r   c                    [        5       n[        [        U 5      5       H!  n[        X   S   5      n[	        U SXU5        M#     U$ )zbuild a nodemap trie

The nodemap stores revision number for each unique prefix.

Each block is a dictionary with keys in `[0, 15]`. Values are either
another block or a revision number.
   r   )r   r  rB   r   _insert_into_block)r   r   r   current_hexs       r   r   r     sC     7DSZ %*Q-(5!T< ! Kr   c           	         Sn[        US-   [        U 5      5       H$  n[        X   S   5      nU[        U SXU5      -  nM&     X14$ )consumer   r	   r
  )r  rB   r   r  )r   r   r   changedr   r  s         r   r   r     sP    GX\3u:.%*Q-(%eQ;GG / =r   c                Z   SnUR                   b  SUl         [        XAUS-    5      nUR                  U5      nUc  X2U'   U$ [        U[        5      (       a  U[        XS-   XsU5      -  nU$ [        X   S   5      nUn	[        5       n
XU'   [        XS-   XU5        [        XS-   XU5        U$ )a  insert a new revision in a block

index: the index we are adding revision for
level: the depth of the current block in the trie
block: the block currently being considered
current_rev: the revision number we are adding
current_hex: the hexadecimal representation of the of that revision
r	   Nr
  )r   r   r;   
isinstancedictr  r   r   )r   levelblockcurrent_revr  r  r   entry	other_hex	other_revr   s              r   r  r    s     G"EAI67IIIi E}&i N 
E4	 	 %19e+
 	
 N Q(		gi5!)SYG5!)S{KNr   c                   0 nUb  US-   nOSn/ n[        U 5       H^  nUR                  b  UR                  U[        U5      '   M*  [        U5      U-   U[        U5      '   UR	                  [        XR5      5        M`     SR                  U5      $ )z]turn a nodemap trie into persistent binary data

See `_build_trie` for nodemap trie structurer	   r   r   )
_walk_trier   idrB   r   _persist_blockr   )r   r   	block_mapbase_idxchunkstns         r   r   r     s     I!#F<<# "Ibf #Fh 6IbfMM.78  88Fr   c              #     #    [        U R                  5       5       H/  u  p[        U[        5      (       d  M  [	        U5       Sh  vN   M1     U v   g N7f)z[yield all the block in a trie

Children blocks are always yield before their parent block.
N)r   itemsr  r  r  )r  __items      r   r  r  (  sE     
 5;;=)dD!!!$''' * K (s   2AAAAc                T   ^ [        U4S jU  5       5      n[        R                  " U6 $ )zproduce persistent binary data for a single block

Children block are assumed to be already persisted and present in
block_map.
c              3  <   >#    U  H  n[        UT5      v   M     g 7frY   )	_to_value)r   vr  s     r   r  !_persist_block.<locals>.<genexpr>9  s     =*Q1i((*s   )tupler   r   )
block_noder  rM   s    ` r   r  r  3  s$     =*==D<<r   c                p    U c  [         $ [        U [        5      (       a  U[        U 5         $ [	        U 5      $ )zpersist any value as an integer)NO_ENTRYr  r  r  r   )r$  r  s     r   r'  r'  =  s3    |	D$		D""d##r   c                   [        U 5      [        R                  -  S:w  a4  Sn[        R                  " U[        R                  [        U 5      4-  5      eU (       d  [        5       S4$ 0 n/ n[        S[        U 5      [        R                  5       Hg  n[        5       n[        U5      Ul        XRUR                  '   XU[        R                  -    n[        R                  U5      nUR                  XW45        Mi     U H@  u  p[        U5       H,  u  pU
[        :X  a  M  U
S:  a  X*   X'   M  [        U
5      X'   M.     MB     WW[        R                  -  4$ )z,parse parse nodemap data into a nodemap Trier   s:   nodemap data size is not a multiple of block size (%d): %dN)rB   r   r1   r   Abortr   r  r   r0   r   	enumerater-  r   )rM   r   r  
new_blocksr  r  
block_datavaluesbidxr(  s              r   
parse_datar6  G  s   D	GLL Q&Kkk#s4y 99::w}IJ1c$i.i.%*%//"a',,./

+5/* /  	'FCH}a"'* (   !w||###r   c                d   SnU R                  S[        U5      -  5        [        U5      u  pE[        [	        U5      5      nU R                  S[        U5      -  5        [        [        U5      5       H  nXv;  a  SU-  nU R                  U5        SnOUR                  U5        [        U[        X   S   5      5      n	U	c  SU-  nU R                  U5        SnMi  X:w  d  Mp  SXy4-  nU R                  U5        SnM     U(       a*  [        U5       H  nS	U-  nU R                  U5        M     SnU$ )
zBverify that the provided nodemap data are valid for the given idexr   s   revisions in index:   %d
s   revisions in nodemap: %d
s$     revision missing from nodemap: %d
r	   r
  s/     revision node does not match any entries: %d
s?     revision node does not match the expected revision: %d != %d
s"     extra revisions in  nodemap: %d
)statusrB   r6  set_all_revisionsr  	write_errremove
_find_noder   r   )
uir   rM   retr   r#  all_revsrr   nm_revs
             r   
check_datarC  e  s'   
CII,E
:;$HD>$'(HII,H=>3u::Q>CLLCOOAD#ehqk"23>EICLLC[!",  LLC% ( !A81<CLL " Jr   c              #  ~   #    [        U 5       H*  nU H!  nUb  [        U[        5      (       a  M  Uv   M#     M,     g7f)z%return all revisions stored in a TrieN)r  r  r   )r   r  r(  s      r   r:  r:    s7     D!AyJq%00G  "s   ;=c                    U R                  [        USS 5      5      n[        U[        5      (       a  [	        X!SS 5      $ U$ )z.find the revision associated with a given noder   r	   N)r;   r   r  r  r=  )r  r   r  s      r   r=  r=    s>    IIgd1Qi()E%%ab**Lr   c                    U R                   (       a1  U R                  S-   nU R                  R                  U5      (       a  U$ U R                  S-   $ )Ns   .n.as   .n)_trypendingr   r-   exists)rC   pending_paths     r   r   r     sC    ||g-==--<<%r   )FFrY   )1
__future__r   r   structr   r    r   r   r   r
   r   r  r   r   r)   rN   r_   ra   r   r"   rS   r2   Structr/   r3   r4   r9   r   r   r   r   r-  r   r   r   r   r   r   r  r   r  r  r'  r6  rC  r:  r=  r   r   r   r   <module>rN     s   # 	   
 #9d 9
	
D(VH( 2!"#o.P MM$	=="F FR.
L --(
)

4D 4D&$$< F r   