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__/rewrite.cpython-310.pyc
o

�]Lb@s�@s\ddlZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZddlmZddlmZmZmZmZmZddlm Z dd	lmZm!Z!d0dd�Z"d0d
d�Z#d0dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd �Z,d1d!d"�Z-	d1d#d$�Z.d%d&�Z/d'd(�Z0d)d*�Z1d+d,�Z2	-d2d.d/�Z3dS)3�N�)�nullrev�)�COMP_MODE_PLAIN�ENTRY_DATA_COMPRESSED_LENGTH�ENTRY_DATA_COMPRESSION_MODE�ENTRY_DATA_OFFSET�ENTRY_DATA_UNCOMPRESSED_LENGTH�ENTRY_DELTA_BASE�ENTRY_LINK_REV�
ENTRY_NODE_ID�ENTRY_PARENT_1�ENTRY_PARENT_2� ENTRY_SIDEDATA_COMPRESSED_LENGTH�ENTRY_SIDEDATA_COMPRESSION_MODE�ENTRY_SIDEDATA_OFFSET�REVIDX_ISCENSORED�REVLOGV0�REVLOGV1)�_)�error�mdiff�pycompat�revlogutils�util)�storageutil)�	constants�deltas�cCs�|jtjksJ|j��ddlm}|�|�}t�d|id�}|j|j|j	|j
ddd�}|j|_|j|_|j|_|j
|_
|��D]i}|�|�}|�|�\}	}
||krw|�|||�|�|	|
|tj�|�|�tkrvtd�}td	�}tj||d
��q?|�|�r�|�|�tkr�td�}t�|��|�|�}
n|�|�}
|�|
||�|�|	|
||�|��q?|j|jdd
�|js�|j|j dd
�|j�!|j|j�|js�|j�!|j |j �|�"�|�#�dS)z*censors a revision in a "version 1" revlogr)�revlog�censoredrstmpcensoredT)�target�radix�postfix�
censorables0censored revision stored as delta; cannot censorsEcensoring of revlogs is not fully implemented; please report this bug)�hints:cannot censor due to censored revision having delta storedsstore)�locationN)$�_format_versionrr�r�revr�packmeta�openerr!r"�
_format_flags�
_generaldelta�_parse_index�revs�node�parents�addrawrevision�linkrevr�deltaparentrrr�Abort�
iscensored�_chunk�rawdata�flags�	addbackup�
_indexfile�_inline�	_datafile�rename�clearcaches�
_loadindex)�rl�tr�
censornode�	tombstoner�	censorrev�newrlr)r0�p1�p2�m�h�rawtext�rL�?/usr/lib/python3/dist-packages/mercurial/revlogutils/rewrite.py�	v1_censor6sl
�
�
�
�

�rNcCsF|jtks
J|j��|jtksJ|j��|�|�h}t||||�dS)z*censors a revision in a "version 2" revlogN)r'rrr)�_rewrite_v2)rrBrCrD�censor_revsrLrLrM�	v2_censor�srQc
CsF|jtks
J|j��|jtksJ|j��|j}|j}t�d|id�}t|�}|j|}|jj|}|t	d?}	|�
|�}
tjdd��P}t
||||�}t|||	|
�}
|
��/}|\}}}}}t|t|��D]}||vrrt|||||�qct||||||�qcWd�n1s�wYWd�n1s�wY|jddd�dS)	a[rewrite a revlog to censor some of its content

    General principle

    We create new revlog files (index/data/sidedata) to copy the content of
    the existing data without the censored data.

    We need to recompute new delta for any revision that used the censored
    revision as delta base. As the cumulative size of the new delta may be
    large, we store them in a temporary file until they are stored in their
    final destination.

    All data before the censored data can be blindly copied. The rest needs
    to be copied as we go and the associated index entry needs adjustement.
    r r�sw+b��modeNT)�transaction�	stripping)r'rr�index�_docketrr*�min�
entry_sizer�sidedata_cut_offr�unnamedtempfile�_precompute_rewritten_delta�_setup_new_files�range�len�_rewrite_censor�_rewrite_simple�write)rrBrPrD�	old_index�docket�first_excl_rev�first_excl_entry�index_cutoff�data_cutoff�sidedata_cutoff�tmp_storage�rewritten_entries�	all_files�
open_files�
old_data_file�old_sidedata_file�new_index_file�
new_data_file�new_sidedata_filer)rLrLrMrO�sj

