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/utils/__pycache__/storageutil.cpython-310.pyc
o

�]Lb�C�	@sddlmZddlZddlZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZddlmZddlmZdd	lmZe�e	j�Zd
Zdd�Ze�d
�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"d%dd�Z#dd�Z$dd�Z%dddddej&d d df	d!d"�Z'd#d$�Z(dS)&�)�absolute_importN�)�_)�bin�nullrev�sha1nodeconstants)�dagop�error�mdiff�pycompat)�
repository)�sidedata)�hashutil�cCs^|tjkrt��}|�|�n||kr|}|}n|}|}t�|�}|�|�|�|�|��S)z�Compute the SHA-1 for revision data and its parents.

    This hash combines both the current file contents and its history
    in a manner that makes it easy to distinguish nodes with the same
    content in the revision graph.
    )r�nullid�	_nullhash�copy�updater�sha1�digest)�text�p1�p2�s�a�b�r�=/usr/lib/python3/dist-packages/mercurial/utils/storageutil.py�hashrevisionsha1$s



r�
cCsf|dd�dkr
dSt�|d���}|d|�}i}|��D]}|�dd�\}}|||<q||dfS)z�Parse metadata header from revision data.

    Returns a 2-tuple of (metadata, offset), where both can be None if there
    is no metadata.
    Nrr)NNs: r)�METADATA_RE�search�start�
splitlines�split)rr�mtext�meta�l�k�vrrr�	parsemetaAs
r*cs,t��}d��fdd�|D��}d||fS)z2Add metadata to fulltext to produce revision text.�c3s �|]}d|�|fVqdS)s%s: %s
Nr)�.0r(�r&rr�	<genexpr>Vs�zpackmeta.<locals>.<genexpr>s
%s
%s)�sorted�join)r&r�keys�metatextrr-r�packmetaSsr3cCst|�d}|od|vS)Nrscensored)r*)rr&rrr�iscensoredtextZsr4cCs*|�d�s|S|�dd�}||dd�S)z�Extract just the revision data from source text.

    Returns ``text`` unless it has a metadata header, in which case we return
    a new buffer without hte metadata.
    rrN)�
startswith�index)r�offsetrrr�filtermetadata_s
r8cCsV|�|�dtjkrdSt|�|��d}|r)d|vr)d|vr)|dt|d�fSdS)z�Resolve file revision copy metadata.

    Returns ``False`` if the file has no copy metadata. Otherwise a
    2-tuple of the source filename and node.
    rFscopyscopyrev)�parentsrrr*�revisionr)�store�noder&rrr�filerevisioncopiedlsr=cCsr|�d�r
d|}n|}|�|�\}}t|||�}||krdS|�|�|��r+|dkS|�|�r7|�|�|kSdS)ahDetermines whether file data is equivalent to a stored node.

    Returns True if the passed file data would hash to the same value
    as a stored revision and False otherwise.

    When a stored revision is censored, filedata must be empty to have
    equivalence.

    When a stored revision has copy metadata, it is ignored as part
    of the compare.
    rs

Tr+F)r5r9r�
iscensored�rev�renamed�read)r;r<�filedata�revisiontextrr�computednoderrr�filedataequivalent�s


