403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /usr/lib64/python3.9/site-packages/mercurial/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/lib64/python3.9/site-packages/mercurial/__pycache__/revlog.cpython-39.opt-1.pyc
a

�+�bW��@s�dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
mZmZmZmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd	l,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3dd
l4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;mZm<Z<m=Z=m>Z>ddl?m@Z@m>ZAdd
l<mBZCmDZEmFZFmGZHmIZImJZJmKZKmLZMddlNmOZOmPZPe#e$e&eeee(e)e*e%e'e2e.e1e/e-e0e3e;�Qd�ZRe;�Sd�ZTe;�Sd�ZUe;�Sd�ZVe
jWZXdZYdd�ZZdd�Z[dd�Z\eZe[e\fZ]dd�Z^eVdu�p@e>�_eRd�Z`eA�ae@jb�e5jcdd�Gdd �d ed���ZeeA�ae@jf�e5jcdd!�Gd"d#�d#ed���Zgd$d%�Zhd&d'�Zid(d)�Zje>�_eRd*��r�d+d,�ZkndZkd-d.�Zld/Zmed0�ZnGd1d�ded�ZodS)2z�Storage back-end for Mercurial.

This provides efficient delta storage with O(1) retrieve and append
and O(changes) merge between branches.
�)�absolute_importN�)�bin�hex�nullrev�sha1nodeconstants�short�wdirrev)�_)�getattr)�	ALL_KINDS�CHANGELOGV2�COMP_MODE_DEFAULT�COMP_MODE_INLINE�COMP_MODE_PLAIN�
ENTRY_RANK�FEATURES_BY_VERSION�FLAG_GENERALDELTA�FLAG_INLINE_DATA�INDEX_HEADER�KIND_CHANGELOG�RANK_UNKNOWN�REVLOGV0�REVLOGV1�REVLOGV1_FLAGS�REVLOGV2�REVLOGV2_FLAGS�REVLOG_DEFAULT_FLAGS�REVLOG_DEFAULT_FORMAT�REVLOG_DEFAULT_VERSION�SUPPORTED_FLAGS)�REVIDX_DEFAULT_FLAGS�REVIDX_ELLIPSIS�REVIDX_EXTSTORED�REVIDX_FLAGS_ORDER�REVIDX_HASCOPIESINFO�REVIDX_ISCENSORED�REVIDX_RAWTEXT_CHANGING_FLAGS)�attr)	�ancestor�dagop�error�mdiff�policy�pycompat�revlogutils�templatefilters�util)�
repositoryr1)�deltas�docket�flagutil�nodemap�randomaccessfile�revlogv0�rewrite�sidedata)�storageutil�
stringutil�parsersr)r*�revlogicCs|dfS�NF���rl�textr@r@�6/usr/lib64/python3.9/site-packages/mercurial/revlog.py�ellipsisreadprocessor�srEcCs|dfSr?r@rAr@r@rD�ellipsiswriteprocessor�srFcCsdSr?r@rAr@r@rD�ellipsisrawprocessor�srGcCs"|r|d�|�n
|�|�dS)z}Verify the integrity of the given revlog ``node`` while providing a hook
    point for extensions to influence the operation.�skipreadN)�add�revision)rB�	skipflags�state�noder@r@rD�_verify_revision�srNZBaseIndexObjectT)�slotsc@sheZdZe��Ze��Ze��Ze��Ze��Z	e��Z
e��Ze��Ze��Z
e��Zejdd�ZdS)�revlogrevisiondeltaN��default)�__name__�
__module__�__qualname__r(�ibrMZp1nodeZp2nodeZbasenode�flagsZbaserevisionsizerJ�deltar:Zprotocol_flags�linknoder@r@r@rDrP�srP)�frozenc@s0eZdZejdd�Zejdd�Zejdd�ZdS)�
revlogproblemNrQ)rSrTrUr(rV�warningr+rMr@r@r@rDr[�sr[cCst�||�\}}||fS�N)r=�parse_index2��data�inline�index�cacher@r@rD�parse_index_v1�srdcCstj||td�\}}||fS�N)�format)r=r^rr_r@r@rD�parse_index_v2�srgcCstj||td�\}}||fSre)r=r^r
r_r@r@rD�parse_index_cl_v2�srh�parse_index_devel_nodemapcCst�||�\}}||fSr])r=rir_r@r@rD�parse_index_v1_nodemap�srjcCst||�\}}t�|�|fSr])rd�
rustrevlogZ
MixedIndexr_r@r@rD�parse_index_v1_mixed�srli���sNcannot read from revlog %s;  expected %d bytes from offset %d, data size is %dc@seZdZdZejZd�dd�Zdd�Zd�dd	�Z	d�d
d�Z
ejdd
��Z
ejdd��Zdd�Zejdd��Zejdd��Zdd�Zdd�Zdd�Zd�dd�Zejdd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd�d,d-�Zd.d/�Zd0d1�Z d2d3�Z!d4d5�Z"d6d7�Z#d8d9�Z$d:d;�Z%d<d=�Z&d>d?�Z'd@dA�Z(dBdC�Z)dDdE�Z*dFdG�Z+dHdI�Z,dJdK�Z-dLdM�Z.e.Z/dNdO�Z0dPdQ�Z1dRdS�Z2dTdU�Z3dVdW�Z4d�dXdY�Z5d�dZd[�Z6d\d]�Z7d�d^d_�Z8d�d`da�Z9d�dbdc�Z:d�ddde�Z;d�dfdg�Z<d�dhdi�Z=djdk�Z>dldm�Z?d�dndo�Z@dpdq�ZAdrds�ZBdtdu�ZCdvdw�ZDdxdy�ZEd�dzd{�ZFd|d}�ZGd~d�ZHd�d��ZId�d��ZJd�d�d��ZKd�d��ZLd�d�d��ZMd�d�d��ZNd�d�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d�d��ZTd�d�d��ZUd�d�d��ZVd�d�d��ZWd�d��ZXd�d�d��ZYd�d��ZZd�d�d��Z[d�d��Z\d�d��Z]ejd�d���Z^ejd�d���Z_d�d��Z`ddeaddfd�d��Zbd�d�d��Zcd�d��Zdd�d��Zed�d�d��Zfd�d��Zgd�d��Zhd�d�d��Zid�d„Zjd�dĄZkd�dƄZld�dȄZmd�dʄZnd�d̄Zodddepjqdfd�d΄Zrd�Zsd�Ztd�Zud�ZvhdӣZwdetddfd�dՄZxd�dׄZyd�d�dڄZzd�d܄Z{d�d�dބZ|d�d�Z}dS)�r>ak
    the underlying revision storage object

    A revlog consists of two parts, an index and the revision data.

    The index is a file with a fixed record size containing
    information on each revision, including its nodeid (hash), the
    nodeids of its parents, the position and offset of its data within
    the data file, and the revision it's based on. Finally, each entry
    contains a linkrev entry that can serve as a pointer to external
    data.

    The revision data itself is a linear collection of data chunks.
    Each chunk represents a revision and is usually represented as a
    delta against the previous chunk. To bound lookup time, runs of
    deltas are limited to about 2 times the length of the original
    version data. This makes retrieval of a version proportional to
    its size, or O(1) relative to the number of revisions.

    Both pieces of the revlog are written to in an append-only
    fashion, which means we never need to rewrite a file to insert or
    remove data, and can use some simple techniques to avoid the need
    for locking while reading.

    If checkambig, indexfile is opened with checkambig=True at
    writing, to avoid file stat ambiguity.

    If mmaplargeindex is True, and an mmapindexthreshold is set, the
    index will be mmapped rather than read if it is larger than the
    configured threshold.

    If censorable is True, the revlog can have censored revisions.

    If `upperboundcomp` is not None, this is the expected maximal gain from
    compression for the data content.

    `concurrencychecker` is an optional function that receives 3 arguments: a
    file handle, a filename, and an expected position. It should check whether
    the current position in the file handle is valid, and log/warn/fail (by
    raising).

    See mercurial/revlogutils/contants.py for details about the content of an
    index entry.
    NFcCs||_||_d|_d|_d|_d|_d|_||_||_||_	|	rLt
�|�|_||_||_
||_||_d|_t�d�|_d|_d|_d|_d|_d|_d|_d|_i|_d|_i|_d|_d|_d|_ d|_!d	|_"d
|_#t$t%j&�|_'d|_(d|_)|�*�|
|_+dS)aJ
        create a revlog object

        opener is a function that abstracts the file opening operation
        and can be used to implement COW semantics or the like.

        `target`: a (KIND, ID) tuple that identify the content stored in
        this revlog. It help the rest of the code to understand what the revlog
        is about without having to resort to heuristic and index filename
        analysis. Note: that this must be reliably be set by normal code, but
        that test, debug, or performance measurement code might not set this to
        accurate value.
        N�d)r�iTszlib���Fg�?i),�upperboundcomp�radix�_docket_file�
_indexfile�	_datafile�
_sidedatafile�
_nodemap_file�postfix�_trypending�opener�nodemaputilZget_nodemap_file�target�_checkambig�_mmaplargeindex�_censorable�_revisioncacher1�lrucachedict�_chainbasecacheZ_chunkcache�_chunkcachesize�_maxchainlen�_deltabothparentsrb�_docket�_nodemap_docket�_pcache�_compengine�_compengineopts�_maxdeltachainspan�_withsparseread�
_sparserevlog�hassidedata�_srdensitythreshold�
_srmingapsize�dictr5Zflagprocessors�_flagprocessors�_writinghandles�
_adding_group�
_loadindex�_concurrencychecker)�selfryr{rqrw�
checkambigZmmaplargeindexZ
censorablerpZpersistentnodemapZconcurrencycheckerZ
trypendingr@r@rD�__init__!sNzrevlog.__init__cCs8d}|jj}d|vr$|jtkr$t}nFd|vr2t}n8d|vrTttB}d|vrj|tO}nd|jjvrft	}nt
}d|vr||d|_d|vr�|d|_d	|vr�|d	|_
t|�d
d��|_d|_|jr�t|�d
d��|_d|vr�|d|_d|vr�|d|jd<d|v�r|d|jd<d|v�r$|d|_|j�r>d|v�r>|d}t|�dd��|_t|�dd��}|j�pj||_d|v�r�|d|_d|v�r�|d|_|�d��r�t|jt<t�|�di��D]\}}t� |||j��q�|jdk�r�t!�"t#d�|j��n&|j|jd@�r"t!�"t#d�|j��|�dd�}|||fS)aprocess options (from above/config) to setup associated default revlog mode

        These values might be affected when actually reading on disk information.

        The relevant values are returned for use in _loadindex().

        * newversionflags:
            version header to use if we need to create a new revlog

        * mmapindexthreshold:
            minimal index size for start to use mmap

        * force_nodemap:
            force the usage of a "development" version of the nodemap code
        Nschangelogv2srevlogv2srevlogv1�generaldeltasrevlogv0schunkcachesizesmaxchainlensdeltabothparentss	lazydeltaTFs
lazydeltabases
compengines
zlib.levels
zstd.levelsmaxdeltachainspansmmapindexthresholds
sparse-revlogswith-sparse-readssparse-read-density-thresholdssparse-read-min-gap-sizesenableellipsissflagprocessorsrs0revlog chunk cache size %r is not greater than 0rs.revlog chunk cache size %r is not a power of 2sdevel-force-nodemap)$ry�options�revlog_kindrr
rrrrrrr�r�r��bool�get�
_lazydelta�_lazydeltabaser�r�r�r}r�r�r�r��ellipsisprocessorr�r"r.�	iteritemsr5Zinsertflagprocessorr+�RevlogErrorr
)r��mmapindexthresholdZopts�
new_headerZwithsparseread�flagZ	processor�
force_nodemapr@r@rD�
_init_optsysx













�����zrevlog._init_optsc
Cs z�|�|���}|dur�|j�|�j}||kr�|dur>t||�}|durft�t�|��Wd�WSt�t�||��Wd�WS|dur�|��Wd�WS|�|�Wd�WSWd�n1s�0YWn8t�y}z|j	t	j
k�r�WYd}~dSd}~00dS)zbreturn a file content with or without mmap

        If the file is missing return the empty stringNrn)ry�fstat�st_size�minr1�bufferZmmapread�read�IOError�errno�ENOENT)r��filepathZmmap_threshold�size�fp�	file_size�instr@r@rD�	_get_data�s"
 "<zrevlog._get_datac	Csz|��\}}}|jdur*d|j|jf}n.|jrN|j�d|j�rNd|j}n
d|j}|durp||_||_�nJd}d|_|�	||�}t
|�dkr�t�|dd��d}d|_n|}|d	@|_
|d
@|_t�|j�}|du�rtd�}	|	|j|jf;}	t�|	��n<|j
|@�r>td�}	|j
d
?}
|	|
|j|jf;}	t�|	��t|j}|d|j
�|_|d|j
�|_|d|_|d�s�||_|}n2||_|j�r�t�||�|_ntj|||jd�|_|jdu�r@|j��|_d}|jj}
|
dk�r.|j	|j||
d�}t
|�|
k�r.td�}	|	|jt
|�|
f;}	t�|	��d|_d|_d|_|jdu�rf|j� �|_!|j�"�|_#n,|jdu�r�d|j|_!nd|j|jf|_!t$|_%|j%j&|_&|j�s�d|_'d|_(|j�o�|�o�t)du}d}t*du�r�|jdu�r�d}n|jj+�d�}t,|_-|jt.k�rt/j0|_-nB|jt1k�r*t2|_-n.|jt3k�r>t4|_-n|�rLt)|_-n|�rXt5|_-z�|�-||j�}|\}}|j�o�|jdu�o�t6�7|d�}|�r�t8�9|�}|du�r�|d}t
|d�|j:k�r�|d|j:d|j;k�r�||_<|j=|�Wn,t>t?f�y t�td�|j��Yn0||_@tA�A|j|j�r>|jn|j!|jB|�|_CtA�A|j|j#|jB�|_Dt6�Ed�|_Fi|_GdS)Ns%s.i.%ss%s.i.as%s.irnTr�Fi���s!unknown version (%d) in revlog %ss-unknown flags (%#04x) in version %d revlog %s�sinliner�ssidedatasdocket)Zuse_pending)r�s.too few index data for %s: got %d, expected %ds%s.ds%s.d.%ss
rust.index�update_nodemap_data�sindex %s is corrupted��)Hr�rwrqrxry�existsr�rrZ
_initemptyr��lenr�unpack�
_format_flags�_format_versionr r�r
�
display_idr+r�r�_inline�
_generaldeltar�rs�
docketutilZdefault_docketZparse_docketZindex_filepath�	index_endrvZ
data_filepathrtZsidedata_filepathrur�
nodeconstants�nullidr��_storedeltachainsrjrkr�rdZ_parse_indexrr8Zparse_index_v0rrgr
rhrlr1�safehasattrrz�persisted_dataZtip_revZtip_noder�r��
ValueError�
IndexErrorrbr7r��_segmentfile�_segmentfile_sidedatar��_chaininfocache�_decompressors)r�r4r�r�r�Zentry_pointZ
entry_data�headerZsupported_flags�msgZdisplay_flagZfeaturesZ
index_dataZ
index_sizeZ
devel_nodemapZuse_rust_index�drbZ
chunkcache�use_nodemap�nodemap_datar@r@rDr��s�










�
�

��


�
�

���
��zrevlog._loadindexcCs
|jdS�Nr)r{�r�r@r@rDr��szrevlog.revlog_kindcCs|jS)z;The public facing "ID" of the revlog that we use in message)rqr�r@r@rDr��szrevlog.display_idcCsxz|j|}Wndtyrz&tj�|�}|�|j�}||j|<Wn*tylt�t	d�t
�|���Yn0Yn0|S)Nsunknown compression type %s)r��KeyErrorr1�compenginesZforrevlogheader�revlogcompressorr�r+r�r
�binasciiZhexlify)r��t�
compressor�enginer@r@rD�_get_decompressor�s�zrevlog._get_decompressorcCstj|j}|�|j�Sr])r1r�r�r�r�)r�r�r@r@rD�_compressor�szrevlog._compressorcCs&|jdurdS|jj}|�|�}|jS)zthe default decompressorN)r��default_compression_headerr��
decompress)r�r��cr@r@rD�
_decompressor�s


zrevlog._decompressorcCs|j|jdd�S)z'file object for the revlog's index file�r��mode)ryrsr�r@r@rD�_indexfp�szrevlog._indexfpc
Cs�zF|j|jd|jd�}|jdur0|�dtj�n|�|jjtj�|WSt	y�}z.|j
t
jkrd�|j|jd|jd�WYd}~Sd}~00dS)N�r+)r�r�r�w+)ryrsr|r��seek�os�SEEK_ENDr��SEEK_SETr�r�r�)r��fr�r@r@rDZ__index_write_fp�s
�

�zrevlog.__index_write_fpcCs|j|jd|jdd�S)N�wT)r�r�Z
atomictemp)ryrsr|r�r@r@rDZ__index_new_fp�s�zrevlog.__index_new_fpr�cCs|j|j|d�S)z&file object for the revlog's data filer�)ryrt)r�r�r@r@rD�_datafp�szrevlog._datafpccsJ|jr|jdVn2|�|j��}|VWd�n1s<0YdS)z%file object suitable to read sidedata�N)r�ryru)r�r�r@r@rD�_sidedatareadfp�szrevlog._sidedatareadfpcCst|j�dS�Nr�r�rbr�r@r@rD�tiprev�sz
revlog.tiprevcCs|�|���Sr])rMr�r�r@r@rD�tip�sz
revlog.tipcCsd|kot|�kSSr�)r��r��revr@r@rD�__contains__�szrevlog.__contains__cCs
t|j�Sr]r�r�r@r@rD�__len__�szrevlog.__len__cCstt�t|���Sr])�iterr.Zxranger�r�r@r@rD�__iter__�szrevlog.__iter__rcCstjt|�||d�S)z8iterate over all rev in this revlog (from start to stop)��start�stop)r;Ziterrevsr�)r�r�rr@r@rD�revs�szrevlog.revscCs*z|�|�WdSty$YdS0dS)NTF)r�r��r�rMr@r@rD�hasnode�s

zrevlog.hasnodecCs$|�|�t@s|�|�t@r dSdS)z;whether two revisions (baserev, rev) can be delta-ed or notFT)rWr')r��baserevr�r@r@rD�candelta�s
�zrevlog.candeltacCs.|jdur*|durt�|�nt�||�dSr])rvrzZupdate_persistent_nodemap�setup_persistent_nodemap�r��transactionr@r@rD�
update_caches�s
zrevlog.update_cachescCs�d|_|j��|j��|j��i|_d|_|j�	�|j
oX|jduoXt�
|jd�}|r�t�|�}|dur�|d|_|jj|�dS)Nr�r)rr��clearr��clear_cacher�r�r�rb�clearcachesr�rvr1r�rzr�r�)r�r�r�r@r@rDrs"



��

zrevlog.clearcachesc	Cslz|j�|�WSty"�YnFtjyf||jjksH||jjvrNtj�t�	||j
td���Yn0dS)N�no node)rbr��	TypeErrorr+r�r��wdirid�wdirfilenodeids�WdirUnsupported�LookupErrorr�r
rr@r@rDr�s
�
�z
revlog.revcCst|j|dd?�S)Nrr�)�intrbr�r@r@rDr�*szrevlog.startcCsV|j|d}|dkr|Sd|krR|j|}|ddkrH|d|dS|d8}qdS)N�r�	r�rb)r�r�Z
sd_cut_off�er@r@rD�sidedata_cut_off-s

zrevlog.sidedata_cut_offcCs|j|dd@S)Nrr�rr�r@r@rDrW>szrevlog.flagscCs|j|dSr�rr�r@r@rD�lengthAsz
revlog.lengthcCs|js
dS|j|dS)Nrr)r�rbr�r@r@rD�sidedata_lengthDszrevlog.sidedata_lengthcCs,|j|d}|dkr|S|�|�}t|�S)z?return the length of the uncompressed text for a given revisionr�r)rb�rawdatar�)r�r��lr�r@r@rD�rawsizeIs

zrevlog.rawsizecCs4|�|�}|tjtA@dkr&|�|�St|�|��S)z=length of non-raw text (processed by a "read" flag processor)r)rWr5ZREVIDX_KNOWN_FLAGSr"rr�rJ)r�r�rWr@r@rDr�Rs

zrevlog.sizecCs|j|t}|tkrdS|S)a�Return the rank of a revision if already known, or None otherwise.

        The rank of a revision is the size of the sub-graph it defines as a
        head. Equivalently, the rank of a revision `r` is the size of the set
        `ancestors(r)`, `r` included.

        This method returns the rank retrieved from the revlog in constant
        time. It makes no attempt at computing unknown values for versions of
        the revlog which do not persist the rank.
        N)rbrr)r�r��rankr@r@rD�	fast_rank\szrevlog.fast_rankcCsV|j�|�}|dur|S|j}|}||d}||krH|}||d}q.||j|<|S)N�)r�r�rb)r�r��baserb�iterrevr@r@rD�	chainbasels
zrevlog.chainbasecCs|j|dS)Nr�rr�r@r@rD�linkrev{szrevlog.linkrevcCsBz|j|}Wn"ty0|tkr*tj��Yn0|d|dfS)N���rbr�r	r+r)r�r��entryr@r@rD�
parentrevs~szrevlog.parentrevscCs8z|j|dWSty2|tkr,tj��Yn0dS)Nr�r'r�r@r@rDrM�szrevlog.nodecCs|�|�|�|�Sr])r�rr�r@r@rD�end�sz
revlog.endcCs4|j}||�|�}||dd||ddfS)Nr%r�r&)rbr�)r�rM�ir�r@r@rD�parents�szrevlog.parentscCs|�|�dSr�)�
_chaininfor�r@r@rD�chainlen�szrevlog.chainlencCs�|j}||vr||S|j}|j}|}||}d}d}||dkr�|d7}||d7}|rd|d}n|d8}||vr�||}	||	d7}||	d7}q�||}q6||d7}||f}
|
||<|
S)Nrr r)r�rbr�)r�r�Zchaininfocacherb�generaldeltar"rZclenZcompresseddeltalenr��rr@r@rDr-�s2

zrevlog._chaininfoc	Cs�z|j�|||j�WSty&Yn0g}|j}|j}|}||}||dkr�||kr�|�|�|rp|d}n|d8}||}qD||kr�d}n|�|�d}|��||fS)aWObtain the delta chain for a revision.

        ``stoprev`` specifies a revision to stop at. If not specified, we
        stop at the base of the chain.

        Returns a 2-tuple of (chain, stopped) where ``chain`` is a list of
        revs in ascending order and ``stopped`` is a bool indicating whether
        ``stoprev`` was hit.
        r rTF)rbZ
deltachainr��AttributeError�append�reverse)	r�r��stoprev�chainrbr/r"r�stoppedr@r@rD�_deltachain�s*



zrevlog._deltachaincCsZt|�}|j}|D]}||�qtdur>|jjr>tj}|j}ntj}|j}|||||d�S)z�Generate the ancestors of 'revs' in reverse revision order.
        Does not generate revs lower than stoprev.

        See the documentation for ancestor.lazyancestors for more details.N)r4�	inclusive)	�listrM�rustancestorrb�rust_ext_compatZ
LazyAncestorsr)�
lazyancestors�_uncheckedparentrevs)r�rr4r8Zcheckrevr0r<�argr@r@rD�	ancestors�s
zrevlog.ancestorscCst�||j|j�Sr])r*Zdescendantrevsrr)�r�rr@r@rD�descendants�szrevlog.descendantscs|dur�jg}|dur ���}�fdd�|D�}�fdd�|D�}Gdd�dt�}|��|�����t���|�t�}t�	�fdd�|D��}|r�|�
�}||vr�q�q�|�|���|�D]}|�vr�|�|�q�q�t
|�}|����fd	d�|D�fS)
a�Return a tuple of the ancestors of common and the ancestors of heads
        that are not ancestors of common. In revset terminology, we return the
        tuple:

          ::common, (::heads) - (::common)

        The list is sorted by revision number, meaning it is
        topologically sorted.

        'heads' and 'common' are both lists of node IDs.  If heads is
        not supplied, uses all of the revlog's heads.  If common is not
        supplied, uses nullid.Ncsg|]}��|��qSr@�r���.0�nr�r@rD�
<listcomp>rnz,revlog.findcommonmissing.<locals>.<listcomp>csg|]}��|��qSr@rBrCr�r@rDrFrnc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)z)revlog.findcommonmissing.<locals>.lazysetcSst�|_||_dSr])�set�addedvalues�
lazyvalues)r�rIr@r@rDr�sz2revlog.findcommonmissing.<locals>.lazyset.__init__cSs||jvp||jvSr]�rHrI�r��valuer@r@rDr�sz6revlog.findcommonmissing.<locals>.lazyset.__contains__css4|j}|D]
}|Vq
|jD]}||vr|VqdSr]rJ)r�Zaddedr0r@r@rDr�s
z2revlog.findcommonmissing.<locals>.lazyset.__iter__cSs|j�|�dSr])rHrIrKr@r@rDrI&sz-revlog.findcommonmissing.<locals>.lazyset.addcSs|j�|�dSr])rH�update)r��valuesr@r@rDrM)sz0revlog.findcommonmissing.<locals>.lazyset.updateN)rSrTrUr�r�r�rIrMr@r@r@rD�lazysets
rOc3s|]}|�vr|VqdSr]r@�rDr0)�hasr@rD�	<genexpr>2rnz+revlog.findcommonmissing.<locals>.<genexpr>csg|]}��|��qSr@�rM)rDZmissr�r@rDrF>rn)r��heads�objectr?rIrrMrG�collections�deque�popleftr)r2r9�sort)r��commonrTrO�missingZvisitr0�pr@)rQr�rD�findcommonmissings.



zrevlog.findcommonmissingcCs:|durtg}tdur,|jjr,t�|j|�St�|j|�S)aOReturn an object that can be used to incrementally compute the
        revision numbers of the ancestors of arbitrary sets that are not
        ancestors of common. This is an ancestor.incrementalmissingancestors
        object.

        'common' is a list of revision numbers. If common is not supplied, uses
        nullrev.
        N)rr:rbr;ZMissingAncestorsr)Zincrementalmissingancestorsr))r�rZr@r@rD�incrementalmissingrevs@s
	zrevlog.incrementalmissingrevscCs4|durtg}|dur|��}|j|d�}|�|�S)axReturn the revision numbers of the ancestors of heads that
        are not ancestors of common.

        More specifically, return a list of revision numbers corresponding to
        nodes N such that every N satisfies the following constraints:

          1. N is an ancestor of some node in 'heads'
          2. N is not an ancestor of any node in 'common'

        The list is sorted by revision number, meaning it is
        topologically sorted.

        'heads' and 'common' are both lists of revision numbers.  If heads is
        not supplied, uses all of the revlog's heads.  If common is not
        supplied, uses nullid.N�rZ)r�headrevsr^�missingancestors�r�rZrTZincr@r@rD�findmissingrevsPszrevlog.findmissingrevscsh|dur�jg}|dur ���}�fdd�|D�}�fdd�|D�}�j|d�}�fdd�|�|�D�S)a.Return the ancestors of heads that are not ancestors of common.

        More specifically, return a list of nodes N such that every N
        satisfies the following constraints:

          1. N is an ancestor of some node in 'heads'
          2. N is not an ancestor of any node in 'common'

        The list is sorted by revision number, meaning it is
        topologically sorted.

        'heads' and 'common' are both lists of node IDs.  If heads is
        not supplied, uses all of the revlog's heads.  If common is not
        supplied, uses nullid.Ncsg|]}��|��qSr@rBrCr�r@rDrF|rnz&revlog.findmissing.<locals>.<listcomp>csg|]}��|��qSr@rBrCr�r@rDrF}rnr_csg|]}��|��qSr@rSrPr�r@rDrF�rn)r�rTr^rarbr@r�rD�findmissinghszrevlog.findmissingc
sgggf}|dur:t|�}|s"|St�fdd�|D��}n�jg}t}|tkrz|durz�fdd��D��jgt����fS|dur�t��d}d�i}�n
t|�}|s�|St��t�|d�}t|�}t	�fdd�|D��}|�rN|�
�}|�jkr�qڈ�|�}||kr�|�v�r:��|�|�
�fdd���|�D��q�||vr�|�
|�qڈ�sX|S|tk�r��fd	d�|D�}|�r�t�fd
d�|D��}n|Snt}�jg}t|�}	|	��}g}
�jt	|d�|dd�D�]}��|�}d}|tk�r�d
}n�||	v�rBd
}||v�rzt��|��}|d|	v�s6|d|	v�rz|�|�n8t��|��}|d|	v�sl|d|	v�rz|	�|�d
}|�rЈdu�s�|�v�r�|
�|��du�r�||v�r�d
||<n0�du�r�d
||<��|�D]}|�
|d��qؐq�dd�t�|�D�}t|�}|
||fS)a�Return a topological path from 'roots' to 'heads'.

        Return a tuple (nodes, outroots, outheads) where 'nodes' is a
        topologically sorted list of all nodes N that satisfy both of
        these constraints:

          1. N is a descendant of some node in 'roots'
          2. N is an ancestor of some node in 'heads'

        Every node is considered to be both a descendant and an ancestor
        of itself, so every reachable node in 'roots' and 'heads' will be
        included in 'nodes'.

        'outroots' is the list of reachable nodes in 'roots', i.e., the
        subset of 'roots' that is returned in 'nodes'.  Likewise,
        'outheads' is the subset of 'heads' that is also in 'nodes'.

        'roots' and 'heads' are both lists of node IDs.  If 'roots' is
        unspecified, uses nullid as the only root.  If 'heads' is
        unspecified, uses list of all of the revlog's heads.Ncsg|]}��|��qSr@rBrCr�r@rDrF�rnz'revlog.nodesbetween.<locals>.<listcomp>csg|]}��|��qSr@rSrPr�r@rDrF�rnrFcsg|]}��|��qSr@rBrCr�r@rDrF�rncsg|]}|�jkr|�qSr@)r�)rDr\r�r@rDrF�rncsg|]}|�vr|�qSr@r@�rD�root)r?r@rDrF�rncsg|]}��|��qSr@rBrer�r@rDrF�rnrr�TcSsg|]\}}|r|�qSr@r@)rD�headr�r@r@rDrFrn)r9r�r�rrTr�rGr��fromkeys�max�popr�rIrMr,�copyrrM�tuple�remover2r.r�)
r��rootsrTZnonodesZ	lowestrevZ
highestrevZ
nodestotagrEr0rAZ
orderedoutZisdescendantr\r@)r?r�rD�nodesbetween�s�

�



�








zrevlog.nodesbetweencCs\|dur0z|j��WSty.|��YS0tdurN|jjrNt�|j|�St�||j�Sr])rbr`r1�	_headrevs�	rustdagopr;r*r=r@r@r@rDr`"szrevlog.headrevscCs|j�|�Sr])rbZcomputephasesmapsets)r�rnr@r@rD�
computephases,szrevlog.computephasescCsjt|�}|stgSdg|d}|j}|D],}d||<||}d||d<||d<q*dd�t|�D�S)Nrrr%r&cSsg|]\}}|r|�qSr@r@)rDr0�valr@r@rDrF:rnz$revlog._headrevs.<locals>.<listcomp>)r�rrb�	enumerate)r��countZisheadrbr0rr@r@rDrp/szrevlog._headrevscs�|dur6|dur6t��s �jgS�fdd����D�S|durDt}n
��|�}�fdd�|p^gD�}tj�j�j||d�}�fdd�|D�S)areturn the list of all nodes that have no children

        if start is specified, only heads that are descendants of
        start will be returned
        if stop is specified, it will consider all the revs from stop
        as if they had no children
        Ncsg|]}��|��qSr@rSrPr�r@rDrFGrnz revlog.heads.<locals>.<listcomp>csh|]}��|��qSr@rBrCr�r@rD�	<setcomp>Nrnzrevlog.heads.<locals>.<setcomp>)�startrev�stoprevscsg|]}��|��qSr@rS�rDr�r�r@rDrFTrn)	r�r�r`rr�r*Zheadrevssubsetrr))r�r�rrxrr@r�rDrT<s
