
    6hY                   X   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK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JrJrJrJrJr  SSKJr  SSKJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1  SS	K2J3r3J4r4J5r5J6r6J7r7J8r8J9r9  SS
K:J;r;  \	Rx                  (       a
  SSK;r;SSK=J>r>  SSK?J@r@JArAJBrBJCrCJDrDJErEJFrFJGrGJHrHJIrJ  SSKKJLrL  SSKFJMrNJOrPJQrQJRrSJTrTJUrUJVrVJWrX  SSKYJZrZJ[r[  \)  \*  \,  \  \$  \#  \.  \/  \0  \+  \-  \8  \4  \7  \5  \3  \6  \9  \DR                  " S5      r]\DR                  " SSS9r_\DR                  " SSS9r`\DR                  " SSS9ra\R                  rcSrdS reS rfS rg\e\f\g4rhS ri\aSL=(       d	    \j" \]S5      rk\;R                  " SS9 " S S\LR                  5      5       rn\;R                  " SS9 " S  S!\LR                  5      5       rpS" rqS# rrS$ rs\j" \]S%5      (       a  S& rtOSrtS'ru\" S(5      rvS)rw " S* S+5      rx\;R                  " 5        " S, S-\x5      5       ry\;R                  " 5        " S. S/\x5      5       rz\;R                  " 5        " S0 S1\x5      5       r{ " S2 S35      r|\	Rx                  (       a  \>r}O\~r} " S4 S5\}5      r " S6 S75      r " S8 S5      rg)9zStorage back-end for Mercurial.

This provides efficient delta storage with O(1) retrieve and append
and O(changes) merge between branches.
    )annotationsN)IterableIteratorOptionalTuple   )binhexnullrevsha1nodeconstantsshortwdirrev)_)	ALL_KINDSCHANGELOGV2COMP_MODE_DEFAULTCOMP_MODE_INLINECOMP_MODE_PLAINDELTA_BASE_REUSE_NODELTA_BASE_REUSE_TRY
ENTRY_RANKFEATURES_BY_VERSIONFLAG_GENERALDELTAFLAG_INLINE_DATAINDEX_HEADERKIND_CHANGELOGKIND_FILELOG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)BaseIndexObject)
ancestordagoperrormdiffpolicypycompatrevlogutilstemplatefiltersutilvfs)
repository)deltasdocketflagutilnodemaprandomaccessfilerevlogv0rewritesidedata)storageutil
stringutilparsersr1   T)pyo3r2   revlogi   c                
    US4$ NF rltexts     2/usr/lib/python3/dist-packages/mercurial/revlog.pyellipsisreadprocessorrP          ;    c                
    US4$ rJ   rK   rL   s     rO   ellipsiswriteprocessorrT      rQ   rR   c                    grJ   rK   rL   s     rO   ellipsisrawprocessorrV      s    rR   c                ^    U(       a  US   R                  U5        gU R                  U5        g)zyVerify the integrity of the given revlog ``node`` while providing a hook
point for extensions to influence the operation.   skipreadN)addrevision)rM   	skipflagsstatenodes       rO   _verify_revisionr^      s(     kt$ 	DrR   r0   )slotsc                     \ rS rSr\R
                  " \S9r\R
                  " \S9r\R
                  " \S9r	\R
                  " \S9r
\R
                  " \S9r\R
                  " \\   S9r\R
                  " \\   S9r\R
                  " \\   S9r\R
                  " \\   S9r\R
                  " \S9r\R
                  " S\\   S9rSrg)revlogrevisiondelta   )typeNdefaultrc   rK   )__name__
__module____qualname____firstlineno__r/   ibbytesr]   p1nodep2nodebasenodeintflagsr   baserevisionsizerZ   deltarC   protocol_flagslinknode__static_attributes__rK   rR   rO   ra   ra      s    77DWW% FWW% FwwE"HGGEwwHSM2wwHUO,HGG%)EwwHUO,HWW#&Nwwt(5/:HrR   ra   )frozenc                      \ rS rSr\R
                  " S\\   S9r\R
                  " S\\   S9r	\R
                  " S\\   S9r
Srg)revlogproblem   Nrd   rK   )rf   rg   rh   ri   r/   rj   r   rk   warningr3   r]   ru   rK   rR   rO   rx   rx      s>    ggd%9GGGDx7E774huo6DrR   rx   c                8    [         R                  XU5      u  p4X44$ N)rF   parse_index2datainlineuses_generaldeltaindexcaches        rO   parse_index_v1r      s    ''6GHLE<rR   c                >    [         R                  XU[        S9u  p4X44$ N)format)rF   r}   r"   r~   s        rO   parse_index_v2r      s+    ''' ( LE <rR   c                >    [         R                  XU[        S9u  p4X44$ r   )rF   r}   r   r~   s        rO   parse_index_cl_v2r      s+    ''' ( LE <rR   parse_index_devel_nodemapc                8    [         R                  XU5      u  p4X44$ r|   )rF   r   r~   s        rO   parse_index_v1_nodemapr      s$    88+
 |rR   isN   cannot read from revlog %s;  expected %d bytes from offset %d, data size is %ds   0123456789abcdefABCDEFc                      \ rS rSrS rSrg)_Configi  c                :    U R                   " S0 U R                  D6$ )NrK   )	__class____dict__selfs    rO   copy_Config.copy  s    ~~...rR   rK   N)rf   rg   rh   ri   r   ru   rK   rR   rO   r   r     s    /rR   r   c                  ,  ^  \ rS rSrSr\R                  " SS9r\R                  " \R                  " \	5      S9r
\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9rU 4S jrSrU =r$ )FeatureConfigi  z=Hold configuration values about the available revlog featuress   zlibre   Fc                b   > [         TU ]  5       nU R                  R                  5       Ul        U$ r|   )superr   compression_engine_options)r   newr   s     rO   r   FeatureConfig.copy  s*    gln)-)H)H)M)M)O&
rR   rK   )rf   rg   rh   ri   __doc__r/   rj   compression_engineFactorydictr   
censorablehas_side_datacompute_rankcanonical_parent_orderenable_ellipsisr   ru   __classcell__)r   s   @rO   r   r     s    G 1!%d1C!D 'JGGE*M775)L "WWU3gge,O rR   r   c                     \ rS rSrSr\R                  " SS9r\R                  " SS9r\R                  " SS9r	\R                  " SS9r
\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9rS	rg)

DataConfigi%  z;Hold configuration value about how the revlog data are readFr   N   g      ?i   rK   )rf   rg   rh   ri   r   r/   rj   try_pending	try_splitcheck_ambigmmap_large_indexmmap_index_thresholdchunk_cache_sizeuncompressed_cache_factoruncompressed_cache_countwith_sparse_readsr_density_thresholdsr_min_gap_sizegeneraldeltaru   rK   rR   rO   r   r   %  s    E ''%(K&I ''%(K wwu-7740wwu- !% 5  $wwt4 wwu-7740ggf-O 775)LrR   r   c                  X   \ rS rSrSr\R                  " SS9r\R                  " SS9r\R                  " SS9r	\R                  " SS9r
\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9r\R                  " SS9rS	rg)
DeltaConfigiI  zHold configuration value about how new delta are computed

Some attributes are duplicated from DataConfig to help havign each object
self contained.
Fr   NTr   rK   )rf   rg   rh   ri   r   r/   rj   general_deltasparse_revlogmax_chain_lenmax_deltachain_spanupper_bound_compdelta_both_parentscandidate_group_chunk_sizedebug_delta
lazy_deltalazy_delta_baseru   rK   rR   rO   r   r   I  s     GGE*MGGE*MGGD)M''"- wwt,.!%!3''%(K&Jgge,OrR   r   c                     \ rS rSr% SrS\S'     S(S jrS rS r\	S 5       r
\	S	 5       rS
 rS rS rS rS rS)S jr\R&                  S 5       r\R&                  S 5       rS*S jrS+S jrS,S jr\R4                  S 5       r\	S 5       r\	S 5       r\R4                  S-S j5       rS)S jrS r S)S jr!S r"S r#S)S jr$S.S  jr%S! r&S" r'S# r(S$ r)S% r*S& r+S'r,g)/_InnerRevlogih  zAn inner layer of the revlog object

That layer exist to be able to delegate some operation to Rust, its
boundaries are arbitrary and based on what we can delegate to Rust.

vfsmod.vfsopenerc                   Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        S U l	        Xl
        S U l        [        R                  " U R                   U R
                  (       a  U R                  OU R                  U R                  R                  U
5      U l        [        R                  " U R                   U R                  U R                  R                  5      U l        0 U l        S U l        S U l        U R                  R&                  b.  [(        R*                  " U R                  R,                  SS9U l        S U l        g )Nr   )maxcost)r   r   
index_file	data_filesidedata_filer   data_configdelta_configfeature_config_orig_index_file_default_compression_header_writinghandlesr@   r   _segmentfile_segmentfile_sidedata_decompressors_revisioncache_uncompressed_chunk_cacher   r9   lrucachedictr   _delay_buffer)r   r   r   r   r   r   r   r   r   r   chunk_cachedefault_compression_headers               rO   __init___InnerRevlog.__init__q  s    &+
$"*&(, !%+E(
  $,==KK $T__--	
 &6%F%FKK--&
" !" *.&55A-1->->  99.D*
 "rR   c                ,    [        U R                  5      $ r|   lenr   r   s    rO   __len___InnerRevlog.__len__      4::rR   c                    U R                   (       a   eS U l        U R                  b  U R                  R                  5         U R                  R                  5         U R                  R                  5         g r|   )is_delayingr   r   clearr   clear_cacher   r   s    rO   r   _InnerRevlog.clear_cache  s[    ####"))5**002%%'""..0rR   c                L    U R                   b  U R                   $ U R                  $ r|   )r   r   r   s    rO   canonical_index_file!_InnerRevlog.canonical_index_file  s$      ,(((rR   c                H    U R                   SL=(       d    U R                  SL$ )zis the revlog is currently delaying the visibility of written data?