��	�������0rOcCs@t�|�}i}t|�}|j����}t|t|��D]u}||vrq||}	|	t|vr*q|	tdkr9t	ddt
f||<q|j||d�}
tj
|	t|�|	t�|�|	t�|
gt|
�d|	td@d�}|j||||d�}|jj}
t�|
|�\}}|��}|�|jd�|��}|j|||f||<qWd�|S1s�wY|S)u�Compute new delta for revisions whose delta is based on revision that
    will not survive as is.

    Return a mapping: {rev → (new_base, data_start, data_end, compression_mode)}
    r)�_dfN�)r0rGrH�btext�textlen�
cachedeltar9)�excluded_bases�
target_revr)r�
deltacomputerrY�_segmentfile�
_open_readr_r`r
r	rrr8r�revisioninforr0r
rr�
finddeltainforX�default_compression_header�delta_compression�tellrc�data�base)rrd�
excluded_revsrk�dcrlrf�dfhr)�entry�text�info�d�default_comp�	comp_mode�start�endrLrLrMr]�sH

�	��
�$�$r]c	s|j}|j�|���}|j�|����|j�|����|j�|����|j�|����|j�|����t	j
|��d�t	j
���d�t	j
���d�|j�|���|j�|���|j�|����|_�|_
�|_|��|j|d�tj��������fdd��}|S)a+

    return a context manager to open all the relevant files:
    - old_data_file,
    - old_sidedata_file,
    - new_index_file,
    - new_data_file,
    - new_sidedata_file,

    The old_index_file is not here because it is accessed through the
    `old_index` object if the caller function.
    )�nb_bytes)rec3sT�t�d���}t�d��|}t�d��g}t�d��R}t�d��=}|�dtj�|���ks.J�|�dtj�|���ks=J�|�dtj�|���ksLJ�|||||fVWd�n1s^wYWd�n1smwYWd�n1s|wYWd�n1s�wYWd�dSWd�dS1s�wYdS)N�rbzr+br)�open�seek�os�SEEK_ENDr�)rorprqrrrs�rirh�new_data_filepath�new_index_filepath�new_sidedata_filepath�old_data_filepath�old_sidedata_filepathrjrLrM�all_files_openerBs>�����������"�z*_setup_new_files.<locals>.all_files_opener)rXr+�join�index_filepath�
data_filepath�sidedata_filepathrqrrrsr�copyfile�
register_file�	index_end�data_end�sidedata_endr?r@�
contextlib�contextmanager)rrhrirjre�old_index_filepathr�rLr�rMr^s2�r^cCs�|\}}}}	}
||}|td@}|td?}
||vr2|�|
�|t}|�|�}|t}|t}n||\}}}}||}|�|�|�|�}|	��}|	�|�|t}|
��}d|krp|t	}|�|�|�|�}|
�|�|t
}|t}||ks�J||f��tj
||||||t|t|t|t||||d�
}|j�|�|j�|�}|�|�|��|j_|	��|j_|
��|j_dS)z@append a normal revision to the index after the rewritten one(s)rurRr�
r9�data_offset�data_compressed_length�data_uncompressed_length�data_delta_base�link_rev�parent_rev_1�parent_rev_2�node_id�sidedata_offset�sidedata_compressed_length�data_compression_mode�sidedata_compression_modeN)rr�r�readr
rr�rcrrr	rrr�rr
rrrW�append�entry_binaryrXr�r�r�)rrdrmr)rlrkrorprqrrrsr�r9�old_data_offset�
new_data_size�new_datar��d_comp_moder�r��new_data_offset�
sidedata_size�new_sidedata_offset�old_sidedata_offset�new_sidedatar��sd_com_mode�	new_entry�	entry_binrLrLrMrb^st�


�





�
rbcCs�|\}}}}}	||}
t|�}|��}|�|�|
t}
|
t}|
t}tjtj	|||||
|||
t
ddttd�
}|j�
|�|j�|�}|�|�|��|j_|��|j_dS)z&rewrite and append a censored revisionrr�N)r`r�rcrr
rrr�rrrrrWr�r�rXr�r�)rrdrmr)rDrorprqrrrsr�r�r�r�rGrHr�r�rLrLrMra�sD�
�
racCsF|�dd�d�dd�}t|�dkrtd�}||;}t�|��|dS)N�.rr�/rs,cannot recognize filelog from filename: '%s')�rsplit�splitr`rrr5)�path�	path_part�msgrLrLrM� _get_filename_from_filelog_index�s
r�cCsddlm}|�|j|�}|S)zAReturns the filelog for the given `path`. Stolen from `engine.py`r)�filelog)r(r��svfs)�repor�r��flrLrLrM�_filelog_from_filename�sr�cCs�ddlm}|�|j�durd}t�|��|jj}|j|}t	|�}	|d|d|	d<|	d<|j
|	dd��}
|�|�|�|
�dS)zASwaps p1 and p2 and overwrites the revlog entry for `rev` in `fp`r��parsersNz*repo needs to be locked to rewrite parents���)
�purer��_currentlock�_lockrefr�ProgrammingError�IndexObject�index_formatrW�list�packr�rc)r�rAr)�offset�fpr�r�r�r�r��packedrLrLrM�_write_swapped_parents�s


r�c
Cs�ddlm}|j}t|�dksJ�|j}|jtjkr$d|j}t�	|��|j
}|d}td�}	|����z�t
j|j�|�|j�|�|jd�|j|dd	��S}
|jrz|�|
���}|��D]}||vrx|�|�}
t||||
|
�|�|	||f�q\n|jj}|D]}||j}
t||||
|
�|�|	||f�q�Wd
�n1s�wY|j�||�|��|��Wt
�|�nt
�|�wWd
�d
S1s�wYd
S)z�
    Swaps p1 and p2 for all `to_fix` revisions of filelog `fl` and writes the
    new version to disk, overwriting the old one with a rename.
    rr�rz+expected version 1 revlog, got version '%d's.tmp-parents-fixs%repaired revision %d of 'filelog %s'
)�
checkambigsr+rSN) r�r��uir`�_revlogr'rrrr�r;r�uninterruptiblerr�r+r��_checkambigr<�InlinedIndexObjectr�r/�_calculate_indexr�rcr�r��sizer>r?r@�	tryunlink)r�r��to_fixr�r�rAr��
index_file�
new_file_path�repaired_msgr�rWr)r�r�rLrLrM�_reorder_filelog_parentssN