�zrevlog.headscCs|g}|�|�}|j|dd�D]X}dd�|�|�D�}|r^|D]}||kr>|�|�|��q>q|tkr|�|�|��q|S)z!find the children of a given noder)r�cSsg|]}|tkr|�qSr@)r)rD�prr@r@rDrF[rnz#revlog.children.<locals>.<listcomp>)r�rr)r2rMr)r�rMr�r\r0Zprevsrzr@r@rD�childrenVs
zrevlog.childrencCs0|�|�|�|�}}|�||�}t�|j|�S)z@calculate all the heads of the common ancestors of nodes a and b)r��_commonancestorsheadsr.ZmaplistrM�r��a�b�ancsr@r@rD�commonancestorsheadsdszrevlog.commonancestorsheadsc	Gs@z|jj|�}Wn*ttfy:tj|jg|�R�}Yn0|S)z7calculate all the heads of the common ancestors of revs)rbr�r1�
OverflowErrorr)r))r�rr�r@r@rDr|js
zrevlog._commonancestorsheadscCs"|�|�|�|�}}|�||�S)zgreturn True if node a is an ancestor of node b

        A revision is considered an ancestor of itself.)r��
isancestorrev�r�r~rr@r@rD�
isancestorrszrevlog.isancestorcCs>|tkrdS||krdS||kr$dSt|j||g|gdd��S)z�return True if revision a is an ancestor of revision b

        A revision is considered an ancestor of itself.

        The implementation of this is trivial but the use of
        reachableroots is not.TF)�includepath)rr��reachablerootsr�r@r@rDr�yszrevlog.isancestorrevc
