HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/mercurial/revlogutils/__pycache__/nodemap.cpython-310.pyc
o

�]LbQV�@s�ddlmZddlZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZGdd	�d	e
�Zd
d�Zdd
�Zdd�Zdd�ZGdd�de�Zdd�Zdd�ZdGdd�ZdZe�d�Ze�d�ZGdd�de�Zdd �Zd!d"�Zd#d$�Zd%d&�Z e�d'�Z!d(Z"dZ#d)d*�Z$d+d,�Z%Gd-d.�d.e
�Z&d/d0�Z'd1d2�Z(d3d4�Z)dHd5d6�Z*d7d8�Z+d9d:�Z,d;d<�Z-d=d>�Z.d?d@�Z/dAdB�Z0dCdD�Z1dEdF�Z2dS)I�)�absolute_importN�)�hex)�error�requirements�util�)�docketc@seZdZdd�ZdS)�NodeMapcCst�d|��)Nsunknown node: %s)r�RevlogError)�self�x�r�?/usr/lib/python3/dist-packages/mercurial/revlogutils/nodemap.py�__missing__�zNodeMap.__missing__N)�__name__�
__module__�__qualname__rrrrrr
sr
cCsdS)zrhook point for test

    This let tests to have things happens between the docket reading and the
    data readingNrrrrr�test_race_hook_1srcCsLtj|jvrdStj|jvrdS|��}td||j�td||jjj�dS)zoThe 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�unfirrr�post_stream_cleanup&sr c
Cs�|jdurdS|j�|j�}|sdSd}t�|||tj��\}|tkr'dS|tj7}t�|||tj��}|\}}}}}	|tj7}t||||��}
||7}||
_	||||	�|
_
||
_||
_t
||
�}|jj�d�}t�z5|�|��&}
|r�zt�t�|
|��}Wnty�d}Ynw|
�|�}Wd�n1s�wYWnttfy�}z|jtjkr�WYd}~dS�d}~wwt|�|kr�dS|
|fS)z'read the nodemap for a revlog from diskNr�persistent-nodemap.mmap�)�
_nodemap_file�opener�tryread�	S_VERSION�unpack�size�ONDISK_VERSION�S_HEADER�
NodeMapDocket�tip_rev�tip_node�data_length�data_unused�_rawdata_filepath�options�getrr�buffer�mmapread�
ValueError�read�IOError�OSError�errno�ENOENT�len)�revlog�pdata�offset�version�headers�uid_sizer,r.r/�
tip_node_sizer	�filename�use_mmap�fd�data�errr�persisted_data3sV



�
���	��rHcs\�jrdS�jdurdSd�j}|�|�rdS|�|�fdd��|�|�fdd��dS)z�Install whatever is needed transaction side to persist a nodemap on disk

    (only actually persist the nodemap if this is relevant for this revlog)
    Nsnm-revlog-persistent-nodemap-%scst|�dd�S)NT)�pending��persist_nodemap��tr�r<rr�<lambda>psz*setup_persistent_nodemap.<locals>.<lambda>cs
t|��S�NrJrLrNrrrOrs
)�_inliner#�hasfinalize�
addpending�addfinalize)rMr<�callback_idrrNr�setup_persistent_nodemapas


