
    6h8                    0   S SK Jr  S SKrS SKrS SKrSSKJrJrJrJ	r	  SSKJ
r
  SS jr\R                  R                  S5      r\(       a  SS	 jr\R                  " \
R                   S
-   5      r\R                  " S5      r " S S5      rS rS rSS jrg)    )annotationsN   )encodingerrornodeutil   )	constantsc                \    [         R                  " [        R                  " U S-  5      5      $ )z[return a new unique identifier.

The identifier is random and composed of ascii characters.r   )r   hexosurandom)id_sizes    >/usr/lib/python3/dist-packages/mercurial/revlogutils/docket.pymake_uidr   $   s      88BJJw!|,--    s   HGTEST_UUIDFILEc                v    [        [        SS9 nUR                  5       R                  5       nS S S 5        [        W5      nSn[        SS5      nU H  nUS-	  nXE-  S-  nXx-   U-   nM     [        R                  " 5       n	U	R                  US	S
9  U	R                  U S-  5      n
U S:X  d   e[        R                  " SU
5      n[        R                  " U5      n[        [        S5       nUR                  U5        S S S 5        U$ ! , (       d  f       N= f! [         a    Sn Nf = f! , (       d  f       U$ = f)Nrb)modes   04r   #11111111111111111111111111111111111r   #      r	   )version      z>Lwb)openstable_docket_filereadstripFileNotFoundErroriterintrandomRandomseedgetrandbitsstructpackr   r   write)r   fr&   	iter_seedint_seedlow_maski	high_partlow_partrrawpnews                r   r   r   2   s   	(t4vvx~~' 5 J	x#A BI +2H +a/H  MMO	x#mmGaK(!||KKc"hhqk$d+qGGCL ,
+ 54  	D	" ,+
s9   D DD *D)
DD D D&%D&)
D8s   BBBBBBQQQQQQcz>BLc                  2   \ rS rSrSr               SS jrS rS rSS jrS r	S	 r
SS
 jrS rS rSS jr\S 5       r\R"                  S 5       r\S 5       r\R"                  S 5       r\S 5       r\R"                  S 5       rSS jrSS jrSrg)RevlogDocketd   zmetadata associated with revlogNc                   X0l         [        U5      U l        SU l        UR                  U l        UR                  U l        UR                  U l	        X@l
        XPl        X`l        Xpl        Xl        Xl        [!        U5      [!        U5      -  (       a   e[!        U5      [!        U	5      -  (       a   e[!        U5      [!        U	5      -  (       a   eX::  d   eX::  d   eX::  d   eXl        Xl        Xl        Xl        Xl        Xl        U(       a4  U R$                  U l        U R(                  U l        U R,                  U l        O3U R"                  U l        U R&                  U l        U R*                  U l        UU l        g )NF)_version_headerbool
_read_only_dirtyradix_radix_docket_file_pathopener_opener_index_uuid_older_index_uuids
_data_uuid_older_data_uuids_sidedata_uuid_older_sidedata_uuidsset_initial_index_end_pending_index_end_initial_data_end_pending_data_end_initial_sidedata_end_pending_sidedata_end
_index_end	_data_end_sidedata_enddefault_compression_header)selfrevloguse_pendingversion_header
index_uuidolder_index_uuids	data_uuidolder_data_uuidssidedata_uuidolder_sidedata_uuids	index_endpending_index_enddata_endpending_data_endsidedata_endpending_sidedata_endrT   s                    r   __init__RevlogDocket.__init__g   sT   &  .{+ll((
}}%"3#!1+%9"()C0@,AAAA'(3/C+DDDD()C0D,EEEE---+++333"+"3!)!1%1"%9""55DO!33DN!%!;!;D"55DO!33DN!%!;!;D*D'r   c                p    U R                   c  [        5       U l         SU R                  U R                   4-  $ )z=file path to the current index file associated to this docket	   %s-%s.idx)rD   r   r?   rU   s    r   index_filepathRevlogDocket.index_filepath   s4     #'zDt{{D,<,<===r   c                    U R                   U R                  4nU R                  R                  SU5        [	        5       U l         U R                  5       $ )zTswitch index file to a new UID

The previous index UID is moved to the "older" list.r   )rD   rQ   rE   insertr   rj   rU   olds     r   new_index_fileRevlogDocket.new_index_file   sG     1&&q#.#:""$$r   c              #  z   #    U R                    H'  u  p#U(       d  US:  d  M  SU R                  U4-  v   M)     g7f)z>yield file path to older index files associated to this docketr   rh   N)rE   r?   rU   include_emptyuuidsizes       r   old_index_filepaths RevlogDocket.old_index_filepaths   s6      11JDq"dkk4%888 2   ;;c                p    U R                   c  [        5       U l         SU R                  U R                   4-  $ )z<file path to the current data file associated to this docket	   %s-%s.dat)rF   r   r?   ri   s    r   data_filepathRevlogDocket.data_filepath   s/     ??"&jDOt{{DOO<<<r   c                    U R                   U R                  4nU R                  R                  SU5        [	        5       U l         U R                  5       $ )zRswitch data file to a new UID

The previous data UID is moved to the "older" list.r   )rF   rR   rG   rm   r   r|   rn   s     r   new_data_fileRevlogDocket.new_data_file   sD     /%%a-"*!!##r   c              #  z   #    U R                    H'  u  p#U(       d  US:  d  M  SU R                  U4-  v   M)     g7f)z=yield file path to older data files associated to this docketr   r{   N)rG   r?   rs   s       r   old_data_filepathsRevlogDocket.old_data_filepaths   s6      00JDq"dkk4%888 1ry   c                p    U R                   c  [        5       U l         SU R                  U R                   4-  $ )z@file path to the current sidedata file associated to this docket	   %s-%s.sda)rH   r   r?   ri   s    r   sidedata_filepathRevlogDocket.sidedata_filepath   s4     &"**Dt{{D,?,?@@@r   c                    U R                   U R                  4nU R                  R                  SU5        [	        5       U l         U R                  5       $ )zZswitch sidedata file to a new UID

The previous sidedata UID is moved to the "older" list.r   )rH   rS   rI   rm   r   r   rn   s     r   new_sidedata_fileRevlogDocket.new_sidedata_file   sI     ""D$6$67""))!S1&j%%''r   c              #  z   #    U R                    H'  u  p#U(       d  US:  d  M  SU R                  U4-  v   M)     g7f)zAyield file path to older sidedata files associated to this docketr   r   N)rI   r?   rs   s       r   old_sidedata_filepaths#RevlogDocket.old_sidedata_filepaths   s6      44JDq"dkk4%888 5ry   c                    U R                   $ N)rQ   ri   s    r   r_   RevlogDocket.index_end   s    r   c                >    XR                   :w  a  Xl         SU l        g g NT)rQ   r=   rU   new_sizes     r   r_   r      s    &&ODK 'r   c                    U R                   $ r   )rR   ri   s    r   ra   RevlogDocket.data_end   s    ~~r   c                >    XR                   :w  a  Xl         SU l        g g r   )rR   r=   r   s     r   ra   r      s    ~~%%NDK &r   c                    U R                   $ r   )rS   ri   s    r   rc   RevlogDocket.sidedata_end   s    !!!r   c                >    XR                   :w  a  Xl         SU l        g g r   )rS   r=   r   s     r   rc   r      s     )))!)DK *r   c                   U R                   (       d  gU R                  (       a&  SnX@R                  -  n[        R                  " U5      eU(       d  UR                  U R                  SS9  U R                  U R                  SSS9 nUR                  U R                  US95        S	S	S	5        X l         g! , (       d  f       N= f)
zWwrite the modification of disk if any

This make the new content visible to all processFs   writing read-only docket: %ss   store)location   wT)r   
atomictemp)pendingN)	r=   r<   rA   r   ProgrammingError	addbackuprC   r*   
_serialize)rU   transactionr   	strippingmsgr+   s         r   r*   RevlogDocket.write   s     {{5zz!,,S11 %%djj8%DdjjtE89 F "K	 FEs   B44
Cc                   U(       a%  U R                   nU R                  nU R                  nO$U R                  nU R                  nU R
                  nX0R                  ::  d   eX@R
                  ::  d   eU R                  [        U R                  5      [        U R                  5      [        U R                  5      [        U R                  5      [        U R                  5      [        U R                  5      UU R                  UU R                  UU R
                  U R                  4n/ nUR                  [         R"                  " U6 5        UR                  U R                  5        U R                   H3  u  pxUR                  [$        R#                  [        U5      U5      5        M5     U R                   H  u  pxUR                  U5        M     UR                  U R                  5        U R                   H3  u  pxUR                  [$        R#                  [        U5      U5      5        M5     U R                   H  u  pxUR                  U5        M     UR                  U R                  5        U R                   H3  u  pxUR                  [$        R#                  [        U5      U5      5        M5     U R                   H  u  pxUR                  U5        M     SR'                  U5      $ )Nr   )rK   rM   rO   rQ   rR   rS   r:   lenrD   rE   rF   rG   rH   rI   rT   appendS_HEADERr)   	S_OLD_UIDjoin)	rU   r   official_index_endofficial_data_endofficial_sidedata_enddatasurv   s	            r   r   RevlogDocket._serialize  s8   !%!8!8 $ 6 6$($>$>!!% $$($6$6! !NN222$(:(::::    !''( &&'##$**+OONN!++
  	%&	!!"..GAHHY^^CFD12 /..GAHHQK / 	
!--GAHHY^^CFD12 .--GAHHQK . 	
$$%11GAHHY^^CFD12 211GAHHQK 2xx{r   )rR   rF   r=   rQ   rD   rM   rK   rO   rG   rE   rI   rC   rA   rN   rL   rP   r?   r<   rS   rH   r:   rT   )FNN Nr   Nr   r   r   r   r   r   r   N)T)FFF)__name__
__module____qualname____firstlineno____doc__re   rj   rp   rw   r|   r   r   r   r   r   propertyr_   setterra   rc   r*   r   __static_attributes__r   r   r   r7   r7   d   s    )
 #'#4El>%9=$9A(9    
   __ 
 " "  
*1r   r7   c                    US-  nU[         R                  [         R                  4;  a  g[        R                  U R
                  R                     R                  5       n[        U UUS9nSUl	        U$ )z?given a revlog version a new docket object for the given revlogi  N)rX   rT   T)
r
   REVLOGV2CHANGELOGV2r   compenginesfeature_configcompression_enginerevlogheaderr7   r=   )rV   rX   
rl_versioncompdockets        r   default_docketr   I  st    &(J),,i.C.CDD00ln 	 %#'F
 FMMr   c                    / n/ n[        SU5       H=  nU " [        R                  5      nUR                  [        R	                  U5      5        M?     U H  u  pgU " U5      nUR                  X45        M!     U$ )Nr   )ranger   rv   r   unpack)	get_datacount	all_sizesall_uidsr/   r3   uid_size	file_sizeuids	            r   _parse_old_uidsr   Z  sr    IH1e_y~~&))#./   )x ()  ) Or   c                x  ^^ [         R                  TS[         R                   5      n[         R                  /mUU4S jn[        U5      n[	        U5      n[	        U5      nU" U5      n[	        U5      n	[        XI5      n
[	        U5      nU" U5      n[	        U5      n[        XM5      n[	        U5      nU" U5      n[	        U5      n[        UU5      n[	        U5      n[	        U5      n[	        U5      n[	        U5      n[	        U5      n[	        U5      n[	        U5      n[        U 4UUUU
UUUUUUUUUUUS.6nU$ )zBgiven some docket data return a docket object for the given revlogNc                   > TS   U -   [        T5      :  a.  SnUTS   U -   [        T5      4-  n[        R                  " U5      eTTS   TS   U -    nTS==   U -  ss'   U$ )z/utility closure to access the `size` next bytesr   s'   docket is too short, expected %d got %d)r   r   Abort)rv   r   r3   r   offsets      r   r   parse_docket.<locals>.get_datan  st    !9tc$i'<CF1I$c$i00C++c""6!9vay4/0q	T	
r   )rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   rT   )r   r   rv   r"   nextr   r7   )rV   r   rW   headerr   iheaderrX   index_uuid_sizerY   older_index_uuid_countrZ   data_uuid_sizer[   older_data_uuid_countr\   sidedata_uuid_sizer]   older_sidedata_uuid_countr^   
index_sizepending_index_size	data_sizepending_data_sizesidedata_sizepending_sidedata_sizerT   r   r   s    `                         @r   parse_docketr   g  sH   __T/HMM23F mm_F	 6lG']N7mO/*J!']'I']N(I M&xGg/0M $W*85NOgJgWIWMM M!%g%+)#1,*"2#=!F$ Mr   )r   r   )
__future__r   r   r$   r(    r   r   r   r   r
   r   environgetr   StructINDEX_HEADER_FMTr   r   r7   r   r   r   r   r   r   <module>r      s   $ # 	   
. %%))*<= X ==336FFG MM% 	b bJ"
Hr   