Cs@z|j�||||�WSty:t�|j||||�YS0dS)zlreturn (heads(::(<roots> and <roots>::<heads>)))

        If includepath is True, return (<roots>::<heads>).N)rbZreachableroots2r1r*Z_reachablerootspurer))r�ZminrootrTrnr�r@r@rDr��s��zrevlog.reachablerootsc	Csj|�|�|�|�}}z|j�||�}Wn&ttfyNt�|j||�}Yn0|rdtt|j	|��S|j
S)z5calculate the "best" common ancestor of nodes a and b)r�rbr?r1r�r)r)r��maprMr�r}r@r@rDr)�szrevlog.ancestorc	Cst|t�r|�|�St|�|jjkrNz|}|�|�|WStjyLYn0zPt|�}d||krht	�|dkr|t|�|}|dks�|t|�kr�t	�|�|�WSt	t
fy�Yn0t|�d|jjk�rzt|�}|�|�|WSttjf�y�Yn0dS)Ns%drr�)
�
isinstancerrMr�r�Znodelenr�r+rr�r�rr)r��idrMr�r@r@rD�_match�s6



z
revlog._matchc	s��jj���}d}zB�j���}|r@��|�r@|r8d}qR|WSn|rLtj�nWdSWn8tjyxt	�dd�std}Ynt
tfy�Yn0|r�t���j
td�����jvr��j�St��dk�r�z�t��d}t�d|d����fdd��jD�}��fd	d�|D�}�jj����r.|��j�t|�d
k�r|t|�dk�rh|�sh|d
�j�<|d
WSt���j
td���|�r�tj�WdSt�y�Yn0dS)NFT�filteredrevssambiguous identifier�(r�cs"g|]}|d���r|d�qS)r�)�
startswith)rDr��prefixr@rDrF�rnz(revlog._partialmatch.<locals>.<listcomp>cs(g|] }t|����r��|�r|�qSr@)rr�rrC)r�r�r@rDrF�srr)r�Zwdirhexr�rbZpartialmatchrr+rr�rr1r��AmbiguousPrefixLookupErrorr�r
r�r�rZnullhexr2r�r)r�r��	maybewdirZ	ambiguous�partialr�nlr@)r�r�r�rD�
_partialmatch�sX
�

�
�zrevlog._partialmatchcCs@|�|�}|dur|S|�|�}|r(|St�||jtd���dS)z{locate a node based on:
        - revision number or str(revision number)
        - nodeid or subset of hex nodeid
        Nsno match found)r�r�r+rr�r
)r�r�rEr@r@rD�lookup�s

z
revlog.lookuprc	s��fdd�}dd��t��}�fdd�}t�dd�s�zt�j���|�}|||�WStjy���jjkr�t�	��j
td	���Ynty�Yn0��jjkr�t
|t|�d
�D] }|d|�}||�r�|Sq�t
|t|�d
�D]&}|d|�}||�r�|||�Sq�dS)z7Find the shortest unambiguous prefix that matches node.csZz��|�}Wn*tjy$YdStjy8YdS0|durVt���jtd���dS)NFTr
)r�r+r�rrr�r
)r�Zmatchednode)rMr�r@rD�isvalidsz revlog.shortest.<locals>.isvalidcSstdd�t�|�D��S)Ncss|]}|dkVqdS)�fNr@)rDr�r@r@rDrRrnz5revlog.shortest.<locals>.maybewdir.<locals>.<genexpr>)�allr.Ziterbytestrr�r@r@rDr�sz"revlog.shortest.<locals>.maybewdircs8t|t|�d�D] }|d|�}�|�s|SqdS)zDisambiguate against wdirid.rN)�ranger�)�hexnode�	minlengthrr�)r�r@rD�disambiguate sz%revlog.shortest.<locals>.disambiguater�Nr
r)rrrirb�shortestr+r�r�rrr�r
r1r�r�)r�rMr�r�r�r�rr�r@)r�rMr�rDr�s0�
zrevlog.shortestcCs |�|�\}}t�|||�|kS)zpcompare text with a given file revision

        returns True if text is different than what is stored.
        )r,r;�hashrevisionsha1)r�rMrC�p1�p2r@r@rD�cmp?sz