rEcCs@d}|dur||krd}||7}||kr|}n|}t�|||�S)z)Iterate over revision numbers in a store.rN���)r�xrange)�storelenr"�stop�steprrr�iterrevs�s�rKc	Cst|t�rz|�|�WStyt�d||td���wt|�dvr7z|�|�|WStjy6Ynwt|�dvrSzt	|�}|�|�|WSt
yRYnwz!t|�}d||kr`t�z|�|�WWStt
fyrYnwWnttfyYnwt�||td���)a�Resolve the file node for a value.

    ``store`` is an object implementing the ``ifileindex`` interface.

    ``fileid`` can be:

    * A 20 or 32 byte binary node.
    * An integer revision number
    * A 40 or 64 byte hex node.
    * A bytes that can be parsed as an integer representing a revision number.

    ``identifier`` is used to populate ``error.LookupError`` with an identifier
    for the store.

    Raises ``error.LookupError`` on failure.
    s%dsno match found)�� )�(�@)
�
isinstance�intr<�
IndexErrorr	�LookupErrorr�lenr?r�	TypeError�
ValueError�
OverflowError)r;�fileid�
identifier�rawnoder?rrr�fileidlookup�sJ
��
�
���r[cCs�t�}|d}i}t�}|D]}	||	�}
|
||	<|
|kr!|�|
�q|rZ|d8}|�|�}||kr7|�|�n|�|�||�D]}|tkrW||�}
|
||<|
|krW|�|
�q@|s$||fS)a�Resolve information needed to strip revisions.

    Finds the minimum revision number that must be stripped in order to
    strip ``minlinkrev``.

    Returns a 2-tuple of the minimum revision number to do that and a set
    of all revision numbers that have linkrevs that would be broken
    by that strip.

    ``tiprev`` is the current tip-most revision. It is ``len(store) - 1``.
    ``headrevs`` is an iterable of head revisions.
    ``linkrevfn`` is a callable that receives a revision and returns a linked
    revision.
    ``parentrevsfn`` is a callable that receives a revision number and returns
    an iterable of its parent revision numbers.
    r)�set�add�pop�remover)�
minlinkrev�tiprev�headrevs�	linkrevfn�parentrevsfn�
brokenrevs�
strippoint�heads�futurelargelinkrevs�head�headlinkrev�linkrev�p�plinkrevrrr�resolvestripinfo�s2
�


��rnFc
!
#s �|j}
|j�|dkr�fdd�|D�}n |dkr*�fdd�|D�}t�||j�}nt�fdd�|D��}d	}|	tjks>|rG|�|d
�d
}t�}|D�]@}|t	krTqL|
|�}|�|�\}}|rf||�}nt	}|	tjkrp|}n9|	tj
krxt	}n1|	tjkr�|}n)|t	kr�||vr�|}n|r�|||fvr�|}n|d	ur�|}nt	}n	|d	ur�|}nt	}|t	kr�|r�|||�s�t	}d	}d	}d	}|
�r*|�|�s�|�|�r�z|�
|�}Wntjy�}z	|j}WYd	}~nd	}~ww|t	kr�|r�||�}n8t|�
|��}n0|t	k�r|	tjk�r|�
|�}|�|�n|�r|||�}nt�|�
|�|�
|��}|�|�d	}d}|�rYz|�|�}Wn
tj�yEi}Ynwtj||||d�\}}|�rYt�|�}|�r`||�nd
}d
} |�rv| tO} ||d
|d
@B}|||
|�|
|�|
|�|||||| d�
V|}qLd	S)a	Generic implementation of ifiledata.emitrevisions().

    Emitting revision data is subtly complex. This function attempts to
    encapsulate all the logic for doing so in a backend-agnostic way.

    ``store``
       Object conforming to ``ifilestorage`` interface.

    ``nodes``
       List of revision nodes whose data to emit.

    ``resultcls``
       A type implementing the ``irevisiondelta`` interface that will be
       constructed and returned.

    ``deltaparentfn`` (optional)
       Callable receiving a revision number and returning the revision number
       of a revision that the internal delta is stored against. This delta
       will be preferred over computing a new arbitrary delta.

       If not defined, a delta will always be computed from raw revision
       data.

    ``candeltafn`` (optional)
       Callable receiving a pair of revision numbers that returns a bool
       indicating whether a delta between them can be produced.

       If not defined, it is assumed that any two revisions can delta with
       each other.

    ``rawsizefn`` (optional)
       Callable receiving a revision number and returning the length of the
       ``store.rawdata(rev)``.

       If not defined, ``len(store.rawdata(rev))`` will be called.

    ``revdifffn`` (optional)
       Callable receiving a pair of revision numbers that returns a delta
       between them.

       If not defined, a delta will be computed by invoking mdiff code
       on ``store.revision()`` results.

       Defining this function allows a precomputed or stored delta to be
       used without having to compute on.

    ``flagsfn`` (optional)
       Callable receiving a revision number and returns the integer flags
       value for it. If not defined, flags value will be 0.

    ``deltamode``
       constaint on delta to be sent:
       * CG_DELTAMODE_STD  - normal mode, try to reuse storage deltas,
       * CG_DELTAMODE_PREV - only delta against "prev",
       * CG_DELTAMODE_FULL - only issue full snapshot.

       Whether to send fulltext revisions instead of deltas, if allowed.

    ``nodesorder``
    ``revisiondata``
    ``assumehaveparentrevisions``
    ``sidedata_helpers`` (optional)
        If not None, means that sidedata should be included.
        See `revlogutil.sidedata.get_sidedata_helpers`.
    snodescsg|]}�|��qSrr�r,�n��frevrr�
<listcomp>}�z!emitrevisions.<locals>.<listcomp>slinearcsh|]}�|��qSrrrorqrr�	<setcomp>rtz emitrevisions.<locals>.<setcomp>c3s�|]}�|�VqdS)Nrrorqrrr.�s�z emitrevisions.<locals>.<genexpr>Nr)rr)r;�sidedata_helpersr
r?r)
r<�p1node�p2node�basenode�flags�baserevisionsizer:�deltar
�protocol_flags)r<r?r�	linearize�
parentrevsr/r�CG_DELTAMODE_PREVr\r�CG_DELTAMODE_FULL�CG_DELTAMODE_P1r>�rawdatar	�CensoredNodeError�	tombstonerTr]r
�textdiffr
�sidedatamod�run_sidedata_helpers�serialize_sidedata�CG_FLAG_SIDEDATA)!r;�nodes�
nodesorder�	resultcls�
deltaparentfn�
candeltafn�	rawsizefn�	revdifffn�flagsfn�	deltamode�revisiondata�assumehaveparentrevisionsrv�fnode�revs�prevrev�	availabler?r<�p1rev�p2rev�deltaparentrev�baserevr:r|r{�e�serialized_sidedata�sidedata_flags�old_sidedatar
rzr}rrqr�
emitrevisions(s��Q




��
�
�
�
�
�
��r�cCsrt�d�}t|�|kr
dS||�}t|�|}|d|�t�||�kr%dSd}t|�}||ko8||||�|kS)aRDetermine if a delta represents censored revision data.

    ``baserev`` is the base revision this delta is encoded against.
    ``baselenfn`` is a callable receiving a revision number that resolves the
    length of the revision fulltext.

    Returns a bool indicating if the result of the delta represents a censored
    revision.
    s>lllFNs
censored:)�struct�calcsizerTr
�replacediffheader)r|r��	baselenfn�hlen�oldlen�newlenr]�addlenrrr�deltaiscensoreds
r�)rN))�
__future__r�rer��i18nrr<rrr�rr	r
r�
interfacesr�revlogutilsr
r��utilsrrrrr�r�compiler r*r3r4r8r=rErKr[rn�CG_DELTAMODE_STDr�r�rrrr�<module>sD


%89
�k