The delaying mechanism can be either in-memory or written on disk in a
side-file.N)r   r   r   s    rO   r   _InnerRevlog.is_delaying  s*     ""$. 
!!-	
rR   c                >    [        U R                  U   S   S-	  5      $ )z.the offset of the data chunk for this revisionr      ro   r   r   revs     rO   start_InnerRevlog.start  s    4::c?1%+,,rR   c                &    U R                   U   S   $ )z.the length of the data chunk for this revisionr   r   r   s     rO   length_InnerRevlog.length  s    zz#q!!rR   c                H    U R                  U5      U R                  U5      -   $ )z+the end of the data chunk for this revisionr   r   r   s     rO   end_InnerRevlog.end  s    zz#S!111rR   c                    U R                   U   S   nX!:X  a  [        $ U R                  R                  (       a  U$ US-
  $ z(return deltaparent of the given revision   r   r   r   r   r   r   r   bases      rO   deltaparent_InnerRevlog.deltaparent  ;    zz#q!;N,,K7NrR   c                   U R                   R                  (       d  U R                  U5      [        :H  $ [	        U R
                  S5      (       a,  U R
                  R                  U l        U R                  U5      $ U[        :X  a  gU R
                  U   nUS   nX1:X  a  gU[        :X  a  gUS   nU R                  U5      S:X  a0  U R                  U5      nXT:X  a  OUnU R                  U5      S:X  a  M0  US   nU R                  U5      S:X  a0  U R                  U5      nXV:X  a  OUnU R                  U5      S:X  a  M0  X4:X  d  X6:X  a  gU R                  U5      $ )tells whether rev is a snapshot
issnapshotTr      r      F)r   r   r  r   hasattrr   r	  r   )r   r   entryr  p1bp2s          rO   r	  _InnerRevlog.issnapshot  s9     ..##C(G33TZZ.."jj33DO??3'''>

3Qx;7?1Xkk"o"  $AwB	 kk"o"
 1Xkk"o"  $AwB	 kk"o"
 :t$$rR   Nc                    U R                   R                  X5      $ ! [         a     Of = f/ nU R                   nU R                  R                  nUnXF   nXgS   :w  a;  Xb:w  a6  UR                  U5        U(       a  US   nOUS-  nXF   nXgS   :w  a  Xb:w  a  M6  Xb:X  a  SnOUR                  U5        SnUR                  5         X84$ )a'  Obtain 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   r   TF)r   
deltachainAttributeErrorr   r   appendreverse)	r   r   stoprevchainr   r   iterrevestoppeds	            rO   _deltachain_InnerRevlog._deltachain  s    	::((   		  

((66N1o'"4LL!A$1A 1o'"4 GLL!G~s    
**c                    [         R                  U R                  R                     nUR	                  U R                  R
                  5      $ r|   )r9   compenginesr   r   revlogcompressorr   )r   engines     rO   _compressor_InnerRevlog._compressor1  s@    !!$"5"5"H"HI&&::
 	
rR   c                p    U R                   c  gU R                   nU R                  U5      nUR                  $ )zthe default decompressorN)r   _get_decompressor
decompress)r   tcs      rO   _decompressor_InnerRevlog._decompressor8  s8     ++3,,""1%||rR   c                v    U R                   U   nU$ ! [         a     [        R                  R	                  U5      nUR                  U R                  R                  5      nX R                   U'    U$ ! [         a7    [        R                  " [        S5      [        R                  " U5      -  5      ef = ff = f)Ns   unknown compression type %s)r   KeyErrorr9   r  forrevlogheaderr   r   r   r3   RevlogErrorr   binasciihexlify)r   r'  
compressorr!  s       rO   r%  _InnerRevlog._get_decompressorA  s    	,,Q/J   
		))99!<#44''BB
 *4##A&
 	  ''458H8H8KK 
	s    
B8AA33AB44B8c                    U(       d  SU4$ U R                   R                  U5      nU(       a  SU4$ USS S:X  a  SU4$ SU4$ )z6Generate a possibly-compressed representation of data.rR   r   r          u)r"  compress)r   r   
compresseds      rO   r6  _InnerRevlog.compressQ  sT    9%%..t4

?"!99TzrR   c                t   U(       d  U$ USS nUS:X  a   [        U5      $ US:X  a  U$ US:X  a  [        R                  " US5      $ U R                  U5      nUR                  U5      $ ! [        R                   a;  n[        R                  " [	        S5      [
        R                  " U5      -  5      eSnAff = f)zDecompress 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.
r   r      xs   revlog decompress error: %sNr4  r5  )_zlibdecompresszlibr3   r.  r   rE   forcebytestrr9   bufferr%  r&  )r   r   r'  r  r1  s        rO   r&  _InnerRevlog.decompress`  s     K. 1I9&t,, %ZK$Y;;tQ''++A.
$$T** :: ''45 --a01 s   
A( (B7<6B22B7c              #    #    [        U R                  5      S:X  a  Sv   gU R                  b)  U R                  (       a  Sn[        R
                  " U5      eU R                  R                  5          U R                  R                  5          Sv   SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f7f)zCContext manager that keeps data and sidedata files open for readingr   N.revlog with delayed write should not be inline)	r   r   r   r   r3   ProgrammingErrorr   readingr   r   msgs     rO   rC  _InnerRevlog.reading  s      tzz?a+BC((--""**,//779 : -,99 -,s6   A/C1B3B"B3	C"
B0	,B33
C=Cc                    U R                   SL$ )z!True is a writing context is openN)r   r   s    rO   
is_writing_InnerRevlog.is_writing  s     ##4//rR   c                h    U R                   R                  =(       d    U R                  R                  $ )zSTrue if any file handle is being held

Used for assert and debug in the python code)r   is_openr   r   s    rO   rK  _InnerRevlog.is_open  s'    
   ((ND,F,F,N,NNrR   c              #  N  #    U R                   (       a  Sv   gS=n=pV [        U R                  5      nSnU(       a  U R                  US-
  5      nSnU R                  (       d|   U R                  U R                  SS9nUc!  UR                  S[        R                  5        O!UR                  U[        R                  5         UR                  U R                  U5        U R                  ba  Uc   eUc   e U R                  U R                  SS9nUR                  U[        R                  5        UR                  U R                  U5        XpR                  R                  -  n	U R                  5       nU R                  (       a  UR                  U R                   X-   5        OUR                  U R                   U	5        XEU4U l        U R                  (       a  UOUU R$                  l        X`R(                  l        Sv   SU l        SU R$                  l        SU R(                  l        Ub  UR+                  5         Ub  UR+                  5         Ub  UR+                  5         gg! [         a    U R                  U R                  SS9n GNf = f! [         a    U R                  U R                  SS9n GNf = f! SU l        SU R$                  l        SU R(                  l        Ub  UR+                  5         Ub  UR+                  5         Ub  UR+                  5         f f = f7f)z_Open the revlog files for writing

Add content to a revlog should be done within such context.
Nr   r      r+mode   w+)rH  r   r   r   r   r   r   seekosSEEK_ENDSEEK_SETFileNotFoundErrorrY   r   
entry_size_InnerRevlog__index_write_fpr   r   r   writing_handler   close)
r   transactiondata_endsidedata_endifhdfhsdfhrdsizeisizes
             rO   writing_InnerRevlog.writing  s     ??##C##3 

O HHQUOE{{F"kk$..ukE#+HHQ4HHXr{{;  OODNNE:%%1'333?*?K#{{4+=+=E{Jr{{;  OOD$6$6E JJ111++-;;OODOOU]COODOOU;(+$'7$:>++33!!0<@**9'+$37!!0<@**9?IIK#JJL ?IIK #I - F"kk$..ukEF - K#{{4+=+=E{JK" (,$37!!0<@**9?IIK#JJL ?IIK #st   L%AJ= %=I' "J= # I' 4J= 8:J 2CJ= A$L%'$JJ= JJ= $J:6J= 9J::J= =A%L""L%c                    U R                   c0  U R                  U R                  SU R                  R                  S9nO7[
        R                  " U R                  U R                  SU R                   5      nUc"  UR                  S[        R                  5        U$ UR                  U[        R                  5        U$ ! [         ax    U R                   c1  U R                  U R                  SU R                  R                  S9s $ [
        R                  " U R                  U R                  SU R                   5      s $ f = f)zpinternal method to open the index file for writing

You should not use this directly and use `_writing` instead
rN  rP  
checkambigr   rQ  )r   r   r   r   r   r@   appenderrR  rS  rT  rU  rV  )r   	index_endfs      rO   __index_write_fp_InnerRevlog.__index_write_fp  s   
	!!)KKOO#//;;    %--KK%9K9K  q"++& H y"++.H  
	!!){{OO#//;; #   (00KK%9K9K 
	s   BB= !B= =AD?7D?>D?c                `    U R                  U R                  SU R                  R                  S9$ )z|internal method to create a new index file for writing

You should not use this unless you are upgrading from inline revlog
   wrg  )r   r   r   r   r   s    rO   __index_new_fp_InnerRevlog.__index_new_fp  s3    
 {{OO''33  
 	
rR   c                   U R                   b   eSnU R                  bI  SnU R                  S   nUR                  5         UR                  5         SU l        SU R                  l        U R                  U R                  SS9nUR                  S5         U R                  5          [        [        U R                  5      5       H&  nUR                  U R                  Xw5      S   5        M(     UR                  5         SSS5        Ub  X0l        U R!                  5        nSU l        [        [        U R                  5      5       HT  nU R                  R%                  U5      n	US:X  a  U R                  R'                  U5      n
X-   n	UR                  U	5        MV     SSS5        [(        R(                  " U R                  U R                  U R*                  R,                  5      U l        U(       a+  U R/                  5       nXS4U l        X`R                  l        SnUb  UR                  5         U R                  $ ! , (       d  f       GND= f! , (       d  f       N= f! Ub  UR                  5         f f = f)z@split the data of an inline revlog into an index and a data fileNFTr   rQ  rO  r   )r   r   flushrZ  r   rY  r   r   truncaterC  ranger   r   writeget_segment_for_revsr   _InnerRevlog__index_new_fpr   entry_binarypack_headerr@   r   r   rX  )r   trheadernew_index_file_pathexisting_handlesfpnew_dfhra  ir  packed_headerr^  s               rO   split_inline_InnerRevlog.split_inline  s   !!))) +#%%a(BHHJHHJ $(D /3D,
 ++dnn5+9%	 s4::/AMM$";";A"A!"DE 0  
 #."5$$&"#s4::/A

//2AAv(,

(>(>v(F)-HHQK 0 ' !1 A A  11!D  ++-(+d';$3:!!0
 "K   '&8 " #s?   I $AH:=!I A>IA?I :
I	I 
II I3c                n   U R                   nX1   n[        US   S-	  5      nX:X  a  XTS   -   nOX2   n[        US   S-	  5      US   -   nU R                  (       a<  XQS-   U R                   R                  -  -  nXbS-   U R                   R                  -  -  nXe-
  nXPR                  R                  XX5      4$ )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.

API: we should consider making this a private part of the InnerRevlog
at some point.
r   r   r   )r   ro   r   rW  r   
read_chunk)	r   startrevendrevr   istartr   r   iendr   s	            rO   rw  !_InnerRevlog.get_segment_for_revsU  s    * 

F1IO$)#C=Dd1gm$tAw.C;;ldjj&;&;;;EQJ$**"7"777C''225AAArR   c                   U R                   b   U R                   R                  U5      nUb  U$ U R                  U   S   nU R                  X5      S   nU[        :X  a  UnOTU[
        :X  a  U R                  U5      nO8U[        :X  a  U R                  U5      nOSnXS-  n[        R                  " U5      eU R                   b#  U R                   R                  X[        U5      S9  U$ )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      unknown compression mode %d)cost)r   getr   rw  r   r   r)  r   r&  r3   r.  insertr   )r   r   uncompcompression_moder   rE  s         rO   _chunk_InnerRevlog._chunkz  s     ))53377<F!::c?2.((215.F!22''-F!11__T*F0C#C##C(())5**11#CK1PrR   c           	        U(       d  / $ U R                   nU R                  nU R                  nU R                  R                  n[
        R                  n/ nUR                  n	/ n
U
R                  nU R                  c  UnO:U H4  nU R                  R                  U5      nUc
  U	" U5        M+  U" X45        M6     U(       d  SnO5U R                  R                  (       d  U4nO[        R                  " U UUS9nU GH-  nUS   nUSSS2    H  nU" U5      S:w  d  M    O    U R                  UW5      u  nnU R"                  nU R$                  nU H  nU" U5      nU(       a  UUS-   U-  -  nU" U5      nU R                  U   S   nU" WUW-
  U5      nU[&        :X  a  UnOCU[(        :X  a	  U" U5      nO0U[*        :X  a	  U" U5      nOSnUU-  n[,        R.                  " U5      eU" UU45        U R                  c  M  U R                  R1                  UU[3        U5      5        M     GM0     U
R5                  5         U
 Vs/ s H  nUS   PM
     sn$ ! [         a%    U H  nU" XR!                  U5      45        M      GNJf = fs  snf )	a'  Obtain decompressed chunks for the specified revisions.

Accepts an iterable of numeric revisions that are assumed to be in
ascending order.

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

Returns a list with decompressed data for each requested revision.
NrK   
targetsizer   r   r   r  r  )r   r   r   r   rW  r9   r>  r  r   r  r   r   	deltautil
slicechunkrw  OverflowErrorr  r&  r)  r   r   r   r3   r.  r  r   sort)r   revsr  r   r   r   iosizer>  fetched_revsfaddchunksladdr   cached_valueslicedchunks	revschunkfirstrevlastrevoffsetr   decomp
def_decomp
chunkstartchunklength	comp_moder(  rE  xs                               rO   _chunks_InnerRevlog._chunks  s{    I

&&""}}))1L#==AA#F'I#,-  L!!22(?L$//%L &I |H$TrT?'?a' +2#887K __F++J "3Z
37f"44J$Sk JJsOB/	4f!4kB/A"22q	A"33"1A8C9$C++C00c1X11=2299#q#a&I' !% &N 	$%f!f%%? ! 2 %C#{{3/01 %2> &s   "IJ+JJc                    SnSnU R                   (       a  U R                   S   nU R                  X#S9u  pVU(       a  U R                   S   nSU l         SnU R                  U   S   nSU::  a  SU-  nU R                  bC  U R                  R
                  n	X-  n
XR                  R                  :  a  XR                  l        U R                  XWS9nUc  [        US   5      nUSS n[        R                  " XK5      nAU$ )zHreturn the possibly unvalidated rawtext for a revision

returns rawtext
Nr   r     r      r  )r   r  r   r   r   r   r   r  rk   r4   patches)r   r]   r   	cachedrevbasetextr  r  r  rawsizefactorcandidate_sizebinsrawtexts                rO   raw_text_InnerRevlog.raw_text  s    	 ++A.I))#)A**1-H #
**S/!$<WJ))5 %%??F$-N > > F FF9G..6||E|9T!W~H8D--/rR   c                d   U R                   U   nUS   nUS   nU R                  (       a  X@R                   R                  SU-   -  -  nUS:X  a  0 $ X$U-   :  a3  U R                  nUnUnUn	[        XiX4-  n
[
        R                  " U
5      eU R                  R                  XE5      nU R                   U   S   nU[        :X  a  UnOTU[        :X  a  U R                  U5      nO8U[        :X  a  U R                  U5      nOSnX-  n[
        R                  " U5      e[        R                  " U5      nU$ )0Return the sidedata for a given revision number.   	   r   r      r  )r   r   rW  r   FILE_TOO_SHORT_MSGr3   r.  r   r  r   r   r)  r   r&  sidedatautildeserialize_sidedata)r   r   r]  index_entrysidedata_offsetsidedata_sizefilenamer   r  r   mcomp_segmentcompsegmentrE  rC   s                   rO   rC   _InnerRevlog.sidedata  s1   jjo%a.#A;;zz44C@@OAIM99))HC$F"F"h%DDA##A&&11<<
 zz#r"?""G&&((6G%%ool3G0CKC##C((44W=rR   c                   U R                   c  Sn[        R                  " U5      eU R                   u  pnUc!  UR                  S[        R
                  5        O UR                  U[        R                  5        U(       aD  U	c!  UR                  S[        R
                  5        O UR                  U	[        R                  5        U(       a   UR                  U
[        R                  5        [        U R                  5      S-
  nU R                  (       d  UR                  U R                  U5        U R                  (       a  UR                  U R                  U5        UR                  U R                  U[        U5      -  5        US   (       a  UR                  US   5        UR                  US   5        U(       a  UR                  U5        U R                  c  UR                  U5        OU R                  R!                  U5        OU R                  b  Sn[        R                  " U5      eX_U R                  R"                  -  -  nUR                  U R                  U5        U(       a   eUR                  U5        UR                  US   5        UR                  US   5        UR%                  5       U(       a  UR%                  5       OS U(       a  UR%                  5       4$ S 4$ )N1   adding revision outside `revlog._writing` contextr   r   s&   invalid delayed write on inline revlog)r   r3   rB  rR  rS  rT  rU  r   r   r   rY   r   r   r   rv  r   r  rW  tell)r   r[  r  r   linkr  rC   r  rj  r\  r]  rE  r^  r_  r`  currs                   rO   write_entry_InnerRevlog.write_entryD  s#   2 'FC((----$HHQ$HHY,BKK(2;;/IIlBKK04::"{{OODNNF3!! 2 2ODOOD55tc%j7HIAw		$q'"IId1g

8$!!)		% ""))%0+;C((--TZZ2222FOOD55v><IIeIId1gIId1gHHJCHHJ4DIIK
 	
 &*
 	
rR   c                n    U R                   nUR                  S5      (       a  U R                   S S nUS-   $ )Ns   .ss   .a)r   endswith)r   r   s     rO   _divert_index_InnerRevlog._divert_index  s9    __

 u%%"-JE!!rR   c                0   U R                   (       a   eU R                  (       a  Sn[        R                  " U5      eU R                  c  U R
                  b  g [        U R                  5      S:X  a  U R                  U l        U R                  5       U l        U R
                  c   eU R                  c   eU R                  R                  U R                  5      (       a%  U R                  R                  U R                  5        U R                  $ / U l        g )NrA  r   )rK  r   r3   rB  r   r   r   r   r   r  r   existsunlinkrD  s     rO   delay_InnerRevlog.delay  s    <<;;BC((--)T-B-B-N_!$(OOD!"002DO((444??...{{!!$//22""4??3??"!#DrR   c                @   U R                   (       a   eU R                  (       a  Sn[        R                  " U5      eU R                  b  gSnU R                  5       nU R                  R                  U5      (       a  U R                  R                  U5        [        R                  " U R                  R                  U R                  5      U R                  R                  U5      5        U R                  (       ag  U R                  US5       nUR                  S[        R                   5        UR#                  SR                  U R                  5      5        S S S 5        SnS U l        U R                  U l        X0l        U R                  U4$ ! , (       d  f       N<= f)NrA  NTFrN  r   rR   T)rK  r   r3   rB  r   r  r   r  r  r9   copyfilejoinr   r   rR  rS  rT  rv  )r   rE  any_pendingpending_index_filer^  s        rO   write_pending_InnerRevlog.write_pending  s3   <<;;BC((--  ,!//1;;011KK12KKT__-KK/0	
 /73BKK(		#((4#5#567 8 K! $,++ 87s   AF
Fc                j   U R                   (       a   eU R                  (       a  Sn[        R                  " U5      eU R                  S LnU R
                  S LnU(       a  U(       a   S5       eU(       a  U R                  (       ao  U R                  U R                  S5       nUR                  S[        R                  5        UR                  SR                  U R                  5      5        S S S 5        S U l        U R                  $ U(       a}  U R                  R                  U R                  5      (       a/  U R                  R                  U R                  U R
                  SS9  U R
                  U l        S U l        U R                  $ Sn[        R                  " U5      e! , (       d  f       N= f)	NrA  unreachablerN  r   rR   Trh  s(   not delay or divert found on this revlog)rK  r   r3   rB  r   r   r   r   rR  rS  rT  rv  r  r  renamer   )r   rE  r  divertr^  s        rO   finalize_pending_InnerRevlog.finalize_pending  sS   <<;;BC((--""$.&&d2V'-'5!![[%8CHHQ,IIchht'9'9:; 9 "&D ((( {{!!$//22""OO))# # 
 #33DO$(D! ((( >C((-- 98s   "AF$$
F2)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r   r   r   r   r|   )r'  rk   r   rk   returnzTuple[bytes, bytes])r   rk   NN)r  rk   )-rf   rg   rh   ri   r   __annotations__r   r   r   propertyr   r   r   r   r   r  r	  r  r9   propertycacher"  r)  r%  r6  r&  
contextlibcontextmanagerrC  rH  rK  rd  rX  rx  r  rw  r  r  r  rC   r  r  r  r  r  ru   rK   rR   rO   r   r   h  s_    @"@"D1  
 
 
-"2%@)V 

 
 
  0+d 
 
 0 0 O O <  < |#J	
9v#BJ<V&p,\$LF
P"(,2)rR   r   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)RustIndexProxyi  a  Wrapper around the Rust index to fake having direct access to the index.

Rust enforces xor mutability (one mutable reference XOR 1..n non-mutable),
so we can't expose the index from Rust directly, since the `InnerRevlog`
already has ownership of the index. This object redirects all calls to the
index through the Rust-backed `InnerRevlog` glue which defines all
necessary forwarding methods.
c                    Xl         g r|   innerr   r  s     rO   r   RustIndexProxy.__init__  s    
rR   c                4    [        U R                  SU 35      $ )N_index_getattrr  r   names     rO   __getattr__RustIndexProxy.__getattr__  s    tzzWTF#344rR   c                6    U R                   R                  5       $ r|   )r  _index___len__r   s    rO   r   RustIndexProxy.__len__  s    zz((**rR   c                8    U R                   R                  U5      $ r|   )r  _index___getitem__r   keys     rO   __getitem__RustIndexProxy.__getitem__       zz,,S11rR   c                8    U R                   R                  U5      $ r|   )r  _index___contains__r  s     rO   __contains__RustIndexProxy.__contains__  s    zz--c22rR   c                8    U R                   R                  U5      $ r|   )r  _index___delitem__r  s     rO   __delitem__RustIndexProxy.__delitem__  r  rR   r  N)rf   rg   rh   ri   r   r   r  r   r  r  r  ru   rK   rR   rO   r  r    s%    
5+232rR   r  c                  >    \ rS rSrSrS r   S   S	S jjrS rSrg)
RustVFSWrapperi
  zoUsed to wrap a Python VFS to pass it to Rust to lower the overhead of
calling back multiple times into Python.
c                    Xl         g r|   r  r  s     rO   r   RustVFSWrapper.__init__  s    
rR   c                    U R                   R                  XX4S9n[        R                  " UR	                  5       5      U(       a  UR
                  4$ S 4$ )N)pathrP  
atomictemprh  )r  __call__rS  dupfileno	_tempname)r   r  rP  r   rh  fds         rO   r!  RustVFSWrapper.__call__  sL     ZZ  Z ! 

 ryy{#ZR\\JJTJJrR   c                .    [        U R                  U5      $ r|   r  r  s     rO   r  RustVFSWrapper.__getattr__   s    tzz4((rR   r  N)s   rbFF)r  rk   rP  rk   )	rf   rg   rh   ri   r   r   r!  r  ru   rK   rR   rO   r  r  
  s6     KK K)rR   r  c                  l   \ rS rSr% Sr\R                  rS\S'   S\S'   \	S 5       r
S\S	'                 Sz S{S jjrS rS|S jrS}S jrS|S jrS rS rS r\R(                  S 5       r\R(                  S 5       rS~S jrS rS rS rS rSS jrSS jrS rS rS r S}SS  jjr!S! r"S" r#S# r$S$ r%S% r&S& r'S' r(S( r)S) r*S* r+S+ r,S, r-\-r.S- r/S. r0S/ r1S0 r2S1 r3S|S2 jr4SS3 jr5S4 r6SS5 jr7S|S6 jr8SS7 jr9SS8 jr:SS9 jr;SS: jr<S; r=S< r>S= r?SS> jr@S? rAS@ rBSA rCSB rDSC rESD rFS}SE jrGSF rHSG rISH rJSI rKSSJ jrLSK rMSL rNSM rOSN rPSO rQSP rRSQ rSSR rTS}SS jrUST rVSU rWSV rXSSW jrY\ZSX 5       r[SY r\SZ r]\^R                  S[ 5       r`\^R                  S\ 5       ra\ZS] 5       rbS^ rcS
S
\dS
S
4S_ jre   SS` jrfSSa jrgSb rh   SSc jriSd rjSe rk     SSf jrlSg rmSh rnSi roSj rpSk rqSl rrS
SS\sR                  S
S
4Sm jruSnrvSorwSprxSqry1 SrkrzS
\wS
S
4Ss jr{St r|SSu jr}SSv jr~     SSw jrSx rSyrg
)rH   i$  a  
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.
r   _innerr   r   c                    [        U 5      S:X  a  g[        R                  " U 5      S   nUS-  nUS-  n[        U   nUS   " U5      $ )zCDetermine if a revlog is inline from the initial bytes of the indexr   T       inline)r   r   unpackr   )header_bytesr|  _format_flags_format_versionfeaturess        rO   is_inline_indexrevlog.is_inline_indexW  sV     |!$$\215( 6/&7	"=11rR   zOptional[bytes]_docket_fileNFc                z   X0l         SU l        SU l        SU l        SU l        SU l        X@l        Xl        Xl        UU l	        SU l
        Xl        U	(       a  [        R                  " U 5      U l        US   [        ;   d   e[        U5      S:X  d   eX l        Ub  UR#                  5       U l        OVSU R                  R&                  ;   a-  U R                  R&                  S   R#                  5       U l        O[)        5       U l        XpR$                  l        XR$                  l        Ub  UR#                  5       U l        OVSU R                  R&                  ;   a-  U R                  R&                  S   R#                  5       U l        O[1        5       U l        XPR.                  l        X`R.                  l        Ub  UR#                  5       U l        OVSU R                  R&                  ;   a-  U R                  R&                  S   R#                  5       U l        O[9        5       U l        XR6                  l        [<        R>                  " S5      U l         SU l!        SU l"        SU l#        0 U l$        [K        [L        RN                  5      U l(        SU l)        U RU                  5       u  nnU RW                  UU5        Xl,        g)	a  
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.
NFr   r  s   feature-configs   data-configs   delta-configd   )-radixr6  
_indexfile	_datafile_sidedatafile_nodemap_filepostfix_trypending
_try_split_may_inline	uses_rustr   nodemaputilget_nodemap_filer   r   targetr   r   optionsr   r   r   r   r   r   r   r   r   r   r9   r   _chainbasecacher   _docket_nodemap_docket_pcacher   r>   flagprocessors_flagprocessors_adding_group
_loadindex_load_inner_concurrencychecker)r   r   rE  r9  r>  rh  mmaplargeindexr   upperboundcomppersistentnodemapconcurrencychecker
trypendingr   r   r   r   r   
may_inliner   r   s                       rO   r   revlog.__init__g  s?   D 
 !!%#%!,!=!=d!CDayI%%%6{a%"0"5"5"7D$++"5"55"&++"5"56G"H"M"M"OD"//D)3&5K2"*//1Dt{{222#{{22>BGGID)|D'1$,:)# , 1 1 3D 3 33 $ 3 3O D I I KD +D-;*  $00504
#  $H$;$;<!!__.{,#5 rR   c                   U R                   R                  nSU;   a=  U R                  [        :X  a)  [        nUR                  SS5      nX0R                  l        OjSU;   a  [        nO]SU;   a0  [        nU R                  (       a	  U[        -  nSU;   a	  U[        -  nO'SU R                   R                  ;   a  [        nO[        nSnU R                  R                   (       a  U R                  R"                  nU R                  R$                  (       a  [&        U R(                  [*        '   UR                  S	0 5      R-                  5        H&  u  pV[.        R0                  " XVU R(                  5        M(     U R                  R2                  nUS
::  a"  [4        R6                  " [9        S5      U-  5      eXwS-
  -  (       a"  [4        R6                  " [9        S5      U-  5      eUR                  SS5      nX$U4$ )a  process 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
s   changelogv2s   changelogv2.compute-rankTs   revlogv2s   revlogv1   generaldeltas   revlogv0Ns   flagprocessorsr   s0   revlog chunk cache size %r is not greater than 0r   s.   revlog chunk cache size %r is not a power of 2s   devel-force-nodemapF)r   rF  revlog_kindr   r   r  r   r   r"   r    rA  r   r   r   r&   r   r   r   r   ellipsisprocessorrL  r)   itemsr>   insertflagprocessorr   r3   r.  r   )	r   opts
new_headerr   mmapindexthresholdflag	processorr   force_nodemaps	            rO   
_init_optsrevlog._init_opts  s     {{""T!d&6&6.&H$J88$?FL/;,D !JD !J..
$&//
DKK///!J/J!,,!%!1!1!F!F..4ED  1  $xx(92>DDFOD(($:N:NO  G  ++<<q ##EF"#  A!56##CD"#  !7?}<<rR   c                ^    U R                  U5       nUb  U R                   R                  U5      R                  nXR:  a  U R                   R                  U5      (       aw  Ub  [	        XS5      nUc3  [
        R                  " [
        R                  " U5      5      sSSS5        $ [
        R                  " [
        R                  " XC5      5      sSSS5        $ Uc  UR                  5       sSSS5        $ UR                  U5      sSSS5        $ ! , (       d  f       g= f! [         a     gf = f)zZreturn a file content with or without mmap

If the file is missing return the empty stringNrR   )
r   fstatst_sizeis_mmap_safeminr9   r>  mmapreadreadrV  )r   filepathmmap_thresholdsizer  	file_sizes         rO   	_get_datarevlog._get_data  s    	X&"!- $ 1 1" 5 = =I!3 KK44X>>+#&y#7D  <#';;t}}R/@#A '& $(;;t}}R/F#G '&  <779# '&& 774=' '&&( ! 		sS   D BD	D %)D	D D*	D 4D	D 
DD D 
D,+D,c                X  ^ ^^^ [        T 5      mT R                  nTS:  a  UTS-
     S   nXA:  a  OTS-
  mTS:  a  M  TS:X  a  / $ TUR                  -  mT R                  TS-
  5      mT R                  (       a-  UUU 4S jnU" 5       n[        U5        T R                  UTT-   4/$ U(       a,  UU 4S jnU" 5       n[        U5        T R                  UTT-   4/$ UU 4S jnUU 4S jnU" 5       n	[        U	5        U" 5       n
[        U
5        T R                  U
T4T R                  U	T4/$ )u  return a list of streams that represent this revlog

This is used by stream-clone to do bytes to bytes copies of a repository.

This streams data for all revisions that refer to a changelog revision up
to `max_linkrev`.

If `force_inline` is set, it enforces that the stream will represent an inline revlog.

It returns is a list of three-tuple:

    [
        (filename, bytes_stream, stream_size),
        …
    ]
r   r   r  c               3     >#    TR                  TR                  SS9 n S v   TT-   nUS::  a  U R                  U5      v   O[        R                  " XS9 S h  vN   S S S 5        g  N! , (       d  f       g = f7fN   rrO  r   limitr   r:  rl  r9   filechunkiter)r  ro  	data_size
index_sizer   s     rO   
get_stream&revlog.get_streams.<locals>.get_streamK  sj     [[t[<J%	1Du} ggdm+#'#5#5b#EEE =< F =<s.   A:;A)A'A)	A:'A))
A73A:c               3    >#    TR                  5          S v   [        T5       H  n TR                  R                  U 5      nU S:X  aP  TR                  cC  TR
                  nUTR                  -  nU[        -  nTR                  R                  U5      nX!-   nUv   TR                  R                  X 5      S   v   M     S S S 5        g ! , (       d  f       g = f7f)Nr   r   )rC  ru  r   ry  rH  r1  r2  r   rz  r*  rw  )r   idxr|  nr   s      rO   r}  r~  [  s     \\^J$Qx"jj55c:!8(<%)%7%7F"d&:&::F"&66F%)ZZ%;%;F%CF"(,C!	"kk>>sHKK  ( $^^s   CB,C	 	C	
CCc               3     >#    TR                  TR                  SS9 n S v   TS::  a  U R                  T5      v   O[        R                  " U TS9 S h  vN   S S S 5        g  N! , (       d  f       g = f7fru  ry  )r  r|  r   s    rO   get_index_stream,revlog.get_streams.<locals>.get_index_streamr  sd     [[t[<J!U* ggj11#'#5#5b
#KKK =<
 L =<s.   A67A%A#A%	A6#A%%
A3/A6c               3     >#    TR                  5        n S v   TS::  a  U R                  T5      v   O[        R                  " U TS9 S h  vN   S S S 5        g  N! , (       d  f       g = f7f)Nr   rw  )_datafprl  r9   rz  )r  r{  r   s    rO   get_data_stream+revlog.get_streams.<locals>.get_data_streamz  sW     \\^rJ E) ggi00#'#5#5b	#JJJ $^
 K $^s.   A,7AAA	A,A
A)%A,)r   r   rW  r   _inlinenextr:  r;  )r   max_linkrevforce_inliner   linkrevr}  inline_streamr  r  index_streamdata_streamr{  r|  r  s   `          @@@rO   get_streamsrevlog.get_streams   sE   " I

!eAEl1oG$ AA !e 6I)))
HHQUO	 <<F 'LM-i1GH  L  'LM-i1GH 
LK ,-L)+Ki8,
; rR   c                .   U R                  5       u  p#nU R                  b  SU R                  U R                  4-  nOU R                  (       a=  U R                  R                  SU R                  -  5      (       a  SU R                  -  nOWU R                  (       a7  U R                  R                  U R                  5      (       a  U R                  nOSU R                  -  nUb  Xl        XPl	        GOSU l
        U R                  XS5      n[        U5      S:  a$  [        R                  " US S 5      S   nSU l
        OUnUS-  U l        US	-  U l        ["        R$                  " U R                   5      nUc;  ['        S
5      n	XR                   U R(                  4-  n	[*        R,                  " U	5      eU R                  U) -  (       aK  ['        S5      n	U R                  S-	  n
XU R                   U R(                  4-  n	[*        R,                  " U	5      e[.        U R                      nUS   " U R                  5      U l        US   " U R                  5      U R2                  l        U R2                  R4                  U R6                  l        US   U R:                  l        US   (       d	  XPl        UnOWXPl	        U R                  (       a  [@        RB                  " X5      U l        O$[@        RD                  " XU R                  S9U l        U R                  b  U R                  RG                  5       U l        SnU R                  RH                  nUS:  ad  U R                  U R>                  X=S9n[        U5      U:  a;  ['        S5      n	XR(                  [        U5      U4-  n	[*        R,                  " U	5      eSU l        SU R2                  l        SU R6                  l        S U l%        U R                  b?  U R                  RM                  5       U l'        U R                  RQ                  5       U l)        OBU R                  c  SU R                  -  U l'        O SU R                  U R                  4-  U l'        [T        U l+        U RV                  RX                  U l,        U R2                  R4                  (       d  SU R2                  l-        SU l.        U RJ                  =(       a    U=(       a    [^        S LnSnU RJ                  S LnU=(       d    U R`                  S   [b        :H  nU=(       a    [e        U R                  SS5      n[f        b  U(       a  SnU R                   [h        :w  a  Sn[k        U R                  S5      (       aU  U R                  Rl                  nU R                  Rn                  (       d  Sn[q        U[r        Rl                  5      (       d  SnOSn[t        U l;        U R                   [x        :X  a  [z        R|                  U l;        ORU R                   [~        :X  a  [        U l;        O2U R                   [        :X  a  [        U l;        OU(       a  [^        U l;        U(       a  WS nnSU lC        OH U Rw                  WU R0                  U R2                  R4                  5      nUu  nnU R                  U5        [        R                  " S5      U lI        UU4$ ! [        [        4 a-    [*        R,                  " ['        S5      U R(                  -  5      ef = f)Ns   %s.i.%ss   %s.i.as   %s.iTr   r  Fr,  r-  s!   unknown version (%d) in revlog %ss-   unknown flags (%#04x) in version %d revlog %sr   r.  rY  s   sidedatas   docket)use_pendingrR   )ro  s.   too few index data for %s: got %d, expected %ds   %s.ds   %s.d.%srust_compatiblefncaches   index %s is corrupted  )Jrd  r>  r9  r?  r   r  r@  _split_index_filerH  r6  
_initemptyrq  r   r   r/  r1  r2  r'   r  r   
display_idr3   r.  r   r  r   r   r   r   r   r   r:  
docketutildefault_docketparse_docketindex_filepathrj  r=  data_filepathr;  sidedata_filepathr<  r   nodeconstantsnullidr   _storedeltachainsr   rE  r   r  
rustrevlogr    r  r:   uses_dotencode
isinstancevfsmodr   _parse_indexr   rA   parse_index_v0r"   r   r   r   rB  _register_nodemap_info
ValueError
IndexErrorr9   r   _chaininfocache)r   r=   r_  r`  rc  entry_point
entry_datar|  supported_flagsrE  display_flagr3  
index_datar|  devel_nodemapuse_rust_indexrust_applicabler:   r   
chunkcacheds                        rO   rN  revlog._loadindex  s   8<8I5
<<#$

DLL'AAK$++"4"4Y5K"L"L#djj0K__!3!3D4J4J!K!K00K!DJJ.K!L +"DOHJ:"%,,Z^<Q?"'#!''!1D#)F?D -11$2F2FGO&<=,,doo>>'',,##&66HI#11R7d&:&:DOOLL'',,*4+?+?@H#I.t/A/ABDL.6.G""/D+ -1,=,=,K,KD)080ED-I&"-'
$/!??#-#<#<T#JDL#-#:#:d6F6F$DL <<#"ll99;DOJ//JA~!^^OO%7 , 
 z?Z/MNCOOS_jIIC++C00 DL.2D+,0D) "&D<<#!\\779DN!%!?!?!AD\\!$tzz1DN'4::t||*DDDN.((//   ...3D+!%  33&d2 	 ,,D8)KT[[^|-K) 
gKK*D/
 !o "N##x/!&4;;	**++//C;;--!&c6::..!& #N*8+ ( 7 7D!!X- .D!![0 1D 6D!+T:E!DN	%%d.?.?.M.M %&!z++E2  $005j   
+ ''./$//A s   1A[ =\c                $   U R                   c  S nOU R                   R                  nU R                  (       GaU  SnS n[        U R                  S5      (       aR  U R                  n[        U[        R                  5      (       a  SnUR                  nUR                  nUR                  nOU R                  nUR                  nUc   S5       e[        R                  UUUUU R                  U R                  U R                  U R                   U R"                  U R$                  U R&                  UUU R(                  S   U R*                  S LS9U l        [/        U R,                  5      U l        U R3                  U R0                  5        SU l        g [5        U R                  UU R                  U R                  U R                  U R                   U R"                  U R$                  U R&                  UUS9U l        U R,                  R0                  U l        g )NFr:   Tz%Rust only supports repos with fncacher   )vfs_baser  vfs_is_readonlyr  r   r   r   r   r   r   r   r   r   revlog_typeuse_persistent_nodemap)r   r   r   r   r   r   r   r   r   r   r   )rH  r   rB  r  r   r  r  readonlyvfsr:   r  r  r  InnerRevlogr:  r;  r<  r  r   r   r   rE  r=  r*  r  r   r  r   )r   r   r   r   r  r  r:   r  s           rO   rO  revlog._load_inner-  s   <<)-&)-)P)P&>>>#OGt{{E**kkc6#5#566&*O''C++ggkkxxH&O(OO&$00! / ??.."00|| ,,!..#22'+E KKN'+'9'9'E 1 DK" (4DJ''

3!DN&{{??.."00|| ,,!..#22'+EDK **DJrR   c                b   U R                   (       + =(       a!    U R                  S L=(       a    [        US5      nU(       ao  [        R                  " U 5      nUbU  US   n[        U5      UR                  :  a6  XR                     S   UR                  :X  a  X@l        UR                  " U6   g g g g g )Nupdate_nodemap_datar      )
r  r=  r  rC  persisted_datar   tip_revtip_noderI  r  )r   r   use_nodemapnodemap_datar=   s        rO   r  revlog._register_nodemap_infoh  s     6""$.645 	
 &55d;L'%aJ/nn-a0FOOC ,2(--%	 D 0 ( rR   c                    U $ )z<simple function to mirror API of other not-really-revlog APIrK   r   s    rO   
get_revlogrevlog.get_revlog|  s    rR   c                     U R                   S   $ Nr   )rE  r   s    rO   rZ  revlog.revlog_kind  s    {{1~rR   c                `    U R                   [        :X  a  U R                  S   $ U R                  $ )z;The public facing "ID" of the revlog that we use in messager   )rZ  r   rE  r9  r   s    rO   r  revlog.display_id  s,     |+ ;;q>!::rR   c                6    U R                  U R                  US9$ )z&file object for the revlog's data filerO  )r   r;  )r   rP  s     rO   r  revlog._datafp  s    {{4>>{55rR   c                2    [        U R                  5      S-
  $ Nr   r   r   s    rO   tiprevrevlog.tiprev  s    4::""rR   c                @    U R                  U R                  5       5      $ r|   )r]   r  r   s    rO   tip
revlog.tip  s    yy''rR   c                >    SUs=:*  =(       a    [        U 5      :  $ s  $ r  )r   r   s     rO   r  revlog.__contains__  s    C###d)####rR   c                ,    [        U R                  5      $ r|   r   r   s    rO   r   revlog.__len__  r   rR   c                <    [        [        [        U 5      5      5      $ r|   )iterru  r   r   s    rO   __iter__revlog.__iter__  s    E#d)$%%rR   c                >    [         R                  " [        U 5      XS9$ )z8iterate over all rev in this revlog (from start to stop)r   stop)rD   iterrevsr   r   r   r  s      rO   r  revlog.revs  s    ##CIUFFrR   c                H     U R                  U5        g! [         a     gf = f)NTF)r   r,  r   r]   s     rO   hasnoderevlog.hasnode  s'    	HHTN 		s    
!!c                z    U R                  U5      [        -  (       d  U R                  U5      [        -  (       a  gg)z;whether two revisions (baserev, rev) can be delta-ed or notFT)rp   r.   )r   baserevr   s      rO   	_candeltarevlog._candelta  s-     JJw"??JJsO;;rR   c                    U R                   b1  Uc  [        R                  " U 5        g[        R                  " X5        gg)zbupdate on disk cache

If a transaction is passed, the update may be delayed to transaction
commit.N)r=  rC  update_persistent_nodemapsetup_persistent_nodemapr   r[  s     rO   update_cachesrevlog.update_caches  s7    
 )"55d;44[G	 *rR   c                   U R                   R                  5         U R                  R                  5         0 U l        SU l        U R                  R                  5         U R                  (       + =(       a+    U R                  SL=(       a    [        U R                  S5      nU(       a>  [        R                  " U 5      nUb$  US   U l        U R                  R                  " U6   ggg)zClear in-memory cachesNr  r   )rG  r   r*  r   rJ  rI  r   clearcachesr  r=  r  rC  r  r  )r   clear_persisted_datar  r  s       rO   r  revlog.clearcaches  s    ""$!#

   ;""$.;

$9: 	
 &55d;L''3A$

..! ( rR   c                V    U R                   R                  U5      $ ! [         a    e [        R                   am    XR
                  R                  :X  d  XR
                  R                  ;   a  [        R                  e[        R                  " XR                  [        S5      5      ef = f)z5return the revision number associated with a <nodeid>   no node)r   r   	TypeErrorr3   r.  r  wdiridwdirfilenodeidsWdirUnsupportedLookupErrorr  r   r  s     rO   r   
revlog.rev  s    	J::>>$'' 	   	J **111--===+++##D//1Z=II	Js
    BB(c                >    [        U R                  U   S   S-	  5      $ )Nr   r   r   r   s     rO   r   revlog.start  s    4::c?1%+,,rR   c                    U R                   U   S   nUS:w  a  U$ SU::  a0  U R                   U   nUS   S:w  a  US   US   -   $ US-  nSU::  a  M0  g)Nr  r   r  r   r   )r   r   
sd_cut_offr  s       rO   sidedata_cut_offrevlog.sidedata_cut_off  sk    ZZ_Q'
? 3h

3Atqytad{"1HC	 3h
 rR   c                ,    U R                   U   S   S-  $ )Nr   r-  r   r   s     rO   rp   revlog.flags  s    zz#q!F**rR   c                &    U R                   U   S   $ r  r   r   s     rO   r   revlog.length      zz#q!!rR   c                ^    U R                   R                  (       d  gU R                  U   S   $ )Nr   r  )r   r   r   r   s     rO   sidedata_lengthrevlog.sidedata_length  s'    ""00zz#q!!rR   c                n    U R                   U   S   nUS:  a  U$ U R                  U5      n[        U5      $ )z?return the length of the uncompressed text for a given revisionr  r   )r   rawdatar   )r   r   lr'  s       rO   r  revlog.rawsize  s7    JJsOA6HLL1vrR   c                    U R                  U5      nU[        R                  [        -  -  S:X  a  U R	                  U5      $ [        U R                  U5      5      $ )z=length of non-raw text (processed by a "read" flag processor)r   )rp   r>   REVIDX_KNOWN_FLAGSr)   r  r   rZ   )r   r   rp   s      rO   ro  revlog.size  sL     

3H///ABaG<<$$4==%&&rR   c                    U R                   U   [           nU R                  [        :w  d
  U[        :X  a  gU[
        :X  a  gU$ )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.
Nr   )r   r   r2  r   r   r   )r   r   ranks      rO   	fast_rankrevlog.fast_rank  s=     zz#z*;.$,2F'>rR   c                    U R                   R                  U5      nUb  U$ U R                  nUnX4   S   nX$:w  a  UnX4   S   nX$:w  a  M  X R                   U'   U$ )Nr   )rG  r  r   )r   r   r  r   r  s        rO   	chainbaserevlog.chainbase1  so    ##'',K

~a oG>!$D o %)S!rR   c                &    U R                   U   S   $ )Nr  r   r   s     rO   r  revlog.linkrev@  r  rR   c                     U R                   U   nU R
                  R                  (       a  US   [        :X  a
  US   US   4$ US   US   4$ ! [         a    U[        :X  a  [        R                  ee f = f)Nr
  r  )r   r  r   r3   r   r   r   r   )r   r   r  s      rO   
parentrevsrevlog.parentrevsC  s}    	JJsOE 55%(g:M8U1X%%8U1X%%  	g~+++	s   A &A3c                z     U R                   U   S   $ ! [         a    U[        :X  a  [        R                  ee f = f)Nr  )r   r  r   r3   r   r   s     rO   r]   revlog.nodeS  s?    	::c?1%% 	g~+++	s    &:c                H    U R                  U5      U R                  U5      -   $ r|   r   r   s     rO   r   
revlog.end]  s    zz#S!111rR   c                    U R                   nX R                  U5         nU R                  R                  (       a'  US   U R                  :X  a  X#S      S   X#S      S   4$ X#S      S   X#S      S   4$ )Nr
  r  r  )r   r   r   r   r  )r   r]   r  r  s       rO   parentsrevlog.parents`  sw    JJhhtn55!A$$++:MqT71:q1wqz))qT71:q1wqz))rR   c                *    U R                  U5      S   $ r  )
_chaininfor   s     rO   chainlenrevlog.chainleni  s    s#A&&rR   c                <   U R                   nX;   a  X!   $ U R                  nU R                  R                  nUnX5   nSnSnXVS   :w  aD  US-  nXS   -  nU(       a  US   nOUS-  nXR;   a  X%   n	XyS   -  nXS   -  nOX5   nXVS   :w  a  MD  XS   -  nXx4n
XU'   U
$ )Nr   r   r   )r  r   r   r   )r   r   chaininfocacher   r   r  r  clencompresseddeltalenr'  ra  s              rO   r,  revlog._chaininfol  s    -- !&&

((66N1oAIDA$&A$1("+!"d*"A 1o  A$&&srR   c                4    U R                   R                  XS9$ )Nr  )r*  r  )r   r   r  s      rO   r  revlog._deltachain  s    {{&&s&<<rR   c                   [        U5      nU R                  nU H  nU" U5        M     [        b8  U R                  R                  (       a  [        R
                  nU R                  nO[        R                  nU R                  nU" XqX#S9$ )zGenerate the ancestors of 'revs' in reverse revision order.
Does not generate revs lower than stoprev.

See the documentation for ancestor.lazyancestors for more details.)r  	inclusive)	listr]   rustancestorr   rust_ext_compatLazyAncestorsr1   lazyancestors_uncheckedparentrevs)r   r  r  r7  checkrevra  r<  args           rO   	ancestorsrevlog.ancestors  sr     Dz99AQK  #

(B(B(66M**C$22M++CSMMrR   c                X    [         R                  " XR                  U R                  5      $ r|   )r2   descendantrevsr  r"  )r   r  s     rO   descendantsrevlog.descendants  s    ##D))T__EErR   c                  ^
 Uc  U R                   /nUc  U R                  5       nU Vs/ s H  o0R                  U5      PM     nnU Vs/ s H  o0R                  U5      PM     nn " S S5      nU" U R                  U5      5      m
T
R	                  [
        5        T
R                  U5        [        5       n[        R                  " U
4S jU 5       5      nU(       ab  UR                  5       nXu;   a  M  UR	                  U5        U R                  U5       H  nUT
;  d  M  UR                  U5        M     U(       a  Mb  [        U5      nUR                  5         T
U V	s/ s H  oR                  U	5      PM     sn	4$ s  snf s  snf s  sn	f )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.c                  2    \ rS rSrS rS rS rS rS rSr	g)	)revlog.findcommonmissing.<locals>.lazyseti  c                .    [        5       U l        Xl        g r|   )setaddedvalues
lazyvalues)r   rL  s     rO   r   2revlog.findcommonmissing.<locals>.lazyset.__init__  s    #&5 ",rR   c                H    XR                   ;   =(       d    XR                  ;   $ r|   rK  rL  r   values     rO   r  6revlog.findcommonmissing.<locals>.lazyset.__contains__  s     0 00LE__4LLrR   c              3  z   #    U R                   nU H  nUv   M	     U R                   H  nX!;  d  M
  Uv   M     g 7fr|   rO  )r   addedra  s      rO   r  2revlog.findcommonmissing.<locals>.lazyset.__iter__  s7     ((AG A: )s   ,;	;c                :    U R                   R                  U5        g r|   )rK  rY   rP  s     rO   rY   -revlog.findcommonmissing.<locals>.lazyset.add  s      $$U+rR   c                :    U R                   R                  U5        g r|   )rK  update)r   valuess     rO   rY  0revlog.findcommonmissing.<locals>.lazyset.update  s      ''/rR   rO  N)
rf   rg   rh   ri   r   r  r  rY   rY  ru   rK   rR   rO   lazysetrH    s    -M ,0rR   r\  c              3  6   >#    U  H  oT;  d  M
  Uv   M     g 7fr|   rK   ).0ra  hass     rO   	<genexpr>+revlog.findcommonmissing.<locals>.<genexpr>  s     !CUsl!!Us   		)r  headsr   r@  rY   r   rY  rJ  collectionsdequepopleftr"  r  r8  r  r]   )r   commonrb  r  r\  missingvisitra  pmissr_  s             @rO   findcommonmissingrevlog.findcommonmissing  s?    >kk]F=JJLE'-.v!((1+v.&+,e!e,	0 	0, dnnV,-

6 %!!!CU!CCA|A+A|Q , e w-9YYt_999Y /,V :s   E=	FFc                    Uc  [         /n[        b;  U R                  R                  (       a   [        R	                  U R                  U5      $ [
        R                  " U R                  U5      $ )a  Return 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.
)r   r9  r   r:  MissingAncestorsr1   incrementalmissingancestorsr"  )r   rf  s     rO   incrementalmissingrevsrevlog.incrementalmissingrevs  sP     >YF#

(B(B00VDD33DOOVLLrR   c                |    Uc  [         /nUc  U R                  5       nU R                  US9nUR                  U5      $ )a(  Return 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.rf  )r   headrevsrp  missingancestors)r   rf  rb  incs       rO   findmissingrevsrevlog.findmissingrevs  sD      >YF=MMOE)))8##E**rR   c                d   Uc  U R                   /nUc  U R                  5       nU Vs/ s H  o0R                  U5      PM     nnU Vs/ s H  o0R                  U5      PM     nnU R                  US9nUR	                  U5       Vs/ s H  oPR                  U5      PM     sn$ s  snf s  snf s  snf )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.rs  )r  rb  r   rp  ru  r]   )r   rf  rb  r  rv  ra  s         rO   findmissingrevlog.findmissing	  s     >kk]F=JJLE'-.v!((1+v.&+,e!e,)))8&)&:&:5&AB&A		!&ABB	 /, Cs   B#B(B-c                H   / / / 4nUb?  [        U5      nU(       d  U$ [        U Vs/ s H  o@R                  U5      PM     sn5      nOU R                  /n[        nU[        :X  aI  UcF  U  Vs/ s H  o`R                  U5      PM     snU R                  /[        U R                  5       5      4$ Uc  [        U 5      S-
  nSn0 nGO[        U5      nU(       d  U$ [        5       n[        R                  US5      n[        U5      n	[        U	 Vs/ s H  o@R                  U5      PM     sn5      nU	(       a  U	R                  5       nX@R                  :X  a  M(  U R                  U5      nXe:  ao  XH;  aT  UR                  U5        U	R                  U R                  U5       V
s/ s H  oU R                  :w  d  M  U
PM     sn
5        OXB;   a  UR                  U5        U	(       a  M  U(       d  U$ U[        :  aM  U Vs/ s H  oU;   d  M
  UPM     nnU(       a+  [        U Vs/ s H  oR                  U5      PM     sn5      nOU$ [        nU R                  /n[        U5      nUR!                  5       n/ nU R#                  [        US5      US-   S9 GH  nU R                  U5      nSnU[        :X  a  SnOXL;   aE  SnXA;   a=  [%        U R                  U5      5      n
U
S   U;   d	  U
S   U;   a  UR'                  U5        O?[%        U R                  U5      5      n
U
S   U;   d	  U
S   U;   a  UR                  U5        SnU(       d  M  Ub  XH;   d  M  UR)                  U5        Ub  XB;   a  SX$'   M  Ub  M  SX$'   U R                  U5       H  n
UR                  U
S5        M     GM     UR+                  5        VVs/ s H  u  nnU(       d  M  UPM     nnn[        U5      nU(       d   eU(       d   eU(       d   eXU4$ s  snf s  snf s  snf s  sn
f s  snf s  snf s  snnf )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.Nr   Fr   r  T)r8  rj  r   r  r   r]   rb  r   rJ  r   fromkeysmaxpoprY   rY  r)  r   r  tupleremover  r\  )r   rootsrb  nonodesr  	lowestrevra  
highestrevr@  
nodestotagri  rootrD  
orderedoutisdescendantheadra  s                    rO   nodesbetweenrevlog.nodesbetween(	  s   * r2,KE%8%QXXa[%89I[[MEI u} (,,t!1t,TZZ\" 
 = TQJIEKEI MM%/EUJ:>:ahhqk:>?JNN$# HHQK>) "a("))(,QL1;KQL  		!+ *, 
 7"
 +0E%$93D%E #$FXXd^$F GI #N $	%j   "
 Y!2aHA		!A LG##!# :dll1o.A!+11DQ$,,q/* aDK'QqT[-@OOA&#'L|)"3!!!$)
  $EH&  $EH!\\!_		!T* -M IP ).>*$>Uzuu5))I 9 -0 ?" M" F %Gv ?s;   P ,PP
 P7P;	PP P;PPc                   Uc  U R                   R                  S U5      $ [        b;  U R                   R                  (       a   [        R                  U R                   U5      $ [        R                  " XR
                  5      $ r|   )r   rt  	rustdagopr:  r2   r=  )r   r  stop_revs      rO   rt  revlog.headrevs	  s\    <::&&tX66 TZZ%?%?%%djj$77~~d$=$=>>rR   c                     U R                   R                  X5      $ ! [         a$    [        R                  " U R                  X5      s $ f = fr|   )r   headrevsdiffr  r2   r=  r  s      rO   r  revlog.headrevsdiff	  sN    	N::**   	N%%d&?&?MM	Ns    +A
Ac                8    U R                   R                  U5      $ r|   )r   computephasesmapsets)r   r  s     rO   computephasesrevlog.computephases	  s    zz..
 	
rR   c                     U R                   R                  5       $ ! [         a8    U R                  5        Vs/ s H  oR	                  U5      PM     Os  snf sns $ f = fr|   )r   head_node_idsr  rt  r]   )r   ra  s     rO   _head_node_idsrevlog._head_node_ids	  sJ    	;::++-- 	;*.--/:/QIIaL/::	;s    AA	AAc                   Uc0  Uc-  [        U 5      (       d  U R                  /$ U R                  5       $ Uc  [        nOU R	                  U5      nU=(       d    /  Vs1 s H  o0R	                  U5      iM     nn[
        R                  " U R                  U R                  XS9nU Vs/ s H  o`R                  U5      PM     sn$ s  snf s  snf )zreturn 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
)r  stoprevs)
r   r  r  r   r   r2   headrevssubsetr  r"  r]   )r   r   r  r  r  r  r   s          rO   rb  revlog.heads	  s     =T\t99}$&&((=EHHUOE)-4AHHQK4##IIt
 +//$3		#$// 5 0s   C&Cc                    U R                  X5      u  p4U Vs/ s H  oPR                  U5      PM     snU Vs/ s H  oPR                  U5      PM     sn4$ s  snf s  snf )zqreturn the nodes that make up the difference between
heads of revs before `start` and heads of revs before `stop`)r  r]   )r   r   r  removedrT  ra  s         rO   	diffheadsrevlog.diffheads	  sQ     **57&-.g		!g.u0Mu!1u0MMM.0Ms
   AAc                   / nU R                  U5      nU R                  US-   S9 H  nU R                  U5       Vs/ s H  oU[        :w  d  M  UPM     nnU(       a2  U H*  nXS:X  d  M
  UR	                  U R                  U5      5        M,     Mh  U[        :X  d  Mt  UR	                  U R                  U5      5        M     U$ s  snf )z!find the children of a given noder   )r   )r   r  r"  r   r  r]   )r   r]   r(  ri  ra  prprevss          rO   childrenrevlog.children
  s    HHTNQ'A"&//!"4F"4BgR"4EFBw1.   g1& (  Gs   C C c                    U R                  U5      U R                  U5      p!U R                  X5      n[        R                  " U R                  U5      $ )z@calculate all the heads of the common ancestors of nodes a and b)r   _commonancestorsheadsr6   maplistr]   r   ar  ancss       rO   commonancestorsheadsrevlog.commonancestorsheads
  s@    xx{DHHQK1))!/		400rR   c                     U R                   R                  " U6 nU$ ! [        [        4 a%    [        R                  " U R
                  /UQ76 n U$ f = f)z7calculate all the heads of the common ancestors of revs)r   r  r  r  r1   r"  )r   r  r  s      rO   r  revlog._commonancestorsheads
  s\    	I::22D
  . 	I00H4HD	Is    1AAc                f    U R                  U5      U R                  U5      p!U R                  X5      $ )z_return True if node a is an ancestor of node b

A revision is considered an ancestor of itself.)r   isancestorrevr   r  r  s      rO   
isancestorrevlog.isancestor
  s,     xx{DHHQK1!!!''rR   c           	     h    U[         :X  a  gX:X  a  gX:  a  g[        U R                  X/U/SS95      $ )zreturn 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)r   boolreachablerootsr  s      rO   r  revlog.isancestorrev&
  s?     <VUD''3'GHHrR   c                     U R                   R                  XX45      $ ! [         a%    [        R                  " U R
                  XX$5      s $ f = f)zdreturn (heads(::(<roots> and <roots>::<heads>)))

If includepath is True, return (<roots>::<heads>).)r   reachableroots2r  r2   _reachablerootspurer"  )r   minrootrb  r  r  s        rO   r  revlog.reachableroots5
  sR    	::--   	,, 	s    ,AAc                N   U R                  U5      U R                  U5      p! U R                  R                  X5      nU(       a  [        [        U R                  U5      5      $ U R                  $ ! [        [        4 a$    [
        R                  " U R                  X5      n Nef = f)z5calculate the "best" common ancestor of nodes a and b)r   r   r@  r  r  r1   r"  rj  mapr]   r  r  s       rO   r1   revlog.ancestorB
  s     xx{DHHQK1	=::''-D s499d+,,{{ . 	=%%dooq<D	=s   A0 01B$#B$c                   [        U[        5      (       a  U R                  U5      $ [        U5      U R                  R
                  :X  a   UnU R                  U5        U$  [        U5      nSU-  U:w  a  [        eUS:  a  [        U 5      U-   nUS:  d  U[        U 5      :  a  [        eU R                  U5      $ ! [        R                   a     Nqf = f! [        [        4 a     Of = f[        U5      SU R                  R
                  -  :X  aI   [        U5      nU R                  U5        U$ ! [        R                  [        R                  4 a     g f = fg )Ns   %dr   r  )r  ro   r]   r   r  nodelenr   r3   r  r  r  r	   r/  Error)r   idr]   r   s       rO   _matchrevlog._matchO
  s<   b#99R= r7d((000	b'Cs{b   Qw$i#oQw#T*  99S>! $$  M* 		r7a$,,44442wNNE$5$56  5s7   B; !AC ;CCC('C(D0 0$EEc                   U R                   R                  R                  U5      nSn U R                  R	                  U5      nU(       a"  U R                  U5      (       a  U(       a  SnOU$ U(       a  [        R                  eg U(       a*  [        R                  " XR                  [        S5      5      eXR                  ;   a  U R                  U   $ [!        U5      S::  Ga  [!        U5      S-  S-  n [!        U5      S-  S:  a  US   ["        ;  a  g [%        US U 5      nU R                   Vs/ s H"  owS	   R                  U5      (       d  M  US	   PM$     nnU V	s/ s H>  n	['        U	5      R                  U5      (       d  M$  U R                  U	5      (       d  M<  U	PM@     nn	U R                   R(                  R                  U5      (       a  UR+                  U R,                  5        [!        U5      S:  aW  [!        U5      S
:X  a  U(       d  US   U R                  U'   US   $ [        R                  " XR                  [        S5      5      eU(       a  [        R                  eg g ! [        R                   a    [        U SS 5      (       d  Sn GN[        [        4 a     GN$f = fs  snf s  sn	f ! [.        R0                   a     g f = f)NFTfilteredrevss   ambiguous identifier(   r  r   r   r  r   )r  wdirhex
startswithr   partialmatchr  r3   r   r.  r  r  r  AmbiguousPrefixLookupErrorr  r   rJ  r   	hexdigitsr	   r
   nullhexr  r  r/  r  )
r   r  	maybewdir	ambiguouspartialr  prefixr  nlr  s
             rO   _partialmatchrevlog._partialmatchq
  sg   &&..99"=			jj--G 4<<00 $I"N+++ 22OOQ'>%?  <<##r7b=B1q A r7Q;?rFi/#RV %)JJJJqA$//&2IdadJJ!!!SV%6%6r%:At||AAr   %%--88<<IIdkk*r7Q;2w!|I+-a5R(!!u::OOQ/F-G  ///9 #    	! 466 	
+ 		0 K	 >> sZ   AI, +I, -I, 6J7 J7 2J-	J-!#J2J2 J2,(J*J*)J*7KKc                    U R                  U5      nUb  U$ U R                  U5      nU(       a  U$ [        R                  " XR                  [        S5      5      e)zclocate a node based on:
- revision number or str(revision number)
- nodeid or subset of hex nodeid
s   no match found)r  r  r3   r  r  r   )r   r  r  s      rO   lookuprevlog.lookup
  sP    
 KKO=Hr"HOOQ7H5IJJrR   c                  ^ ^^	 UU 4S jnS m	[        T5      nU	4S jn[        T SS5      (       d/   T R                  R                  T5      n[	        Xb5      nU" XG5      $ TT R                  R                  :X  a5  [        U[        U5      S-   5       H  nUSU nU" U5      (       d  M  Us  $    [        U[        U5      S-   5       H  nUSU nU" U5      (       d  M  U" XG5      s  $    g! [
        R                   aH    TT R                  R                  :w  a+  [
        R                  " TT R                  [        S5      5      e N[         a     Nf = f)z7Find the shortest unambiguous prefix that matches node.c                   >  TR                  U 5      nUc+  [        R                  " TTR
                  [        S5      5      eg! [        R                   a     g[        R                   a     gf = f)NFTr  )r  r3   r  r   r  r  r   )r  matchednoder]   r   s     rO   isvalid revlog.shortest.<locals>.isvalid
  sk    "008 "''dooq}MM 33 (( s   A A/A/.A/c                N    [        S [        R                  " U 5       5       5      $ )Nc              3  *   #    U  H	  oS :H  v   M     g7f)   fNrK   )r^  r(  s     rO   r`  5revlog.shortest.<locals>.maybewdir.<locals>.<genexpr>
  s     G*FQDy*Fs   )allr6   iterbytestr)r  s    rO   r  "revlog.shortest.<locals>.maybewdir
  s    G(*>*>v*FGGGrR   c                p   > [        U[        U 5      S-   5       H  nU SU nT" U5      (       a  M  Us  $    g)zDisambiguate against wdirid.r   N)ru  r   )hexnode	minlengthr   r  r  s       rO   disambiguate%revlog.shortest.<locals>.disambiguate
  s9    	3w<!+;< &) ((!M =rR   r  Nr  r   )r
   r  r   shortestr~  r3   r.  r  r  r  r  r   r  ru  r   )
r   r]   r  r  r  r  r  r   r  r  s
   ``       @rO   r  revlog.shortest
  sG   
		H d)	" t^T22::.. X1#G44 4%%,,,	3w<!+;< &)6??!M =
 Is7|a'78FWf%Fv#G44 9 $$ 4--444++dooq}  5 " s   -C+ +AE	EEc                \    U R                  U5      u  p4[        R                  " X#U5      U:g  $ )z`compare text with a given file revision

returns True if text is different than what is stored.
)r)  rD   hashrevisionsha1)r   r]   rN   r  r  s        rO   cmp
revlog.cmp
  s,    
 d#++Db9TAArR   c                    U R                   U   S   nX!:X  a  [        $ U R                  R                  (       a  U$ US-
  $ r   r  r  s      rO   r  revlog.deltaparent
  r  rR   c                r    U R                   R                  U5      nU R                   R                  U l        U$ )r  )r*  r	  )r   r   rets      rO   r	  revlog.issnapshot	  s,    kk$$S)++00
rR   c                    U R                  U5      (       d  [        R                  " S5      e[        U R                  R                  U5      S   5      S-
  $ )z/number of snapshot in the chain before this ones   revision %d not a snapshotr   r   )r	  r3   rB  r   r*  r  r   s     rO   snapshotdepthrevlog.snapshotdepth  sG    s##(()FGG4;;**3/23a77rR   c                    U[         :w  a9  U R                  U5      U:X  a$  [        U R                  R	                  U5      5      $ [
        R                  " U R                  U5      U R                  U5      5      $ )zreturn 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.
)r   r  rk   r*  r  r4   textdiffr  )r   rev1rev2s      rO   revdiffrevlog.revdiff  sZ     7?t//5=++D122~~dll40$,,t2DEErR   c                $    U R                  U5      $ )zDreturn an uncompressed revision of a given node or revision
number.
_revisiondatar   	nodeorrevs     rO   rZ   revlog.revision   s     !!),,rR   c                v    [        U[        5      (       a  UnOU R                  U5      nU R                  U5      $ )za 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  ro   r   	_sidedata)r   r  r   s      rO   rC   revlog.sidedata&  s3     i%%C((9%C~~c""rR   c                   U R                   R                  (       a8  U R                   R                  S   U:X  a  X R                   R                  S   S4$ Uc  U R                  U5      nU R                   R                  X5      nX#S4$ )zZreturn the possibly unvalidated rawtext for a revision

returns (rev, rawtext, validated)
r   r  TF)r*  r   r   r  )r   r]   r   rN   s       rO   _rawtextrevlog._rawtext4  ss     ;;%%{{))!,4[[77:DAA;((4.C{{##D.5!!rR   c                   [        U[        5      (       a  UnU R                  U5      nOUnS nX@R                  :X  a  gU R	                  XC5      u  p5nU(       a	  U(       a  U$ Uc  U R                  U5      nU R                  U5      nU(       a  U[        :X  a  U$ U(       a  [        R                  " XU5      nUn	O[        R                  " XU5      n
U
u  pU(       a  U R                  XUS9  U(       d  XCU4U R                  l        U	$ )NrR   )r   )r  ro   r]   r  r  r   rp   r(   r>   processflagsrawprocessflagsread	checkhashr*  r   )r   r  rawr   r]   r  	validatedrp   validatehashrN   ra  s              rO   r  revlog._revisiondataE  s    i%%C99S>DDC ;; #'--":i9 N;((4.C 

3"66N#33D5ILD))$?A!"DNN43N/*.W)=DKK&rR   c                    U R                   c  0 $ SnU R                  b  U R                  R                  nU R                  R	                  X5      $ )r  N)r<  rH  r]  r*  rC   )r   r   r]  s      rO   r
  revlog._sidedataq  sF    %I<<#<<44L{{##C66rR   c                "    U R                  USS9$ )zCreturn an uncompressed raw data of a given node or revision number.T)r  r  r  s     rO   r  revlog.rawdataz  s    !!)!66rR   c                0    [         R                  " XU5      $ )zaCompute a node hash.

Available as a function so that subclasses can replace the hash
as needed.
)rD   r  )r   rN   r  r  s       rO   hashrevlog.hash~  s     ++Db99rR   c                    Uc  Uc  U R                  U5      u  p4X R                  XU5      :w  a  U R                  R                  (       a.  U R                  R                  S   U:X  a  SU R                  l        UnUc  [        R
                  " [        U5      5      n[        R                  " [        S5      U R                  [        R                  " U5      4-  5      eg! [        R                   aY    U R                  R                  (       a<  [        R                   " U5      (       a!  [        R"                  " U R                  X!5      ee f = f)zuCheck node hash integrity.

Available as a function so that subclasses can extend hash mismatch
behaviors as needed.
Nr   s   integrity check failed on %s:%s)r)  r  r*  r   r8   r   r
   r3   r.  r   r  r6   bytestrr   r   rD   iscensoredtextCensoredNodeError)r   rN   r]   r  r  r   	revornodes          rO   r  revlog.checkhash  s   	zbjd+yy2.. KK..2215=15DKK.	$ / 5 5c$i @I''89(8(8(CDE ! /(    	""--+2L2L3 3 --dootJJ	s   CC   A-Ec                    U R                   R                  S5      n[        U5      S:  a0  US   S-   nUSS nUS   S-   nU/U-   U/-   nSR                  U5      $ U R                   S-   $ )zthe path where to expect the index of an ongoing splitting operation

The file will only exist if a splitting operation is in progress, but
it is always expected at the same location.   /r   r   s   -sr   s   .is   .i.s)r9  splitr   r  )r   partsr  midstailpiecess         rO   r  revlog._split_index_file  s|     

  &u:>8e#D2;D9u$DVd]dV+F99V$$ ::''rR   c                  ^
^^^ [        U 5      S-
  nU R                  U5      U R                  U5      -   nU R                  (       a  U R                  (       a  U[
        :  a  gU R                  b  Sn[        R                  " U5      eUR                  U R                  R                  5      nUSLnU(       dC  U R                  S   [        :w  a,  [        R                  " [        S5      U R                   -  5      eUR#                  U R                  R                  US9  UR%                  U R&                  S5        Sm
U R                   mU R(                  m
U R*                  m[,        R.                  " U 5      mU
UUU4S jnUU4S jnUR1                  T
5        U R                  S   b  S	U R                  -  n	OS
U R                  S   -  n	UR3                  X5        UR5                  X5        U =R6                  [8        ) -  sl        U R                  R;                  UU R6                  U R<                  -  T
S9  SU l        T
b  T
U l        [>        R@                  " X5        g)zCheck 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.
r   Ns&   inline revlog should not have a docketr   s   %s not found in the transaction)
for_offsetc                   > TR                  TTSS9  T" 5       nUb#  TUl        UR                  UR                  l        g g )NTr  )r  r:  r*  r   )r{  
maybe_selfr}  old_index_file_pathr   	weak_selfs     rO   finalize_callback4revlog._enforceinlinesize.<locals>.finalize_callback  sM    MM##  
 #J%(;
%/9/D/D
!!, &rR   c                n   > T" 5       nUb*  TUl         SUR                  l        TUR                  l        g g r  )r:  r*  r   r   )r{  r/  r0  r1  s     rO   abort_callback1revlog._enforceinlinesize.<locals>.abort_callback  s9    "J%(;
%+/
!!(/B
!!, &rR   s   001-revlog-split-%d-%ss   001-revlog-split-%d)r}  F)!r   r   r   r  rA  
_maxinlinerH  r3   rB  
findoffsetr*  r   rE  r   r.  r   r:  	addbackuprY   r;  r  r   weakrefrefregistertmpaddfinalizeaddabortr1  r   r  r2  rC  r  )r   r{  r  
total_sizerE  troffsetpre_touchedr2  r5  callback_idr}  r0  r   r1  s             @@@@rO   _enforceinlinesizerevlog._enforceinlinesize  s    TQZZ'$++f*==
|| 0 0Z*5L<<#;C((--
 ==!A!ABd*t{{1~?##45G  	T[[55+N
t~~q!""oo"44KK%			E 		E	C 	*+ ;;q>%3dkkAK04;;q>AK
{6
K0///  !5!55 3 	! 	
 *1DO,,R6rR   c                    g)z0called when trying to add a node already stored.NrK   )r   r[  r]   s      rO   _nodeduplicatecallbackrevlog._nodeduplicatecallback  s    rR   c              #  |   #    U R                   R                  5          S v   S S S 5        g ! , (       d  f       g = f7fr|   )r*  rC  r   s    rO   rC  revlog.reading  s#     [[  " #""s   <+	<
9<c              #    #    U R                   (       a&  SnX R                  -  n[        R                  " U5      eU R                  R
                  (       a  S v   g S nS nU R                  b,  U R                  R                  nU R                  R                  nU R                  R                  UUUS9   S v   U R                  b  U R                  U5        S S S 5        g ! , (       d  f       g = f7f)Ns)   try to write in a `trypending` revlog: %s)r\  r]  )r?  r  r3   rB  r*  rH  rH  r\  r]  rd  _write_docket)r   r[  rE  r\  r]  s        rO   _writingrevlog._writing  s     >C??"C((--;;!!HL||'<<00#||88$$!) % 
 <<+&&{3  s   B0C/2#C	C/
C,(C/c                .    U R                   R                  $ r|   )r*  r   r   s    rO   r   revlog.is_delaying+  s    {{&&&rR   c                :    U R                   R                  U5        g)zwrite 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)rH  rv  r  s     rO   rK  revlog._write_docket/  s     	;'rR   c                   U[         :X  a,  [        R                  " [        S5      U R                  -  5      eU
c  0 n
OAU
(       a:  U R
                  R                  (       d  [        R                  " [        S5      5      eU(       a  U=(       d    U R                  XU5      n[        R                  " XU5      u  pX:w  a  Sn[        U5      [        :  a7  [        R                  " [        S5      U R                  [        U5      4-  5      eU=(       d    U R                  XU5      nU R                  R                  U5      nUb  U$ U(       a  U R                  XXES9  U R!                  UUUUUUUUU	U
S9
$ )aC  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 %sNs9   trying 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deltacomputerrC   )r   r3   r.  r   r  r   r   rB  r  r>   processflagswriter   _maxentrysizer   get_revr  addrawrevision)r   rN   r[  r  r  r  rS  r]   rp   rT  rC   r  r  r   s                 rO   addrevisionrevlog.addrevision8  sd   6 7?##67$//I  Hd11??((NO  2499Tr2D ( : :4u M ?Jw<-'##R ??CL12  1tyyb1jj  &?JNN7RN7""!' # 
 	
rR   c                    U R                  U5         U R                  UUUUUUUUU	U
S9
sSSS5        $ ! , (       d  f       g= f)zadd 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).
rT  rC   N)rL  _addrevision)r   r  r[  r  r  r  r]   rp   rS  rT  rC   s              rO   rX  revlog.addrawrevision  sM    " ]];'$$+! %  (''s	   4
Ac                8    U R                   R                  U5      $ r|   )r*  r6  r   r   s     rO   r6  revlog.compress  s    {{##D))rR   c                8    U R                   R                  U5      $ r|   )r*  r&  r`  s     rO   r&  revlog.decompress  s    {{%%d++rR   c                   XR                   :X  a,  [        R                  " [        S5      U R                  -  5      eXR
                  R                  :X  d  XR
                  R                  ;   a,  [        R                  " [        S5      U R                  -  5      eU R                  R                  (       d  Sn[        R                  " U5      eU/n[        U 5      nUS-
  nU R                  U5      nU R                  (       a  U R                  R                  u  nnnU R                  (       a7  U R                  UU R                   UXR"                  R$                  -  -   5        OPU R                  UU R                   XR"                  R$                  -  5        U R                  UU R&                  U5        U R)                  U5      U R)                  U5      nnUc1  [*        R,                  " [.        R1                  XS   5      US   5      nO[        U5      nU
c>  SnU R2                  R4                  (       a  UR6                  n[8        R:                  " U US9n
Ub]  [        U5      S:X  aN  U R2                  R<                  (       a"  U R2                  R>                  (       a  [@        nO[B        nUS   US   U4n[D        RF                  " UUUUUUU5      nU
RI                  U5      n[J        nU RL                  b2  U RL                  RN                  n[8        RP                  " UU5      nUu  nn[J        nU(       a  U RR                  RT                  (       a  [V        n[X        RZ                  " U5      nU RL                  R\                  n U R                  R_                  U5      u  n!n"U!S	:w  aX  U"SS S
:w  aO  [        U"5      [        U5      :  a7  U!(       a   eU"SS U RL                  RN                  :X  a	  [`        nU"nO[J        nU"nOSnSn [b        n#U RR                  Rd                  (       a  UU4[f        [f        4:X  a  Sn#OU[f        :w  a  U[f        :X  a  SU Ri                  U5      -   n#OU[f        :X  a  U[f        :w  a  SU Ri                  U5      -   n#O[j        b=  U R"                  Rl                  (       a"  [j        Ro                  U R"                  UU5      n#OK[q        UU45      u  n$n%SU Ri                  U%5      -   n#U#[s        S U Ru                  U%/U$/5       5       5      -  n#[D        Rv                  " UUURx                  UUURz                  UUUUU [        U5      UU#S9n&U R"                  R}                  U&5        U R"                  R                  U5      n'US:X  aF  U RL                  c9  U R                  U R                  -  n(U R"                  R                  U(5      n(U(U'-   n'U R                  UU'UR                  UUUU 5        US   nU	(       a  Uc  U
R                  U5      n[        U5      [        :X  a  XU4U R                  lH        UR                  U R                  U'   U$ )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 revisionr  r   Nr   write_debugr  r5  r4  rR   c              3  &   #    U  H  nS v   M	     g7f)r   NrK   )r^  r   s     rO   r`  &revlog._addrevision.<locals>.<genexpr>K  s     P+Oa+Os   )rp   data_offsetdata_compressed_lengthdata_uncompressed_lengthdata_compression_modedata_delta_baselink_revparent_rev_1parent_rev_2node_idr  sidedata_compressed_lengthsidedata_compression_moder  )Kr  r3   r.  r   r  r  r  r  r*  rH  rB  r   _get_data_offsetrP  r   r  r:  r   rW  r;  r   r4   patchedsizerH   ro  r   r   _reportr  rT  r   r   r   r   r7   revisioninfofinddeltainfor   rH  r   delta_compressionr   r   r   r  serialize_sidedatar]  r6  r   r   r   r   r  r  r:  r  sortedsumrw  r  deltalenr  r  ry  r1  r2  rz  _writeentryr   	buildtextrc   rk   r   r  rG  ))r   r]   r  r[  r  r  r  rp   rS  alwayscacherT  rC   rE  btextr  prevr  r^  r_  r`  p1rp2rtextlenrf  delta_base_reuserevinfo	deltainfor  default_compra  rs  serialized_sidedatar  hcomp_sidedatar  pminpmaxr  r  r|  s)                                            rO   r]  revlog._addrevision  s   6 ;;##56H  &&---))999##56H  {{%%FC((--	4yax&&t,##![[88NCd|| ((&4**:O:O3O*O
 (($1F1F*F ((dnnfE88B<"S ? ''DQ-0*Q-G 'lG K  ,,)11%33+M !c*o&:
 !!//%%55#7 #6 $Q-A8HIJ**
 "//8	+<<#<<BBL++L)DA*+'i$4!++99(7%"."A"A("K"ll77O#{{334GHA}T	!!A&%/&-@)AAu!!A&||>>? 1B-*7'0@-*7'"%  O++Szgw//C7N4>>#..C7N4>>#..(TZZ-G-G$>>$**c3?D!'c
!3JD$t~~d33DCP4+?+?+OPPPD#,#5#5%,"2%NN+'*+>'?&?
" 	

!

''-19-''$*>*>>FZZ++F3FUNENN	
 (7?#--g6G=E!*.g)>DKK&%.%8%8T"rR   c                j    U R                   c  U R                  U5      $ U R                   R                  $ )a  Returns 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.)rH  r   r\  )r   r  s     rO   rt  revlog._get_data_offsetx  s,     <<88D>!<<(((rR   c                   S =n=pU R                   bB  U R                   R                  nU R                   R                  n	U R                   R                  n
U R                  R                  UUUUUUUUU	U
5
      nU R                  U5        U R                   b<  US   U R                   l        US   U R                   l        US   U R                   l        [        R                  " X5        g )Nr   r   r  )	rH  rj  r\  r]  r*  r  rC  rC  r  )r   r[  r  r   r  r  rC   r  rj  r\  r]  	files_ends               rO   r~  revlog._writeentry  s    , /32	2H<<#..I||,,H<<44LKK++
	 	,<<#%.q\DLL"$-aLDLL!(1!DLL%,,[?rR   c	                ,   U R                   (       a  [        R                  " S5      eUcC  U R                  R                  (       a"  U R                  R
                  (       a  [        nO[        nSU l         Sn	 U R                  U5         Sn
U R                  R                  (       a  UR                  n
[        R                  " U U
US9nU GH  nUu  nnnnnnnnU" U5      nU=(       d    [        nU R                  R                  U5      nUb&  U R!                  UU5        U(       a	  U" U U5        Sn	Mj  X4 HN  nU R                  R#                  U5      (       a  M%  [        R$                  " UU R&                  [)        S5      5      e   U R                  R#                  U5      (       d+  [        R$                  " UU R*                  [)        S5      5      eU R-                  U5      nU[.        :w  a  U R1                  U5      (       a  [2        R4                  " S5      nU R7                  U5      n[9        U5      U-
  nUSU [:        R<                  " UU5      :w  a0  [        R>                  " U R*                  U RA                  U5      5      eU(       d   U RC                  UU5      (       a	  U[D        -  nU RG                  USUUUUUUUU4UUUS	9nU(       a	  U" U U5        Sn	GM     SSS5        SU l         U	(       + $ ! , (       d  f       N= f! SU l         f = f)
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.
s   cannot nest addgroup() callsNT)rf  
debug_infoFs   unknown parents   unknown delta bases   >lll)r  rT  rC   )$rM  r3   rB  r   r   r   r   r   rL  r   rv  r  rT  r(   r   rW  rF  has_noder  r9  r   r  r   r   
iscensoredstructcalcsizer  r   r4   replacediffheaderCensoredBaseErrorr]   _peek_iscensoredr-   r]  )r   r<   
linkmapperr[  r  addrevisioncbduplicaterevisioncbr  delta_base_reuse_policyemptyrf  rT  r   r]   r  r  rt   	deltabaserr   rp   rC   r  r   ri  r  hlenoldlennewlens                               rO   addgrouprevlog.addgroup  s   , (()HII #*!!//%%55*>'*='!X	'{+"$$00"-"5"5K ) 7 7 +)! #D 	 ! %h/D!9%9E**,,T2C33KE./c: %  X#zz22155"'"3"3 !4::q1B/C#  &  ::..y99#//%t:O8P  #hhy1G')doog.F.F  &w7!%g!6!$Ud!2 $<5+B+B"F,  #("9"9 $71C#  !T%:%:7E%J%J!22 ++# %)@A$/&3!) , C %%dC0!EW # ,n "'Dyq ,+n "'Ds,   8L
 	CK9FK9#L
 9
LL
 
	Lc                j    U R                   R                  (       d  gU R                  U5      [        -  $ )z%Check if a file revision is censored.F)r   r   rp   r-   r   s     rO   r  revlog.iscensored7  s(    ""--zz#!222rR   c                |    U R                   R                  (       d  g[        R                  " X!U R                  5      $ )z6Quickly check if a delta produces a censored revision.F)r   r   rD   deltaiscensoredr  )r   r  rr   s      rO   r  revlog._peek_iscensored>  s+    ""--**54<<HHrR   c                    [         R                  " U[        U 5      S-
  U R                  5       U R                  U R
                  5      $ )zfind 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   )rD   resolvestripinfor   rt  r  r"  )r   minlinks     rO   getstrippointrevlog.getstrippointE  s<     ++IMMMOLLOO
 	
rR   c                :   [        U 5      S:X  a  gU R                  U5      u  p4U[        U 5      :X  a  gU R                  U5      nU R                  (       d5  UR	                  U R
                  U5        X0R                  R                  -  nOXSU R                  R                  -  -   nU R                  (       a-  U R                  U5      nUR	                  U R                  U5        UR	                  U R                  U5        U R                  bK  X`R                  l        XPR                  l        WU R                  l        U R                  R                  USS9  [         R"                  " S5      U l        U R&                  R)                  5         U R                  US2	 g)a  truncate 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.
r   NT)	strippingr  r   )r   r  r   r  rY   r;  r   rW  r<  r  r:  rH  rj  r\  r]  rv  r9   r   r  r*  r   )r   r  r[  r   r   r\  r   r]  s           rO   striprevlog.stripS  s;    t9>##G,#d) ::c?||OODNNH5

---CDJJ$9$99:C005LOOD..=-<<# &)LL"$,LL!(4DLL%LL{d;  $005!JJs2vrR   c                4   Sn[        U 5      (       a'  [        SU R                  [        U 5      S-
  5      5      n U R                  5        nUR	                  S[
        R                  5        UR                  5       nSSS5        WU-
  n U R                  U R                  5      nUR	                  S[
        R                  5        UR                  5       nUR                  5         U R                  R                  n[        SX5-  5      nX6U-  -
  nU R                  (       a?  SnU  H!  n	U[        SU R                  U	5      5      -  nM#     SnU[        U 5      U-  -
  U-
  nXG4$ ! , (       d  f       N= f! [         a    Sn Nf = f! [         a    Sn XG4$ f = f)zCheck 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).
r   r   N)r   r~  r   r  rR  iorT  r  rV  r   r:  rZ  r   rW  r  r   )
r   expectedrk  actualddsr  di	databytesra  s
             rO   	checksizerevlog.checksize  s`    t991dhhs4y1}56H	1q"++&   ("B	DOO,AFF1bkk"VVXFGGI

%%AAv{#Aq5!B||	AQA!77I c$i!m+i7 x1   ! 	B	" ! 	Bx	s<   E4 1E#<E4 
CF #
E1-E4 4FFFFc                   U R                   /nU R                  c.  U R                  (       d  UR                  U R                  5        U$ UR                  U R                  5        UR                  U R                  R                  SS95        U R                  R                  (       a  UR                  U R                  5        UR                  U R                  R                  SS95        U R                  R                  (       a  UR                  U R                  5        UR                  U R                  R                  SS95        U$ )z-return list of files that compose this revlogF)include_empty)r:  r6  r  r  r;  extendrH  old_index_filepathsr\  old_data_filepathsr]  r<  old_sidedata_filepaths)r   ress     rO   filesrevlog.files  s    $<<

4>>* 
 JJt(()JJt||77e7LM||$$

4>>*JJt||66U6KL||((

4--.JJt||:::OP
rR   c                   US;  a  [         R                  " SU-  5      eUc  U R                  R                  (       d  SnU R                  (       d$  U[
        R                  :w  a  [
        R                  n[        R                  " U UU[        U R                  U R                  U R                  U R                  U R                  UUUUUS9$ )N)s   nodes   storages   linearNs"   unhandled value for nodesorder: %sr  )
deltaparentfn
candeltafn	rawsizefn	revdifffnflagsfn	deltamoderevisiondataassumehaveparentrevisionssidedata_helpersr  )r3   rB  r   r   r  r;   CG_DELTAMODE_PREVCG_DELTAMODE_FULLrD   emitrevisionsra   r  r  r  r  rp   )r   nodes
nodesorderr  r  r  r  r  s           rO   r  revlog.emitrevisions  s     DD((5
B  d&7&7&E&E#J &&Z999"44I((**~~llllJJ%&?-!
 	
rR      always   samerevs   never   fulladd>   r  r  r  r  c           
        X@R                   ;  a  [        [        S5      U-  5      e[        U5      (       a  [        [        S5      5      e[	        U SS5      (       a  [        [        S5      5      e[	        USS5      (       a  [        [        S5      5      eUR
                  nUR
                  R                  5       Ul         X@R                  :X  a#  SUR
                  l        SUR
                  l	        OcX@R                  :X  a#  SUR
                  l        SUR
                  l	        O1X@R                  :X  a"  SUR
                  l        SUR
                  l	        U=(       d    UR                  nXR
                  l        U R                  5          UR                  U5         U R                  UUUUUU5        SSS5        SSS5        Xrl        g! , (       d  f       N= f! , (       d  f       N&= f! Xrl        f = f)	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: %ss   destination revlog is not emptyr  Ns$   source revlog has filtered revisionss)   destination revlog has filtered revisionsTF)DELTAREUSEALLr  r   r   r  r   r   DELTAREUSEALWAYSr   r   DELTAREUSESAMEREVSDELTAREUSENEVERr   rC  rL  _clone)	r   r{  
destrevlogr  
deltareuseforcedeltabothparentsr  old_delta_configr   s	            rO   clonerevlog.clone  s   j ///56C  z??QABCC4..QFGHH:~t44QKLMM &22","9"9">">"@
	7222:>
''759
''2666:?
''759
''2333:?
''75:
''2 &L)9)L)L  :L##6!4!4R!8!)$ "9 '7# "9!8 '7#s=   C
G/ GG6G>G/ 
G	G
G,(G/ /G7c                Z   SnU R                   R                  (       a  UR                  n[        R                  " UUS9nU R
                  n	U  GH  n
X   nUS   S-  nUS   nXS      S   nXS      S   nUS   nSnSnX@R                  :X  ah  U R                  U
5      nU R                  U
5      nUb*  [        R                  " XUU
5      u  nnUUS   US	   ) -  -  nUR                  UUUUUUUUUUS
9
  OUR                   R                  (       aA  U R                  U
5      nU[        :w  a&  U[        U R                   R#                  U
5      5      4nSnU(       d#   U R                  U
5      nU R                  U
5      nUc  U R                  U
5      nUb*  [        R                  " XUU
5      u  nnUUS   US	   ) -  -  nUR-                  UUUUUUUUUUS9
  U(       d  GM  U" X
U5        GM     g! [$        R&                   a&  nU[(        -  (       d   eUR*                  n SnANSnAff = f)zBperform the core duty of `revlog.clone` after parameter processingNre  r   r-  r  r
  r  r  r   )rS  r]   rp   rT  rC   r\  )r   r   rv  r  rT  r   DELTAREUSEFULLADDr  rC   r  run_sidedata_helpersrY  r   r  r   rk   r*  r  r3   r!  r-   	tombstoner]  )r   r{  r  r  r  r  r  rf  rT  r   r   r  rp   r  r  r  r]   rS  r  rN   rC   	new_flagsdpcensoreds                           rO   r  revlog._cloneQ  ss    ((**K!//#
 

CJE !Hv%EAhGQx#BQx#B8D JG333))#.==-#/,8,M,M#-)Xy "IaLIaL=$@@E&&)"/% '  **55))#.BW}&(%0B0B30G*H%I
!5"&"4"4S"9  $}}S1H##}}S1H#/,8,M,M#-)Xy "IaLIaL=$@@E''"/% (  }d.U ^ !22 5$'8888"*"4"45s   G00H*H%%H*c                
   U R                   [        :X  a,  [        R                  " [	        S5      U R                   -  5      eU R                   [
        :X  a  [        R                  " XX#5        g [        R                  " XX#5        g )Ns%   cannot censor with version %d revlogs)	r2  r   r3   r.  r   r    rB   	v1_censor	v2_censor)r   r{  censor_nodesr  s       rO   censorrevisionrevlog.censorrevision  sj    8+##:;&&'  !!X-d@d@rR   c           	   #    #    U R                  5       u  p#U(       a  [        [        S5      U-  S9v   U(       a  [        [        S5      U-  S9v   U R                  nXAS   :w  a&  [        [        S5      U R                  XAS   4-  S9v   [        5       US'   [        5       US'   U  H  nU R                  U5      n UR                  S	S
5      nU(       a  XpR                  U5      -  n[        XX5        U R                  U5      n[        U R                  U5      5      n	X:w  a  [        [        S5      X4-  US9v   M  M     g! [        R                   a:    US   (       a,  [        [        S5      US9v   US   R                  U5         M   M  [          aW  n
[        [        S5      [#        U5      [$        R&                  " U
5      4-  US9v   US   R                  U5         Sn
A
GME  Sn
A
ff = f7f)znVerifies the integrity of the revlog.

Yields ``revlogproblem`` instances describing problems that are
found.
s   data length off by %d bytes)r3   s   index contains %d extra bytess   expectedversions0   warning: '%s' uses revlog format %d; expected %d)rz   rX   s   safe_renameds	   skipflagsr   s    unpacked size is %d, %d expected)r3   r]   s   erroroncensoreds   censored file datas   unpacking %s: %sN)r  rx   r   r2  r  rJ  r]   r  rp   r^   r  r   r  r3   r!  rY   	Exceptionr   rE   r=  )r   r\   r  r  versionr   r]   r[   l1l2r  s              rO   verifyintegrityrevlog.verifyintegrity  s     !a(F&G"&LMMa(H&IB&NOO&& .//MN??G3E-FGH 
 !Uk!$oC99S>Dd-!IIlA6	C0I %>\\#&d+,8' CDxO!  { F ** 1+,' 56T  +&**40	 -
  -#/0T{J$;$;A$>?@ 
 k"&&t,,-s?   B9G4<BE=G4AG1G4	G1AG,%G4,G11G4c                  ^  0 nU(       aW  T R                   T R                  4/US'   T R                  (       d*  US   R                  T R                   T R                  45        U(       a  / US'   U(       a  [        T 5      US'   U(       a+  [        [        T R                  [        T 5      5      5      US'   U(       a&  [        U 4S jT R                  5        5       5      US'   U$ )Ns   exclusivefiless   sharedfiless   revisionscounts   trackedsizec              3  n   >#    U  H*  nTR                   R                  U5      R                  v   M,     g 7fr|   )r   statrh  )r^  r  r   s     rO   r`  %revlog.storageinfo.<locals>.<genexpr><  s)      #;G4  &..<s   25s
   storedsize)r   r:  r  r  r;  r   r|  r  r  r  r  )r   exclusivefilessharedfilesrevisionscounttrackedsize
storedsizer  s   `      rO   storageinforevlog.storageinfo#  s     %)[[$//$B#CA <<#$++T[[$..,IJ "An#&t9A  #Cd4j$A BAn" #;?::<#  Am rR   c           	        U R                   R                  (       d  g U R                  (       a   eUS   (       d  US   (       d  g / nU R                  U5         U R                  R
                  u  pgnUR                  U R                  R                  [        R                  5        UR                  5       n	[        X4S-   5       GH  n
U R                  U
   n[        R                  " U U0 U
S9u  p[        R                   " U5      n["        nU(       a  U R                   R                  (       a  [$        nU R                  R'                  U5      u  nnUS:w  aX  US   S:w  aO  [)        U5      [)        U5      :  a7  U(       a   eUS   U R                  R*                  :X  a	  [,        nUnO["        nUnUS   S:w  d	  US   S:w  a  S	n[.        R0                  " U5      eUS   US   US   ) -  -  nU	[)        U5      UU4nUR                  U	[        R                  5        UR3                  U5        UR5                  U5        U	[)        U5      -  n	UR                  5       U R                  l        GM     UR                  X0R                  R6                  -  5        [9        U5       H  u  nnUU-   n
U R                  R:                  " U
/UQ76   U R                  R=                  U
5      nU
S:X  aF  U R                  c9  U R>                  U R@                  -  nU R                  RC                  U5      nUU-   nUR3                  U5        M     S S S 5        g ! , (       d  f       g = f)
Nr   r  )storer  rC   r   r5  r   r4  r  r  s0   rewriting existing sidedata is not supported yet)"r   r   r  rL  r*  r   rR  rH  r]  rS  rU  r  ru  r   r  r  rz  r   r   r6  r   r   r   r3   Abortrv  r  rW  	enumeratereplace_sidedata_infory  r1  r2  rz  )r   r[  helpersr  r  new_entriesr^  r_  r`  current_offsetr   r  new_sidedatarp   r  rs  r  r  rE  new_offset_flagsentry_updater  r  packedr|  s                            rO   rewrite_sidedatarevlog.rewrite_sidedataB  s   ""00<<qz'!*]];'![[88NCdHHT\\..<!YY[NXz2

3&2&G&G%,	'# '3&E&E '# -=)&4+>+>+L+L0?-'+{{';';<O'P$A}T	)!,5.5H1II#$u)!,#||FFG 9J52?/8H52?/8q=E!HM NC++c** $)8eAh%(.B#B "+,$-	  		."++6

./""<0#&9"::,0IIK)m 3r HHX

 5 556!+.1l

00 005!8 4!//$2F2FFF!ZZ33F;F#f_F		&! / (''s   K-M
M)#rM  rG  r  rP  r;  rH  r6  rL  r1  r2  r:  r  r  r*  rA  rI  r=  r  rJ  r<  r  r@  r?  r   r   r   r   r	  r  r  r   r>  r9  rE  rB  )NFFFNFNFFTNNNTr  r|   )F)rv  )r  zIterator[int])r   N)r  r  r  None)r   Fr  )r   )NNNr  )FNN)FNNNN)rR   )r  z#Iterable[repository.iverifyproblem])FFFFF)rf   rg   rh   ri   r   r3   r.  _flagserrorclassr  staticmethodr4  r   rd  rq  r  rN  rO  r  r  r9   r  rZ  r  r  r  r  r  r   r  r  r  r  r  r  r   r   r  rp   r   r  r  ro  r  r  r  r"  r=  r]   r   r)  r-  r,  r  r@  rD  rk  rp  rw  rz  r  rt  r  r  r  rb  r  r  r  r  r  r  r  r1   r  r  r  r  r  r  r	  r  r  rZ   rC   r  r  r
  r  r  r  r  r  rC  rF  r  r  rC  rL  r   rK  r(   rY  rX  r6  r&  r]  rt  r~  r  r  r  r  r  r  r  r;   CG_DELTAMODE_STDr  r  r  r  r  r  r  r  r  r  r	  r  ru   rK   rR   rO   rH   rH   $  s   +Z ((2 2 "! #%`6`6D9=v8iV`!D9+v( 
  
 6#($&G	H,J&-"+""
'$"& &2*'>=N*F>:@M +0C4^*@?N

;02N1(I D@DK45lB8	F-#""*X77:"H ( ($M7^?   4 4, ' '(  "L
n >*, KZ).@j   $B3I
.`&P( "'--'
R !$O"BM %"b7H\/|	Ag-V >T"rR   )r   
__future__r   r/  rc  r  r  rS  r  typingr:  r<  r   r   r   r   r]   r	   r
   r   r   r   r   i18nr   revlogutils.constantsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   revlogutils.flagutilr(   r)   r*   r+   r,   r-   r.   
thirdpartyr/   TYPE_CHECKINGpure.parsersr0    r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r  
interfacesr;   r<   r  r=   r  r>   r?   rC  r@   rA   rB   rC   r  utilsrD   rE   	importmodrF   
importrustr9  r  r  r&  r;  r7  rP   rT   rV   r[  r^   r  HAS_FAST_PERSISTENT_NODEMAPr  irevisiondeltara   iverifyproblemrx   r   r   r   r   rV  r  r  r   r   r   r   r   	ProxyBaseobjectr  r  rH   rK   rR   rO   <module>r/     s   #    	 	             4    
-  	 	 	 	                 


9
%  $7gD1	xd3
 // 

   )4 9 
 d;*33 ; ; t7J-- 7 7 7/00 "
 ; 
 &	/ /
 G  
:  *  * 
 *F -' - 
-<x) x)v 
II2Y 2@) )4r-" r-"rR   