revlog.cmpc
Cs�|j}||}t|dd?�}||kr4||d}n ||}t|dd?�|d}|jr�||d|jj7}||d|jj7}||}	||j�||	|�fS)a�Obtain a segment of raw data corresponding to a range of revisions.

        Accepts the start and end revisions and an optional already-open
        file handle to be used for reading. If the file handle is read, its
        seek position will not be preserved.

        Requests for data may be satisfied by a cache.

        Returns a 2-tuple of (offset, data) for the requested range of
        revisions. Offset is the integer offset from the beginning of the
        revlog and data is a str or buffer of the raw byte data.

        Callers will need to call ``self.start(rev)`` and ``self.length(rev)``
        to determine where each revision's data begins and ends.
        rr�r)rbrr��
entry_sizer��
read_chunk)
r�rw�endrev�dfrbZistartr�r*Ziendrr@r@rD�_getsegmentforrevsGszrevlog._getsegmentforrevscCsl|j|d}|j|||d�d}|tkr.|S|tkr@|�|�S|tkrR|�|�Sd}||;}t�|��dS)a<Obtain a single decompressed chunk for a revision.

        Accepts an integer revision and an optional already-open file handle
        to be used for reading. If used, the seek position of the file will not
        be preserved.

        Returns a str holding uncompressed data for the requested revision.
        �
�r�r�unknown compression mode %dN)	rbr�rrr�rr�r+r�)r�r�r��compression_moder`r�r@r@rD�_chunkis	

z
revlog._chunkc	s�|sgS�j}�j}�j}�jj}tj}g}	|	j}
�js@|f}nt	j
�||d�}|D�]&}|d}
|ddd�D]}||�dkrpq�qpz�j|
|�d�\}}Wn*ty���fdd�|D�YS0�j
}�j}|D]�}||�}|r�||d|7}||�}�j|d	}|||||�}|tk�r4|
|�q�|tk�rL|
||��q�|tk�rd|
||��q�d
}||;}t�|��q�qT|	S)a�Obtain decompressed chunks for the specified revisions.

        Accepts an iterable of numeric revisions that are assumed to be in
        ascending order. Also accepts an optional already-open file handle
        to be used for reading. If used, the seek position of the file will
        not be preserved.

        This function is similar to calling ``self._chunk()`` multiple times,
        but is faster.

        Returns a list with decompressed data for each requested revision.
        )�
targetsizerNror�csg|]}�j|�d��qS)r�)r�ry�r�r�r@rDrF�rnz"revlog._chunks.<locals>.<listcomp>rr�r�)r�rr�rbr�r1r�r2r��	deltautilZ
slicechunkr�r�r�r�rrrr+r�)r�rr�r�r�rraZiosizer�rZladdZslicedchunksZ	revschunkZfirstrevZlastrev�offsetr`�decompZ
def_decompr�Z
chunkstartZchunklengthZ	comp_moder�r�r@r�rD�_chunkssT
�




zrevlog._chunkscCs0|j|d}||krtS|jr$|S|dSdS)z(return deltaparent of the given revisionr rN)rbrr�)r�r�r!r@r@rD�deltaparent�szrevlog.deltaparentcCs�|js|�|�tkSt�|jd�r6|jj|_|�|�S|tkrBdS|j|}|d}||kr`dS|tkrldS|d}|d}||ks�||kr�dS|�|�S)ztells whether rev is a snapshots
issnapshotTr r%r&F)r�r�rr1r�rb�
issnapshot)r�r�r(r!r�r�r@r@rDr��s$


zrevlog.issnapshotcCs*|�|�st�d��t|�|�d�dS)z/number of snapshot in the chain before this onesrevision %d not a snapshotrr)r�r+�ProgrammingErrorr�r7r�r@r@rD�
snapshotdepth�s

zrevlog.snapshotdepthcCs<|tkr$|�|�|kr$t|�|��St�|�|�|�|��S)z�return or calculate a delta between two revisions

        The delta calculated is in binary form and is intended to be written to
        revlog data directly. So this function needs raw revision data.
        )rr��bytesr�r,Ztextdiffr)r�Zrev1Zrev2r@r@rD�revdiff�szrevlog.revdiffcCs|�||�S)z�return an uncompressed revision of a given node or revision
        number.

        _df - an existing file handle to read from. (internal-only)
        ��
_revisiondata�r��	nodeorrev�_dfr@r@rDrJ�szrevlog.revisioncCs$t|t�r|}n
|�|�}|�|�S)z�a map of extra data related to the changeset but not part of the hash

        This function currently return a dictionary. However, more advanced
        mapping object will likely be used in the future for a more
        efficient/lazy code.
        )r�rr��	_sidedata)r�r�r�r�r@r@rDr:�s

zrevlog.sidedatacCs�t|t�r|}|�|�}n|}d}||jkr0dS|j|||d�\}}}|rR|rR|S|durd|�|�}|�|�}|r~|tkr~|S|r�t�	|||�}	|}
nt�
|||�}|\}
}	|	r�|j|
||d�|s�|||f|_|
S)Nrn)r�rB)
r�rrMr��_rawtextr�rWr!r5ZprocessflagsrawZprocessflagsread�	checkhashr)r�r�r��rawr�rM�rawtextZ	validatedrW�validatehashrCr0r@r@rDr�
s2



zrevlog._revisiondatacCs�d}d}|jr6|jd|kr,||jddfS|jd}|durH|�|�}|j||d�\}}|rh|jd}d|_d}|j|d}	d|	kr�d|	}|j|||d�}
|dur�t|
d�}|
dd�}
t�||
�}~||d	fS)
zjreturn the possibly unvalidated rawtext for a revision

        returns (rev, rawtext, validated)
        Nrr�Tr)r4r�)r�r�F)rr�r7rbr�r�r,Zpatches)r�rMr�r�Z	cachedrevZbasetextr5r6r�rZbinsr�r@r@rDr�6s.


zrevlog._rawtextcCs�|j|}|d}|d}|jr4||jjd|7}|dkr@iS|jj||kr�|j}|jj}|}|}t||||f}	t�|	��|j	�
||�}
|j|d}|tkr�|
}n>|tkr�|�
|
�}n*|tkr�|�|
�}nd}
|
|;}
t�|
��t�|�}|S)z0Return the sidedata for a given revision number.rrrr�r�)rbr�r�r��sidedata_endru�FILE_TOO_SHORT_MSGr+r�r�r�rrr�rr��sidedatautilZdeserialize_sidedata)r�r�Zindex_entry�sidedata_offsetZ
sidedata_size�filenamer*r�r�mZcomp_segment�compZsegmentr�r:r@r@rDr�as:

�

zrevlog._sidedatacCs|j||dd�S)z�return an uncompressed raw data of a given node or revision number.

        _df - an existing file handle to read from. (internal-only)
        T)r�r�r�r@r@rDr�szrevlog.rawdatacCst�|||�S)zyCompute a node hash.

        Available as a function so that subclasses can replace the hash
        as needed.
        )r;r�)r�rCr�r�r@r@rD�hash�szrevlog.hashcCs�z�|dur |dur |�|�\}}||�|||�kr�|jrL|jd|krLd|_|}|durft�t|��}t�td�|j	t
�|�f��Wn6tjy�|jr�t
�|�r�t�|j	||���Yn0dS)z�Check node hash integrity.

        Available as a function so that subclasses can extend hash mismatch
        behaviors as needed.
        Nrsintegrity check failed on %s:%s)r,r�rr0rrr+r�r
r�r.Zbytestrr~r;Ziscensoredtext�CensoredNodeError)r�rCrMr�r�r�Z	revornoder@r@rDr��s$��zrevlog.checkhashc	Cs�t|�d}|�|�|�|�}|jr.|tkr2dS|�|j�}|durZt�t	d�|j��d}|�
|jd�d}|jdur�d}|jd}|�
�|��d|_d|j_|�d�}|�d��z�|���b}	|D]D}
|�|j|
|
|	d�d�|dur�||�|
�|
|jjkr�|
}q�|�
�Wd�n1�s00Y|du�rHd}|����}|jtM_d|_|D]R}|j�|�}|dk�r�|jdu�r�|j|jB}
|j�|
�}
|
|}|�|��ql|jdu�r�|��|j_ |�!|j|�|��Wd�n1�s0Y|�!|j||jj�t"�#||�t$�$|j%|j|j&�|_|�rj|�'�}||df|_||j_d}W|du�r�|��n|du�r�|��0dS)	aCheck if the revlog is too big for inline and convert if so.

        This should be called after revisions are added to the revlog. If the
        revlog has grown too large to be an inline revlog, it will convert it
        to use multiple index and data files.
        rNs%s not found in the transactionrFTr�r�)(r�r�rr��
_maxinlineZ
findoffsetrsr+r�r
rIrtr��flush�closer��writing_handler��truncater��writer�rbr��_revlog__index_new_fpr�r�entry_binaryr�r��pack_header�tellr��replacerzrr7ryr��_revlog__index_write_fp)r��trr�Z
total_sizeZtroffsetZtrindexZexisting_handlesr�Znew_dfhZread_ifhr0r+rr��ifhr@r@rD�_enforceinlinesize�s��




���(

4�

�
zrevlog._enforceinlinesizecCsdS)z0called when trying to add a node already stored.Nr@)r�rrMr@r@rD�_nodeduplicatecallbackszrevlog._nodeduplicatecallbackc	cs^|j���@|j���dVWd�n1s20YWd�n1sP0YdS)zCContext manager that keeps data and sidedata files open for readingN)r��readingr�r�r@r@rDr�szrevlog.readingc

cs�|jrd}||j;}t�|��|jdur2dV�njd}}}�zt|�}d}|r`|�|d�}d}|js�z:|�d�}|j	dur�|�
dtj�n|�
|j	j
tj�Wn<ty�}z$|jtjkr‚|�d�}WYd}~n
d}~00|�|j|�|jdu�r|z&|j|jdd�}|�
|j	jtj�WnFt�yh}z,|jtjk�rD�|j|jdd�}WYd}~n
d}~00|�|j|j	j�||jj}	|��}|j�r�|�|j||	�n|�|j|	�|||f|_|j�r�|n||j_||j_dV|j	du�r�|�|�Wd|_d|j_d|j_|du�r(|��|du�r:|��|du�r�|��nNd|_d|j_d|j_|du�rv|��|du�r�|��|du�r�|��0dS)Ns)try to write in a `trypending` revlog: %srrr�r�r�) rxr�r+r�r�r�r*r�r�r�r�r�r��data_endr�r�r�r�rIrtruryr�rbr�r�rsr�r�r��
_write_docketr�)
r�rr�r��dfh�sdfhr0Zdsizer�Zisizer@r@rD�_writings�





 &
�



�


zrevlog._writingcCs|j�|�dS)z�write the current docket on disk

        Exist as a method to help changelog to implement transaction logic

        We could also imagine using the same transaction logic for all revlog
        since docket are cheap.N)r�r�rr@r@rDr�cszrevlog._write_docketcCs�|tkrt�td�|j��|
dur*i}
n|
rB|jsBt�td���|rX|pV|�|||�}t�	|||�\}}||krvd}t
|�tkr�t�td�|jt
|�f��|p�|�|||�}|j�
|�}
|
dur�|
S|r�|j||||d�|j|||||||||	|
d�
S)a�add a revision to the log

        text - the revision data to add
        transaction - the transaction object used for rollback
        link - the linkrev data to add
        p1, p2 - the parent nodeids of the revision
        cachedelta - an optional precomputed delta
        node - nodeid of revision; typically node is not specified, and it is
            computed by default as hash(text, p1, p2), however subclasses might
            use different hashing method (and override checkhash() in such case)
        flags - the known flags to set on the revision
        deltacomputer - an optional deltacomputer instance shared between
            multiple calls
        s!attempted to add linkrev -1 to %sNs9trying to add sidedata to a revlog who don't support thems;%s: size of %d bytes exceeds maximum revlog storage of 2GiB)r�r�)�
cachedelta�
deltacomputerr:)rr+r�r
r�r�r�r�r5Zprocessflagswriter��
_maxentrysizerb�get_revr��addrawrevision)r�rCr�linkr�r�r�rMrWr�r:r�r�r�r@r@rD�addrevisionlsR�
�����zrevlog.addrevisionc
CsL|�|��.|j|||||||||	|
d�
Wd�S1s>0YdS)z�add a raw revision with known flags, node and parents
        useful when reusing a revision not stored in this revlog (ex: received
        over wire, or read from an external bundle).
        �r�r:N)r��_addrevision)r�r�rr�r�r�rMrWr�r�r:r@r@rDr��s�zrevlog.addrawrevisioncCsD|sd|fS|j�|�}|r$d|fS|dd�dkr<d|fSd|fS)z6Generate a possibly-compressed representation of data.rnrr��u)r��compress)r�r`�
compressedr@r@rDr��szrevlog.compressc
Cs�|s|S|dd�}|dkrhz
t|�WStjyd}z$t�td�t�|���WYd}~q�d}~00n |dkrt|S|dkr�t�|d�S|�	|�}|�
|�S)z�Decompress a revlog chunk.

        The chunk is expected to begin with a header identifying the
        format type so it can be routed to an appropriate decompressor.
        rr�xsrevlog decompress error: %sNr�r�)�_zlibdecompress�zlibr+r�r
r<�forcebytestrr1r�r�r�)r�r`r�rr�r@r@rDr��s$
��
zrevlog.decompressc(Cs�||jkrt�td�|j��||jjks6||jjvrJt�td�|j��|jdurbd}t�	|��|j
rt|jd}
n
|jd}
|g}t|�}|d}|�|�}|j
r�|j\}}}|j
r�|�
||j|||jj�n(|�
||j||jj�|�
||j|�|�|�|�|�}}|du�r:t�t�||d�|d�}nt|�}|
du�rVt�|�}
t�|||||||�}|
�||
�}t}|jdu�r�|jj}t�||�}|\}}t}|�r2|j �r2t!}t"�#|�}|jj$}|�%|�\} }!| dk�r:|!dd�dk�r:t|!�t|�k�r:|!dd�|jjk�r(t&}|!}nt}|!}nd	}d}t'}"|j(t)k�r�||ft*t*fk�rbd}"n�|t*k�r�|t*k�r�d|�+|�}"nd|t*k�r�|t*k�r�d|�+|�}"n@t,||f�\}#}$d|�+|$�}"|"t-d
d�|�.|$g|#g�D��7}"tj/|||j0|||j1|||||t|�||"d�}%|j�2|%�|j�3|�}&|dk�rf|jdu�rf|j4|j(B}'|j�5|'�}'|'|&}&|�6||&|j7||||�|d}|	�r�|du�r�|
�8||
�}t9|�t:k�r�|||f|_;|j<|j=|<|S)
a�internal function to add revisions to the log

        see addrevision for argument descriptions.

        note: "addrevision" takes non-raw text, "_addrevision" takes raw text.

        if "deltacomputer" is not provided or None, a defaultdeltacomputer will
        be used.

        invariants:
        - rawtext is optional (can be None); if not set, cachedelta must be set.
          if both are set, they must correspond to each other.
        s %s: attempt to add null revisions %s: attempt to add wdir revisionN�1adding revision outside `revlog._writing` contextrrr�r�rncss|]
}dVqdS)rNr@)rDr
r@r@rDrR�	rnz&revlog._addrevision.<locals>.<genexpr>)rWZdata_offsetZdata_compressed_lengthZdata_uncompressed_lengthZdata_compression_modeZdata_delta_baseZlink_revZparent_rev_1Zparent_rev_2Znode_idr�Zsidedata_compressed_length�sidedata_compression_moder)>r�r+r�r
r�r�rrr�r�r�r��_get_data_offsetr�rsrbr�rtr�r,Zpatchedsizer>r�r�r�r/ZrevisioninfoZ
finddeltainforr�r�Zdelta_compressionr�rr��serialize_sidedatar�r�rrr�r
rr�sorted�sumrcr(Zdeltalenr!r2r�r�r��_writeentryr`Z	buildtext�typer�rr#r�)(r�rMr�rr�r�r�rWr��alwayscacher�r:r�ZfhZbtext�curr�prevr�r�r�r�Zp1rZp2rZtextlenZrevinfoZ	deltainfor�Zdefault_compr0r��serialized_sidedatar��h�
comp_sidedatarZpminZpmaxrr(r�r@r@rDr�	s�
�
�
��



��
�

�

���
��"��
zrevlog._addrevisioncCs |jdur|�|�S|jjSdS)aReturns the current offset in the (in-transaction) data file.
        Versions < 2 of the revlog can get this 0(1), revlog v2 needs a docket
        file to store that information: since sidedata can be rewritten to the
        end of the data file within a transaction, you can have cases where, for
        example, rev `n` does not have sidedata while rev `n - 1` does, leading
        to `n - 1`'s sidedata being written after `n`'s data.

        TODO cache this in a docket file before getting out of experimental.N)r�r*r�)r�r�r@r@rDr��	s	

zrevlog._get_data_offsetcCs�|jdurd}t�|��|j\}	}
}|jdur>|	�dtj�n|	�|jjtj�|
r�|jdurn|
�dtj�n|
�|jj	tj�|r�|�|jj
tj�t|�d}|j�s"|�
|j|�|jr�|�
|j|�|�
|j|t|��|dr�|
�|d�|
�|d�|�r|�|�|	�|�nN|||jj7}|�
|j|�|	�|�|	�|d�|	�|d�|�|�|jdu�r�|jd}
|jd}|jd}|
��|j_|��|j_	|��|j_
t�||�dS)Nr�rrr�)r�r+r�r�r�r�r�r�r�r�r�r�r�rIrtrursr�rbr�r�r�rzr)r�rr(r`r�r�r:r�r�r�r�r�r�Zwh1Zwh2Zwh3r@r@rDr��	sN









zrevlog._writeentrycCs�|jrt�d��d|_d}�z�|�|����t�|�}|D�]l}	|	\}
}}}
}}}}||
�}|pbt}|j�|
�}|dur�|�	||�|r�|||�d}q:||fD]$}|j�
|�s�t�||jt
d���q�|j�
|�s�t�||jt
d���|�|�}|tk�rT|�|��rTt�d�}|�|�}t|�|}|d|�t�||�k�rTt�|j|�|���|�sp|�||��rp|tO}|j|
d|||||||f|||d�}|�r�|||�d}q:Wd�n1�s�0YWd|_nd|_0|S)	a\
        add a delta group

        given a set of deltas, add them to the revision log. the
        first delta is against its parent, which should be in our
        log, the rest are against the previous delta.

        If ``addrevisioncb`` is defined, it will be called with arguments of
        this revlog and the node that was added.
        scannot nest addgroup() callsTNFsunknown parentsunknown delta bases>lll)r�r�r:)r�r+r�r�r�r�r!rbr�r�Zhas_noderrqr
r�r�r�
iscensored�struct�calcsizerr�r,ZreplacediffheaderZCensoredBaseErrorrM�_peek_iscensoredr&r�)r�r3Z
linkmapperrr��
addrevisioncbZduplicaterevisioncb�emptyr�r`rMr�r�rYZ	deltabaserXrWr:r�r�r\rZhlenZoldlenZnewlenr@r@rD�addgroup&
s�



�
��


��	�
(zrevlog.addgroupcCs|js
dS|�|�t@S)z%Check if a file revision is censored.F)r~rWr&r�r@r@rDr�
szrevlog.iscensoredcCs|js
dSt�|||j�S)z6Quickly check if a delta produces a censored revision.F)r~r;Zdeltaiscensoredr)r�rrXr@r@rDr�
szrevlog._peek_iscensoredcCs"t�|t|�d|��|j|j�S)z�find the minimum rev that must be stripped to strip the linkrev

        Returns a tuple containing the minimum rev and a set of all revs that
        have linkrevs that will be broken by this strip.
        r)r;Zresolvestripinfor�r`r$r))r��minlinkr@r@rD�
getstrippoint�
s
�zrevlog.getstrippointcCs�t|�dkrdS|�|�\}}|t|�kr.dS|�|�}|jsZ|�|j|�||jj}n|||jj}|jr�|�	|�}|�|j|�|�|j
|�|jdur�||j_||j_
||j_|jj|dd�d|_t�d�|_|j��|j��|j|d�=dS)a7truncate the revlog on the first revision with a linkrev >= minlink

        This function is called when we're stripping revision minlink and
        its descendants from the repository.

        We have to remove all revisions with linkrev >= minlink, because
        the equivalent changelog revisions will be renumbered after the
        strip.

        So we truncate the revlog on the first of these revisions, and
        trust that the caller has saved the revisions that shouldn't be
        removed and that it'll re-add them after this truncation.
        rNT)Z	strippingr�ro)r�rr�r�rIrtrbr�rurrsr�r�r�r�r�rr1r�r�r�rr�)r�r
rr�r
r�r*r�r@r@rD�strip�
s0




zrevlog.stripc
Cs~d}t|�r$td|�t|�d��}zJ|���&}|�dtj�|��}Wd�n1sZ0Y||}Wn6ty�}z|j	t	j
kr��d}WYd}~n
d}~00z�|�|j�}|�dtj�|��}|�
�|jj}td||�}|||}|j�r8d}	|D]}
|	td|�|
��7}	�qd}|t|�||	}Wn:t�yt}z |j	t	j
k�r\�d}WYd}~n
d}~00||fS)z�Check size of index and data files

        return a (dd, di) tuple.
        - dd: extra bytes for the "data" file
        - di: extra bytes for the "index" file

        A healthy revlog will return (0, 0).
        rrN)r�rir*r�r��ior�r�r�r�r�ryrsr�rbr�r�r)r�Zexpectedr��actual�ddr��sr+�diZ	databytesr0r@r@rD�	checksize�
s>	
&zrevlog.checksizecCs�|jg}|jdur&|js�|�|j�np|�|j�|�|jjdd��|jjrZ|�|j�|�|jj	dd��|jj
r�|�|j�|�|jjdd��|S)NF)Z
include_empty)
rsrrr�r2rt�extendr�Zold_index_filepathsr�Zold_data_filepathsr�ruZold_sidedata_filepaths)r��resr@r@rD�files
s
zrevlog.filescCsl|dvrt�d|��|dur(|js(d}|js>|tjkr>tj}tj|||t	|j
|j|j|j
|j||||d�
S)N)snodes�storageslinearNs"unhandled value for nodesorder: %sr)	Z
deltaparentfnZ
candeltafnZ	rawsizefnZ	revdifffnZflagsfn�	deltamode�revisiondata�assumehaveparentrevisions�sidedata_helpers)r+r�r�r�r2ZCG_DELTAMODE_PREVZCG_DELTAMODE_FULLr;�
emitrevisionsrPr�rrr�rW)r�ZnodesZ
nodesorderrrrrr@r@rDrs4	����zrevlog.emitrevisions�always�samerevs�never�fulladd>rrrrc
Cs||jvrttd�|��t|�r.ttd���t|dd�rFttd���t|dd�r^ttd���|j}|j}|j}	zz||jkr�d|_d|_n.||j	kr�d|_d|_n||j
kr�d|_d|_|p�|	|_|�||||||�W||_||_|	|_n||_||_|	|_0dS)	a]Copy this revlog to another, possibly with format changes.

        The destination revlog will contain the same revisions and nodes.
        However, it may not be bit-for-bit identical due to e.g. delta encoding
        differences.

        The ``deltareuse`` argument control how deltas from the existing revlog
        are preserved in the destination revlog. The argument can have the
        following values:

        DELTAREUSEALWAYS
           Deltas will always be reused (if possible), even if the destination
           revlog would not select the same revisions for the delta. This is the
           fastest mode of operation.
        DELTAREUSESAMEREVS
           Deltas will be reused if the destination revlog would pick the same
           revisions for the delta. This mode strikes a balance between speed
           and optimization.
        DELTAREUSENEVER
           Deltas will never be reused. This is the slowest mode of execution.
           This mode can be used to recompute deltas (e.g. if the diff/delta
           algorithm changes).
        DELTAREUSEFULLADD
           Revision will be re-added as if their were new content. This is
           slower than DELTAREUSEALWAYS but allow more mechanism to kicks in.
           eg: large file detection and handling.

        Delta computation can be slow, so the choice of delta reuse policy can
        significantly affect run time.

        The default policy (``DELTAREUSESAMEREVS``) strikes a balance between
        two extremes. Deltas will be reused if they are appropriate. But if the
        delta could choose a better revision, it will do so. This means if you
        are converting a non-generaldelta revlog to a generaldelta revlog,
        deltas will be recomputed if the delta's parent isn't a parent of the
        revision.

        In addition to the delta policy, the ``forcedeltabothparents``
        argument controls whether to force compute deltas against both parents
        for merges. By default, the current default is used.

        See `revlogutil.sidedata.get_sidedata_helpers` for the doc on
        `sidedata_helpers`.
        s value for deltareuse invalid: %ssdestination revlog is not emptyr�Ns$source revlog has filtered revisionss)destination revlog has filtered revisionsTF)�
DELTAREUSEALLr�r
r�rr�r�r��DELTAREUSEALWAYS�DELTAREUSESAMEREVS�DELTAREUSENEVER�_clone)
r�r��
destrevlogr�
deltareuse�forcedeltabothparentsrZoldlazydeltaZoldlazydeltabaseZoldamdr@r@rD�cloneLsL5

�



�
�zrevlog.clonecCs�t�|�}|j}|D�]�}	||	}
|
dd@}|
d}||
dd}
||
dd}|
d}d}d}||jkr�|�|	�}|�|	�}|dur�t�||||	�\}}||d|d@B}|j||||
||||||d	�
n�|j	�r|�
|	�}|tk�r|t|�
|	��f}d}|�s"|�|	�}|�|	�}|du�r6|�|	�}|du�rjt�||||	�\}}||d|d@B}|�|��.|j|||||
|||||d
�
Wd�n1�s�0Y|r|||	|�qdS)zBperform the core duty of `revlog.clone` after parameter processingrr�r�r%r�r&Nr)r�rMrWr�r:r�)r�r�rb�DELTAREUSEFULLADDr�r:r��run_sidedata_helpersr�r�r�rr�r�r�r�)r�r�r%rr&r'rr�rbr�r(rWr$r�r�rMr�r�rCr:Z	new_flagsZdpr@r@rDr$�sz





��







��&
z
revlog._clonerncCsP|jtkr t�td�|j��n,|jtkr<t�||||�nt�||||�dS)Ns%cannot censor with version %d revlogs)	r�rr+r�r
rr9Z	v1_censorZ	v2_censor)r�r�Z
censornodeZ	tombstoner@r@rD�censorrevisions
��
zrevlog.censorrevisionccs�|��\}}|r$ttd�|d�V|r<ttd�|d�V|j}||dkrnttd�|j||dfd�Vt�|d<t�|d<|D�]}|�|�}zj|�d	d
�}|r�||�|�M}t	||||�|�
|�}t|�|��}	||	kr�ttd�|	|f|d�VWq�t
j�y@|d
�r<ttd�|d�V|d�|�Yq�t�y�}
z>ttd�t|�t�|
�f|d�V|d�|�WYd}
~
q�d}
~
00q�dS)z�Verifies the integrity of the revlog.

        Yields ``revlogproblem`` instances describing problems that are
        found.
        sdata length off by %d bytes)r+sindex contains %d extra bytessexpectedversions0warning: '%s' uses revlog format %d; expected %d)r\rHssafe_renameds	skipflagsrs unpacked size is %d, %d expected)r+rMserroroncensoredscensored file datasunpacking %s: %sN)rr[r
r�r�rGrMr�rWrNrr�rr+r�rI�	Exceptionrr<r�)r�rLrr�versionr�rMrK�l1�l2rr@r@rD�verifyintegritysT��



2
�
���zrevlog.verifyintegritycs�i}|r6�j�jfg|d<�js6|d��j�jf�|rBg|d<|rRt��|d<|rntt�jt	����|d<|r�t�fdd���
�D��|d<|S)Nsexclusivefilesssharedfilessrevisionscountstrackedsizec3s|]}�j�|�jVqdSr])ry�statr�)rD�pathr�r@rDrR�sz%revlog.storageinfo.<locals>.<genexpr>s
storedsize)ryrsr�r2rtr�r�r�rr�r)r�ZexclusivefilesZsharedfilesZrevisionscountZtrackedsizeZ
storedsizer�r@r�rD�storageinfoxs �zrevlog.storageinfocCs<|js
dS|ds|dsdSg}|�|����|j\}}}|�|jjtj�|��}	t	||d�D�]"}
|j
|
}tj||i|
d�\}}
t�
|�}t}|r�|jr�t}|�|�\}}|dkr�|ddkr�t|�t|�kr�|d|jjkr�t}|}nt}|}|ddk�s|ddk�r$d	}t�|��|d|
d|
d@B}|	t|�||f}|�|	tj�|�|�|�|�|	t|�7}	|��|j_qd|�||j
j�t|�D]r\}}||}
|j
j|
g|�R�|j
�|
�}|
dk�r
|jdu�r
|j|jB}|j
�|�}||}|�|��q�Wd�n1�s.0YdS)
Nrr�)�storerr:r�r�rr�rrs0rewriting existing sidedata is not supported yet)r�r�r�r�r�r�r�r�r�r�rbr�r*r�rrr�r�r�rr+ZAbortr�r2r�rtZreplace_sidedata_infor�r�r�r�)r�rZhelpersrwr�Znew_entriesr�r�r�Zcurrent_offsetr�r(Znew_sidedatarWrr�rrr�Znew_offset_flagsZentry_updater+rZpackedr�r@r@rD�rewrite_sidedata�s|
�
�
�
����
�

zrevlog.rewrite_sidedata)NFFFNFNF)N)N)r�)rN)N)rF)NN)N)NN)NN)NN)N)NN)F)r)N)N)NN)N)N)NF)N)N)NNN)NNN)FNN)FNN)rn)FFFFF)~rSrTrU�__doc__r+r�Z_flagserrorclassr�r�r�r�r1Z
propertycacher�r�r�r�r�r�r�r�r��
contextlib�contextmanagerr�r�r�r�r�r�rrrr	rr�r�rrWrrrr�rr#r$r)r=rMr*r,r.r-r7r?rAr]r^rcrdror`rrrprTr{r�r|r�r�r�r)r�r�r�r�r�r�r�r�r�r�r�r�rJr:r�r�r�rr�r�r�r�r�r�r�r!r�r�r�r�r�r�r�r	rrrrrrr2ZCG_DELTAMODE_STDrr!r"r#r)r r(r$r+r0r3r5r@r@r@rDr>�s@-�
XR





	



	


)

@



!





":
3
"

D



,
+&

^

E�
W�
<�
>F�
m2,�
'�
cU
k�
)pr6Z
__future__rr�rVr7r�r
r�rr�rMrrrrrr	Zi18nr
r.rZrevlogutils.constantsrr
rrrrrrrrrrrrrrrrrrr Zrevlogutils.flagutilr!r"r#r$r%r&r'Z
thirdpartyr(�r)r*r+r,r-r/r0r1Z
interfacesr2Z
interfaceutilr3r�r4r�r5r6rzr7r8r9r:r�Zutilsr;r<Z	importmodr=Z
importrustr:rqrkr�r�r�rErFrGr�rNr�ZHAS_FAST_PERSISTENT_NODEMAPZimplementerZirevisiondeltarrUrPZiverifyproblemr[rdrgrhrjrlr�r�r>r@r@r@rD�<module>	s� \$	,(




��




�

Youez - 2016 - github.com/yon3zu
LinuXploit