�
��
��
"�r�cs*��fdd�}��fdd�}t||�|�S)Nc��j���S�N)r�r8rL��filerevr�rLrM�<lambda>8�z'_is_revision_affected.<locals>.<lambda>cr�r�)r��
parentrevsrLr�rLrMr�9r�)�_is_revision_affected_inner)r�r��metadata_cache�	full_text�parent_revsrLr�rM�_is_revision_affected7s
�r�cCslz|�}WntjyYdSwt|dd��dk}|dur#|||<|r4|�\}}|tkr4|tkr4dSdS)a�Mercurial currently (5.9rc0) uses `p1 == nullrev and p2 != nullrev` as a
    special meaning compared to the reverse in the context of filelog-based
    copytracing. issue6528 exists because new code assumed that parent ordering
    didn't matter, so this detects if the revision contains metadata (since
    it's only used for filelog-based copytracing) and its parents are in the
    "wrong" order.FNrs
T)r�CensoredNodeError�bytesr)r��parents_revsr�r��raw_text�has_metarGrHrLrLrMr�?s
�
r�c	s`|j���fdd�}��fdd�}��fdd�}��fdd�}��fdd�}t|||||�|�S)Nc�
����Sr�)r6rL�r�rArLrMr�^�
z,_is_revision_affected_fast.<locals>.<lambda>crr�)r4rLrrLrMr�_rcrr�)r7rLrrLrMr�`rcrr�)r8rLrrLrMr�arcrr�)r�rLrrLrMr�br)r�� _is_revision_affected_fast_inner)	r�r�r�r��is_censored�
delta_base�deltar�r�rLrrM�_is_revision_affected_fast\s�r	cCs�|�r	d||<dS|�\}}|tks|tkrdS|�}	|�|	�}
|
dur+t||||�S|�}t|�s4|
Sd}t|�|krCt�td���t�d|d|��\}
}}|
dkr]t||||�}|S|
||<|
S)aGOptimization fast-path for `_is_revision_affected`.

    `metadata_cache` is a dict of `{rev: has_metadata}` which allows any
    revision to check if its base has metadata, saving computation of the full
    text, instead looking at the current delta.

    This optimization only works if the revisions are looked at in order.FN�spatch cannot be decodeds>lllr)	r�getr�r`rr5r�struct�unpack)rrrr�r�r�r�rGrH�delta_parent�parent_has_metadata�chunk�
header_lengthr��_end�_length�is_affectedrLrLrMrns@

��rc

sh|�td�|�|���t|dd��}|���d�D]o}|s q|�dd�\}}t||��t�fdd�|�d	�D��}	t�}
|	D]-}t�|�rSd
}|�|||f�q@td�}|t	�
��|��|f;}|�|�|
�|�q@|	|
}	|	s�td�}|�||�q|s�t
|�t|	��qWd
�n1s�wYWd
�d
SWd
�d
S1s�wYd
S)a
    Fix the revisions given in the `from_report` file, but still checks if the
    revisions are indeed affected to prevent an unfortunate cyclic situation
    where we'd swap well-ordered parents again.

    See the doc for `debug_fix_issue6528` for the format documentation.
    sloading report file '%s'
r�rS�
� rc3s �|]}��t�|��VqdSr�)r)�binascii�	unhexlify)�.0�n�r�rLrM�	<genexpr>�s�
�z_from_report.<locals>.<genexpr>�,�,found affected revision %d for filelog '%s'
s)revision %s of file '%s' is not affected
s*no affected revisions were found for '%s'
N)rcrr�r�r�r��setr��warnr�hexlifyr0�addr��sorted)
r�r��context�from_report�dry_run�f�line�	filenodes�filenamer��excludedr�r�rLrrM�_from_report�s:
�

��P�r,c	#sF�i}t��
��t|t�
��D]�\}}|\���}}��}�
j�|�s-t�|�
jt	d����
�
|���
j���sBt���
jt	d����
�
����
j���sWt���
jt	d����
�
���	�fdd�}��
fdd���fdd����	fdd�}	��������
fdd�}
t|��fd	d�|
|	||�}|r����||��|f}|Vqd
S)z7filter incomind deltas to repaire issue 6528 on the flysunknown parentcst�t@�Sr�)�boolrrL)r9rLrMr��r�z(filter_delta_issue6528.<locals>.<lambda>crr�)r)rL)rrrLrMr��rc��Sr�rLrL)�base_revrLrMr���cs��fSr�rLrL)�p1_rev�p2_revrLrMr��sc	sdt�������}t����dg|��f��}�jdusJ��jr'�jd}n�jd}��||�S)Nrr)r�patchedsizer�rr~�_writinghandlesr<�	buildtext)rw�revinfo�fh)r/rr{r9r0�p1_node�p2_noderrLrMr��s�

z)filter_delta_issue6528.<locals>.full_textcr.r�rLrL)rrLrMr�r0N)rr{�	enumerater`rW�has_noder�LookupErrorr"rr)r)r�deltas_iterr�r)r��linknode�	deltabase�sidedatarr�r�rrL)r/rrr{r9r0r8r1r9r2rrM�filter_delta_issue6528�sf�

��



�	�
�rAFc
s4ddlm�tj���fdd��}|rt|�||��Sg}|���t�fdd��j��D��}|jtd�td�t	|�d	�}	d
}
|D]�\}}|�
d�rO|�j@sPqA|	��t
|�}
t�|
�}t�}i}|��D]M}t�|||�}|r�t||�}||kr�td�}t�|�|��}t�||
|f��|r�d
}|�|||f�d}
�s��r�|�t�|�|���qf|�|�qf|r�t|�}�r�|�|
|f�qAt�||�qA|
r�|�td����r|�rt�dd��}|D]\}}|�dd�|�|f�q�Wd�n1s�wY|	� �Wd�dS1�swYdS)Nr��storec	3s���s�r
dVdS����(����dVWd�n1s!wYWd�dSWd�dS1s9wYdSr�)�wlock�lockrL)r&r��	to_reportrLrMr$-s�
P�z!repair_issue6528.<locals>.contextc3s2�|]\}}}|�d�r|�j@r||fVqdS)�.iN)�endswith�FILEFLAGS_FILELOG)r�	file_typer��_srBrLrMr;s���
�z#repair_issue6528.<locals>.<genexpr>slooking for affected revisionssfilelogs)�unit�totalTrGs)paranoid check failed for '%s' at node %srFs!no affected revisions were found
�wbrSs%s %s
r)!r(rCr�r�r,r��	datafiles�makeprogressrr`rHrI�	incrementr�r�rr/r	r�rr!r0rr5r r"r#r�r�rcr�r��complete)r�r�r&rFr%�paranoidr$�report_entries�files�progress�
found_nothingrJr�r*r�r�r�r��affected�slowr�r0r'rL)r&r�rCrFrM�repair_issue6528(s|����
�

����
$�rZ)rr�)FNNF)4rr�r�rr0rrrrrrr	r
rrr
rrrrrrr�i18nrr(rrrrr�utilsrrrNrQrOr]r^rbrar�r�r�r�r�r�r	rr,rArZrLrLrLrM�<module>s<	H

N
	R5JP3	
0
�@(S