�rVc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�_NoTransactionzCtransaction like object to update the nodemap outside a transactioncCs
i|_dSrP��
_postclose�rrrr�__init__xs
z_NoTransaction.__init__cCs||j|<dSrPrX)rrU�
callback_funcrrr�addpostclose{rz_NoTransaction.addpostclosecO�dSrPr�r�args�kwargsrrr�registertmp~�z_NoTransaction.registertmpcOr^rPrr_rrr�	addbackup�rcz_NoTransaction.addbackupcOr^rPrr_rrr�add�rcz_NoTransaction.addcOr^rPrr_rrr�addabort�rcz_NoTransaction.addabortcGr^rPr)rr`rrr�_report�rcz_NoTransaction._reportN)rrr�__doc__r[r]rbrdrerfrgrrrrrWusrWcCsJ|jrdS|jdurdSt�}t||�t|j�D]	}|j|d�qdS)z�update the persistent nodemap right now

    To be used for updating the nodemap on disk outside of a normal transaction
    setup (eg, `debugupdatecache`).
    N)rQr#rWrK�sortedrY)r<�notr�krrr�update_persistent_nodemap�s

�rlcCsN|j}t�d|�}|j�|j�}|j�|�D]
}|�|�r$|j�	|�qdS)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)rMrr<�prefix�pattern�dirpath�frrrr�s
��rFcs,t|dd�rt�d��|jdur|rt|�|_nd}t�|��t�|jd�}|j}t�|jd�}|j	j
�d�}d}	|r�|dur�|j��}
|j�
�\}}}	|
jt|	�}
|
j|}||
kr_d}	nX|
|d	krhd}	nOt||
��|��|
j�|�	�d
��/}|�|
j�|�|	�|r�|r�|�d�|�|
�}n
|��t�t�||
��}Wd�n1s�wY|
|
_||
_|	du�r#t�}
t||
��t�|jd�r�|j��}	nt|j�}	|j	j���fd
d�}d�}|�||�|�	�d��$}|�|	�|�r|r�|	}n|��t�t�|t|	���}Wd�n	1�swYt|	�|
_|��|
_|� |
j�|
_!|j}|�r?|d7}|�"|�n|�#|�|j	|ddd��}|�|
�$��Wd�n	1�s_wY|
|_|�rq|j�%|
|�t&||
����r�t|d|j	����fdd�}d|j}|�'||�dSdS)z-Write nodemap data on disk for a given revlog�filteredrevsrz.cannot persist nodemap of a filtered changelogNz?calling persist nodemap on a revlog without the feature enabled�nodemap_data_incremental�update_nodemap_datar!�
sr+r�nodemap_data_allcs���dSrPrrL)�datafilerurr�abortck�sz persist_nodemap.<locals>.abortcks	delete-%ssw+s.a�wT)�
atomictemp�_realopenercs�D]}��|�qdSrP)ru)rM�oldfile)�olds�realvfsrr�cleanups�z persist_nodemap.<locals>.cleanupsrevlog-cleanup-nodemap-%s)(�getattrr�ProgrammingErrorr#�get_nodemap_filer�safehasattr�index�_nodemap_docketr$r1r2�copyr{r.r;r/r0re�seek�writer6�flushr3r4r+r~�persistent_datarurf�tiprevr,�noder-rbrd�	serializer|�_other_rawdata_filepathr])rMr<rI�force�msg�can_incremental�
ondisk_docket�	feed_datarDrF�
target_docket�
src_docket�data_changed_count�
new_length�
new_unusedrE�new_datar�rU�	file_path�fpr�r)rr�r�rurrK�s��


�



��




��


�

�rKz>Bz>BQQQQc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)r+z}metadata associated with persistent nodemap data

    The persistent data may come from disk or be on their way to disk.
    NcCs2|durt��}||_d|_d|_d|_d|_dS)Nr)�
docket_mod�make_uid�uidr,r-r.r/)rr�rrrr[:s	
zNodeMapDocket.__init__cCs0t|jd�}|j|_|j|_|j|_|j|_|S)N)r�)r+r�r,r-r.r/)r�newrrrr�VszNodeMapDocket.copycCsD|j|jkrdS|j|jkrdS|j|jkrdS|j|jkr dSdS)N���rr�r�r.�r�otherrrr�__cmp__^szNodeMapDocket.__cmp__cCs|j|jko|j|jkSrPr�r�rrr�__eq__iszNodeMapDocket.__eq__cCsfg}|�t�t��t|j�|j|j|jt|j	�f}|�t
j|��|�|j�|�|j	�d�|�S)z9return serialized bytes for a docket using the passed uidr")�appendr&�packr)r;r�r,r.r/r-r*�join)rrFr@rrrr�ls�
zNodeMapDocket.serializerP)	rrrrhr[r�r�r�r�rrrrr+4s
r+cCs|j}d||jfS)z9The (vfs relative) nodemap's rawdata file for a given uids%s-%s.nd)rmr�)r<r	rvrrrr0}sr0c	Csl|j}t�d|�}t||�}|j�|�}|j�|�}g}|j�|�D]}|�|�r3||kr3|�	|�q#|S)Ns(^|/)%s-[0-9a-f]+\.nd$)
rmrnror0r$�basenamerprrrsr�)	r<r	rvrw�
new_file_path�
new_file_namerx�othersryrrrr��s

�r�cCst|�}t|�S)zAreturn the persistent binary form for a nodemap for a given index)�_build_trie�
_persist_trie)r��trierrrr��sr�cCs&t|||�\}}|tjt||d�fS)zGreturn the incremental update for persistent nodemap from a given index)�existing_idx)�_update_trie�S_BLOCKr(r�)r��root�max_idx�last_rev�
changed_blockr�rrr�update_persistent_data�s
�r�z>llllllllllllllllr�cCs
|tS)z�Return 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)�revrrr�_transform_rev�s
r�cCs
t|d�S)z/turn an hexadecimal digit into a proper integer�)�int)�	hex_digitrrr�_to_int�s
r�cs(eZdZdZ�fdd�Zdd�Z�ZS)�BlockzOrepresent a block of the Trie

    contains up to 16 entry indexed from 0 to 15cstt|���d|_dSrP)�superr�r[�	ondisk_idrZ��	__class__rrr[�s
zBlock.__init__cst�fdd�td�D��S)Nc3s�|]}��|�VqdSrP)r2)�.0�irZrr�	<genexpr>���z!Block.__iter__.<locals>.<genexpr>r�)�iter�rangerZrrZr�__iter__�szBlock.__iter__)rrrrhr[r��
__classcell__rrr�rr��sr�cCs<t�}tt|��D]}t||d�}t|d|||�q	|S)z�build 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�r;r�_insert_into_block)r�r�r��current_hexrrrr��s
r�cCsHd}t|dt|��D]}t||d�}|t|d|||�7}q||fS)�consumerrr�)r�r;rr�)r�r�r��changedr�r�rrrr��s
r�cCs�d}|jdur
d|_t|||d��}|�|�}|dur#|||<|St|t�r6|t||d|||�7}|St||d�}|}	t�}
|
||<t||d|
|	|�t||d|
||�|S)a7insert 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
    rNr�)r�r�r2�
isinstance�dictr�rr�)r��level�block�current_revr�r�r��entry�	other_hex�	other_revr�rrrr��s(	


���r�cCsti}|dur|d}nd}g}t|�D]!}|jdur"|j|t|�<qt|�||t|�<|�t||��qd�|�S)zaturn a nodemap trie into persistent binary data

    See `_build_trie` for nodemap trie structureNrrr")�
_walk_trier��idr;r��_persist_blockr�)r�r��	block_map�base_idx�chunks�tnrrrr�s


r�ccs@�t|���D]\}}t|t�rt|�D]}|Vqq|VdS)zcyield all the block in a trie

    Children blocks are always yield before their parent block.
    N)ri�itemsr�r�r�)r��__�item�	sub_blockrrrr�*s�
�
r�cs t�fdd�|D��}tj|�S)z�produce persistent binary data for a single block

    Children block are assumed to be already persisted and present in
    block_map.
    c3s�|]}t|��VqdSrP)�	_to_value)r��v�r�rrr�<r�z!_persist_block.<locals>.<genexpr>)�tupler�r�)�
block_noder�rFrr�rr�6s
r�cCs*|durtSt|t�r|t|�St|�S)zpersist any value as an integerN)�NO_ENTRYr�r�r�r�)r�r�rrrr�@s

r�cCs�t|�tjdkrd}t�|tjt|�f��|st�dfSi}g}tdt|�tj�D]$}t�}t|�|_|||j<|||tj�}t�|�}|�	||f�q+|D]#\}}t
|�D]\}	}
|
tkrcqZ|
dkrn||
||	<qZt|
�||	<qZqR||tjfS)z,parse parse nodemap data into a nodemap Triers:nodemap data size is not a multiple of block size (%d): %dN)
r;r�r(r�Abortr�r�r�r'r��	enumerater�r�)rFr�r��
new_blocksr�r��
block_data�values�b�idxr�rrr�
parse_dataJs.



�r�c
Csd}|�dt|��t|�\}}tt|��}|�dt|��tt|��D]C}||vr8d|}|�|�d}n|�|�t|t	||d��}	|	durXd|}|�|�d}q&|	|krid	||	f}|�|�d}q&|r~t
|�D]}d
|}|�|�qpd}|S)zBverify that the provided nodemap data are valid for the given idexrsrevision in index:   %d
srevision in nodemap: %d
s$  revision missing from nodemap: %d
rr�Ns/  revision node does not match any entries: %d
s?  revision node does not match the expected revision: %d != %d
s!  extra revision in  nodemap: %d
)�statusr;r��set�_all_revisionsr��	write_err�remove�
_find_noderri)
�uir�rF�retr�r��all_revs�rr��nm_revrrr�
check_datahs<


��
�rccs8�t|�D]}|D]}|dust|t�rq	|Vq	qdS)z%return all revisions stored in a TrieN)r�r�r�)r�r�r�rrrr��s���r�cCs6|�t|dd���}t|t�rt||dd��S|S)z.find the revision associated with a given noderrN)r2r�r�r�r�)r�r�r�rrrr��s
r�cCs*|jr|jd}|j�|�r|S|jdS)Ns.n.as.n)�_trypendingrmr$�exists)r<�pending_pathrrrr��s


r�)FFrP)3�
__future__rr9rn�structr�r�rrrr	r�r�r
rr rHrV�objectrWrlrrKr)�Structr&r*r+r0r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�rrrr�<module>sV
.



I&
		
"

#