
    	^c                       d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0 dd	l1m2Z2 dd
l3m4Z4m5Z5m6Z6m7Z7m8Z8mZm9Z9m:Z:m;Z; ddl<m=Z=m;Z> ddl9m?Z@mAZBmCZCmDZEmFZFmGZGmHZHmIZJ ddlKmLZLmMZM e  e! e# e e e e% e& e' e" e$ e/ e+ e. e, e* e- e0  e8jN        d          ZO e8jP        d          ZQ e8jP        d          ZR e8jP        d          ZSejT        ZUdZVd ZWd ZXd ZYeWeXeYfZZd Z[eSdup e;j\        eOd          Z] e>j^        e=j_                   e2j`        d           G d d                                  Za e>j^        e=jb                   e2j`        d           G d d                                  Zcd Zdd  Zed! Zf e;j\        eOd"          rd# ZgndZgd$ Zhd%Zi ed&          Zjd'Zk G d( d          ZldS ))zStorage back-end for Mercurial.

This provides efficient delta storage with O(1) retrieve and append
and O(changes) merge between branches.
    N   )binhexnullrevsha1nodeconstantsshortwdirrev)_)getattr)	ALL_KINDSCHANGELOGV2COMP_MODE_DEFAULTCOMP_MODE_INLINECOMP_MODE_PLAIN
ENTRY_RANKFEATURES_BY_VERSIONFLAG_GENERALDELTAFLAG_INLINE_DATAINDEX_HEADERKIND_CHANGELOGRANK_UNKNOWNREVLOGV0REVLOGV1REVLOGV1_FLAGSREVLOGV2REVLOGV2_FLAGSREVLOG_DEFAULT_FLAGSREVLOG_DEFAULT_FORMATREVLOG_DEFAULT_VERSIONSUPPORTED_FLAGS)REVIDX_DEFAULT_FLAGSREVIDX_ELLIPSISREVIDX_EXTSTOREDREVIDX_FLAGS_ORDERREVIDX_HASCOPIESINFOREVIDX_ISCENSOREDREVIDX_RAWTEXT_CHANGING_FLAGS)attr)	ancestordagoperrormdiffpolicypycompatrevlogutilstemplatefiltersutil)
repositoryr1   )deltasdocketflagutilnodemaprandomaccessfilerevlogv0rewritesidedata)storageutil
stringutilparsersr)   r*   revlogi   c                 
    |dfS NF rltexts     2/usr/lib/python3/dist-packages/mercurial/revlog.pyellipsisreadprocessorrF          ;    c                 
    |dfS r@   rA   rB   s     rE   ellipsiswriteprocessorrJ      rG   rH   c                     dS r@   rA   rB   s     rE   ellipsisrawprocessorrL      s    5rH   c                 n    |r|d                              |           dS |                     |           dS )z}Verify the integrity of the given revlog ``node`` while providing a hook
    point for extensions to influence the operation.   skipreadN)addrevision)rC   	skipflagsstatenodes       rE   _verify_revisionrT      sE      kt$$$$$ 	DrH   BaseIndexObjectT)slotsc                   \   e Zd Z ej                    Z ej                    Z ej                    Z ej                    Z ej                    Z	 ej                    Z
 ej                    Z ej                    Z ej                    Z ej                    Z ej        d          ZdS )revlogrevisiondeltaNdefault)__name__
__module____qualname__r(   ibrS   p1nodep2nodebasenodeflagsbaserevisionsizerP   deltar:   protocol_flagslinknoderA   rH   rE   rX   rX      s         4799DTWYYFTWYYFtwyyHDGIIEtwyytwyyHDGIIEtwyyHTWYYNtwt$$$HHHrH   rX   )frozenc                   t    e Zd Z ej        d          Z ej        d          Z ej        d          ZdS )revlogproblemNrY   )r[   r\   r]   r(   r^   warningr+   rS   rA   rH   rE   ri   ri      sL         dgd###GDGD!!!E474   DDDrH   ri   c                 F    t                               | |          \  }}||fS N)r=   parse_index2datainlineindexcaches       rE   parse_index_v1rs      s%    ''f55LE5%<rH   c                 T    t                               | |t                    \  }}||fS N)format)r=   rm   r   rn   s       rE   parse_index_v2rw      s*    ''fX'FFLE5%<rH   c                 T    t                               | |t                    \  }}||fS ru   )r=   rm   r   rn   s       rE   parse_index_cl_v2ry      s*    ''f['IILE5%<rH   parse_index_devel_nodemapc                 F    t                               | |          \  }}||fS rl   )r=   rz   rn   s       rE   parse_index_v1_nodemapr|      s%    88vFFue|rH   c                 `    t          | |          \  }}t                              |          |fS rl   )rs   
rustrevlog
MixedIndexrn   s       rE   parse_index_v1_mixedr      s.    !$//LE5  ''..rH   isN   cannot read from revlog %s;  expected %d bytes from offset %d, data size is %ds   0123456789abcdefABCDEFc                      e Zd ZdZej        Z	 	 	 	 	 	 	 	 	 dxdZd ZdydZ	dydZ
ej        d	             Zej        d
             Zd Zej        d             Zej        d             Zd Zd Zd ZdzdZej        d             Zd Zd Zd Zd Zd Zd{dZd Zd Z d Z!d Z"d Z#d  Z$d! Z%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-d* Z.e.Z/d+ Z0d, Z1d- Z2d. Z3d/ Z4dyd0Z5d|d1Z6d2 Z7d}d3Z8dyd4Z9d}d5Z:d}d6Z;d}d7Z<dyd8Z=d9 Z>d: Z?d}d;Z@d< ZAd= ZBd> ZCd? ZDd@ ZEd~dAZFdB ZGdC ZHdD ZIdE ZJddGZKdH ZLdydIZMdydJZNd}dKZOdL ZPdM ZQdN ZRdO ZSdydPZTdydQZUddRZVdydSZWdT ZXdydUZYdV ZZddWZ[dX Z\dY Z]ej        dZ             Z^ej        d[             Z_d\ Z`ddeaddfd]Zb	 	 	 dd^Zcd_ Zdd` Ze	 	 	 ddaZfdb Zgdc Zh	 	 	 dddZide Zjdf Zkdg Zldh Zmdi Zndj Zodddepjq        dfdkZrdlZsdmZtdnZudoZvh dpZwdetddfdqZxdr ZyddtZzdu Z{	 	 	 	 	 ddvZ|dw Z}dS )r>   ak  
    the underlying revision storage object

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

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

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

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

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

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

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

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

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

    See mercurial/revlogutils/contants.py for details about the content of an
    index entry.
    NFTc                    || _         || _        d| _        d| _        d| _        d| _        d| _        || _        || _        || _	        |	rt          j        |           | _        |d         t          v sJ t          |          dk    sJ || _        || _        || _        || _        d| _        t'          j        d          | _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        i | _        d	| _        i | _         d
| _!        d| _"        d| _#        d| _$        d| _%        d| _&        tO          tP          j)                  | _*        d| _+        d| _,        | -                                 |
| _.        || _/        dS )aJ  
        create a revlog object

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

        `target`: a (KIND, ID) tuple that identify the content stored in
        this revlog. It help the rest of the code to understand what the revlog
        is about without having to resort to heuristic and index filename
        analysis. Note: that this must be reliably be set by normal code, but
        that test, debug, or performance measurement code might not set this to
        accurate value.
        Nr      d   )r   rH   i   TFs   zlibg      ?i   )0upperboundcompradix_docket_file
_indexfile	_datafile_sidedatafile_nodemap_filepostfix_trypendingopenernodemaputilget_nodemap_filer   lentarget_checkambig_mmaplargeindex_censorable_revisioncacher1   lrucachedict_chainbasecache_chunkcache_chunkcachesize_maxchainlen_deltabothparents_debug_deltarq   _docket_nodemap_docket_pcache_compengine_compengineopts_maxdeltachainspan_withsparseread_sparserevloghassidedata_srdensitythreshold_srmingapsizedictr5   flagprocessors_flagprocessors_writinghandles_adding_group
_loadindex_concurrencycheckercanonical_parent_order)selfr   r   r   r   
checkambigmmaplargeindex
censorabler   persistentnodemapconcurrencychecker
trypendingr   s                rE   __init__zrevlog.__init__!  s   8 -
 !!% 	D!,!=d!C!CDayI%%%%6{{a &-%"#055#$ !%!
#"!"$$" #' #  $H$;<<  $!#5  '=###rH   c                    d}| j         j        }d|v r| j        t          k    rt          }nKd|v rt
          }n?d|v rt          t          z  }d|v r
|t          z  }nd| j         j        v rt          }nt          }d|v r|d         | _        d|v r|d         | _        d	|v r|d	         | _        t          |                    d
d                    | _        d| _        | j        r(t          |                    dd                    | _        d|v r|d         | _        d|v r|d         | _        d|v r|d         | j        d<   d|v r|d         | j        d<   d|v r|d         | _        | j        rd|v r|d         }t          |                    dd                    | _        t          |                    dd                    }| j        p|| _        d|v r|d         | _        d|v r|d         | _        |                    d          rt6          | j        t:          <   |                    di                                           D ] \  }}t?          j         ||| j                   !| j        dk    r)tC          j"        tG          d          | j        z            | j        | j        dz
  z  r)tC          j"        tG          d          | j        z            |                    dd          }|||fS )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
        Ns   changelogv2s   revlogv2s   revlogv1   generaldeltas   revlogv0s   chunkcachesizes   maxchainlens   deltabothparentss	   lazydeltaTFs   lazydeltabases   debug-deltas
   compengines
   zlib.levels
   zstd.levels   maxdeltachainspans   mmapindexthresholds   sparse-revlogs   with-sparse-reads   sparse-read-density-thresholds   sparse-read-min-gap-sizes   enableellipsiss   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-nodemap)$r   optionsrevlog_kindr   r   r   r   r   r   r   r   r   r   r   boolget
_lazydelta_lazydeltabaser   r   r   r   r   r   r   r   r   ellipsisprocessorr   r"   itemsr5   insertflagprocessorr+   RevlogErrorr
   )r   mmapindexthresholdopts
new_headerwithsparsereadflag	processorforce_nodemaps           rE   
_init_optszrevlog._init_opts  s]     "{"T!!d&6.&H&H$JJD  !JJD  !$44J$&&//
DK///!JJ/J$$#'(9#:D T!! $^ 4D$&&%)*=%>D"txxd;;<<#? 	J"&txx0@%'H'H"I"IDT!! $^ 4DD  #M2DD  26}2ED /D  26}2ED /4''&*+?&@D# 	=$9T$A$A!%&;!<!$((+;U"C"CDDdhh':EBBCC#1C^+t33'+,L'MD$&$..!%&A!BD88%&& 	F4ED 1  $xx(92>>DDFF 	P 	POD)(y$:NOOOO1$$#EFF&'   !T%9A%=> 	#CDD&'   !7??-}<<rH   c                 2   	 |                      |          5 }|| j                             |          j        }||k    ry|t          ||          }|2t	          j        t	          j        |                    cddd           S t	          j        t	          j        ||                    cddd           S | |                                cddd           S |                    |          cddd           S # 1 swxY w Y   dS # t          $ r Y dS w xY w)zbreturn a file content with or without mmap

        If the file is missing return the empty stringNrH   )	r   fstatst_sizeminr1   buffermmapreadreadFileNotFoundError)r   filepathmmap_thresholdsizefp	file_sizes         rE   	_get_datazrevlog._get_data  s   	X&& )"!- $ 1 1" 5 5 =I N22+#&y$#7#7D  <#';t}R/@/@#A#A) ) ) ) ) ) ) ) $(;t}R/F/F#G#G) ) ) ) ) ) ) ) <7799) ) ) ) ) ) ) )  774==!) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )" ! 	 	 	33	sY   D A!C;8D &C;+D 8C;D C;.D ;C??D C?D 
DDc                    |                                  \  }}}| j        d| j        | j        fz  }n>| j        r-| j                            d| j        z            rd| j        z  }n
d| j        z  }||| _        || _        nd}d| _        | 	                    ||          }t          |          dk    r*t          j        |d d                   d         }d| _        n|}|d	z  | _        |d
z  | _        t          j        | j                  }|4t#          d          }	|	| j        | j        fz  }	t'          j        |	          | j        | z  r?t#          d          }	| j        dz	  }
|	|
| j        | j        fz  }	t'          j        |	          t*          | j                 } |d         | j                  | _         |d         | j                  | _        |d         | _        |d         s
|| _        |}nJ|| _        | j        rt5          j        | |          | _        n!t5          j        | || j                  | _        | j        | j                                        | _        d}| j        j        }|dk    rm| 	                    | j        ||          }t          |          |k     r=t#          d          }	|	| j        t          |          |fz  }	t'          j        |	          d| _        d| _        d | _        | j        =| j                                         | _!        | j        "                                | _#        n-| j        d| j        z  | _!        nd| j        | j        fz  | _!        tH          | _%        | j%        j&        | _&        | j        sd| _'        d| _(        | j        o
|otR          d u}d}tT          )| j        d}n| j        j+                            d          }tX          | _-        | j        t\          k    rt^          j0        | _-        nW| j        tb          k    rtd          | _-        n:| j        tf          k    rth          | _-        n|rtR          | _-        n|rtj          | _-        	 | -                    || j                  }|\  }}| j         o| j        d uotm          j7        |d          }|rotq          j9        |           }|Y|d         }t          |d                   |j:        k    r3|d         |j:                 d         |j;        k    r|| _<         |j=        |  n># t|          t~          f$ r* t'          j        t#          d          | j        z            w xY w|| _@        t          jA        | j        | j        r| j        n| j!        | jB        |          | _C        t          jA        | j        | j#        | jB                  | _D        tm          jE        d          | _F        i | _G        d S )Ns   %s.i.%ss   %s.i.as   %s.irH   Tr      Fi    s!   unknown version (%d) in revlog %ss-   unknown flags (%#04x) in version %d revlog %s   s   inliner   s   sidedatas   docket)use_pending)r   s.   too few index data for %s: got %d, expected %ds   %s.ds   %s.d.%ss
   rust.indexupdate_nodemap_data   s   index %s is corrupted  )Hr   r   r   r   r   existsr   r   
_initemptyr   r   r   unpack_format_flags_format_versionr    r   r
   
display_idr+   r   r   _inline_generaldeltar   r   
docketutildefault_docketparse_docketindex_filepath	index_endr   data_filepathr   sidedata_filepathr   r   nodeconstantsnullidr   _storedeltachainsr|   r~   r   rs   _parse_indexr   r8   parse_index_v0r   rw   r   ry   r   r1   safehasattrr   persisted_datatip_revtip_noder   r   
ValueError
IndexErrorrq   r7   r   _segmentfile_segmentfile_sidedatar   _chaininfocache_decompressors)r   r4   r   r   r   entry_point
entry_dataheadersupported_flagsmsgdisplay_flagfeatures
index_data
index_sizedevel_nodemapuse_rust_indexdrq   
chunkcacheuse_nodemapnodemap_datas                        rE   r   zrevlog._loadindex  s!   8<8I8I5
&<#$
DL'AAKK 	/$+"4"4Y5K"L"L 	/#dj0KK!DJ.K!DL +DJ"DO5GHHJ:""%,Z^<<Q?"'#!''!1D#)F?D -1$2FGGO&<==,do>>',,,#&66 -HII#1R7d&:DOLL',,,*4+?@H.8I.t/ABBDL!:/!:4;M!N!ND'4DI& 
"-'

$/!? #-#<T6#J#JDLL#-#:jd6F$ $ $DL <#"l99;;DOJ/JA~~!^^O%7j ,  
 z??Z//MNNCDOS__jIIC+C000 DL!%D "&D<#!\7799DN!%!?!?!A!AD\!$tz1DNN'4:t|*DDDN.(/ ! 	'!&D!%  33&d2 	 !!-!%!%!4!8!8!G!G*8++ ( 7D!X-- .D![00 1D 	5 6D 	5 4D	!!*dl;;A !E:L  C&d2C$U,ABB 
  
A*9$??+)!_FAaD		FN22aD03vFF 06,11<@@J' 	 	 	#*++do=  	 
,=K $@T__$. 	
 
 &6%FK &
 &
"  $055 s   &B7T ;Uc                     | j         d         S Nr   )r   r   s    rE   r   zrevlog.revlog_kind  s    {1~rH   c                     | j         S )z;The public facing "ID" of the revlog that we use in message)r   r  s    rE   r   zrevlog.display_id  s    
 zrH   c                 V   	 | j         |         }n# t          $ r 	 t          j                            |          }|                    | j                  }|| j         |<   nD# t          $ r7 t          j        t          d          t          j        |          z            w xY wY nw xY w|S )Ns   unknown compression type %s)r  KeyErrorr1   compenginesforrevlogheaderrevlogcompressorr   r+   r   r
   binasciihexlify)r   t
compressorengines       rE   _get_decompressorzrevlog._get_decompressor  s    
	,Q/JJ 	 	 	)99!<<#44T5IJJ
)3#A&&   '4558H8K8KK   '&		 s(    
B&AAB&AB  B&%B&c                 d    t           j        | j                 }|                    | j                  S rl   )r1   r  r   r  r   )r   r  s     rE   _compressorzrevlog._compressor  s)    !$"23&&t';<<<rH   c                 d    | j         dS | j         j        }|                     |          }|j        S )zthe default decompressorN)r   default_compression_headerr  
decompress)r   r  cs      rE   _decompressorzrevlog._decompressor  s6     <4L3""1%%|rH   c                 :    |                      | j        d          S )z'file object for the revlog's index file   rmode)r   r   r  s    rE   _indexfpzrevlog._indexfp  s    {{4?{666rH   c                 T   	 |                      | j        d| j                  }| j        !|                    dt
          j                   n*|                    | j        j        t
          j                   |S # t          $ r% |                      | j        d| j                  cY S w xY w)N   r+)r*  r   r      w+)
r   r   r   r   seekosSEEK_ENDr   SEEK_SETr   )r   fs     rE   __index_write_fpzrevlog.__index_write_fp  s    	e8H   A |#q"+&&&&t|-r{;;;H  	 	 	;;e8H      	s   A5A8 8,B'&B'c                 H    |                      | j        d| j        d          S )N   wT)r*  r   
atomictemp)r   r   r   r  s    rE   __index_new_fpzrevlog.__index_new_fp  s.    {{O'	  
 
 	
rH   r(  c                 :    |                      | j        |          S )z&file object for the revlog's data filer)  )r   r   )r   r*  s     rE   _datafpzrevlog._datafp  s    {{4>{555rH   c              #      K   | j         r| j         d         V  dS |                     | j                  5 }|V  ddd           dS # 1 swxY w Y   dS )z%file object suitable to read sidedatar   N)r   r   r   )r   r   s     rE   _sidedatareadfpzrevlog._sidedatareadfp  s        	&q))))))T/00 B                 s   AAAc                 0    t          | j                  dz
  S Nr   r   rq   r  s    rE   tiprevzrevlog.tiprev  s    4:""rH   c                 P    |                      |                                           S rl   )rS   r@  r  s    rE   tipz
revlog.tip  s    yy'''rH   c                 <    d|cxk    ot          |           k     nc S r  )r   r   revs     rE   __contains__zrevlog.__contains__  s*    C#####d))#####rH   c                 *    t          | j                  S rl   r?  r  s    rE   __len__zrevlog.__len__  s    4:rH   c                 T    t          t          t          |                               S rl   )iterranger   r  s    rE   __iter__zrevlog.__iter__  s    E#d))$$%%%rH   r   c                 J    t          j        t          |           ||          S )z8iterate over all rev in this revlog (from start to stop)startstop)r;   iterrevsr   )r   rO  rP  s      rE   revszrevlog.revs  s     #CIIUFFFFrH   c                 T    	 |                      |           dS # t          $ r Y dS w xY w)NTF)rE  r  r   rS   s     rE   hasnodezrevlog.hasnode  s=    	HHTNNN4 	 	 	55	s    
''c                 ~    |                      |          t          z  s|                      |          t          z  rdS dS )z;whether two revisions (baserev, rev) can be delta-ed or notFT)rb   r'   )r   baserevrE  s      rE   candeltazrevlog.candelta  sB     JJw"?? 	JJsOO;;	 5trH   c                 r    | j         /|t          j        |            d S t          j        ||            d S d S rl   )r   r   update_persistent_nodemapsetup_persistent_nodemapr   transactions     rE   update_cacheszrevlog.update_caches  sI    )"5d;;;;;4[$GGGGG	 *)rH   c                    d | _         | j                                         | j                                         | j                                         i | _        d | _        | j        	                                 | j
         o"| j        d uot          j        | j        d          }|r4t          j        |           }| |d         | _         | j        j        |  d S d S d S )Nr   r   )r   r   clearr   clear_cacher   r   r   rq   clearcachesr   r   r1   r   r   r   r   )r   r  r  s      rE   rb  zrevlog.clearcaches  s    """$$$%%'''"..000#
     D"$.D -BCC 	
  	>&5d;;L''3A$.
.====		> 	>''rH   c                    	 | j                             |          S # t          $ r  t          j        $ rS || j        j        k    s|| j        j        v rt          j        t          j	        || j
        t          d                    w xY w)N   no node)rq   rE  	TypeErrorr+   r   r   wdiridwdirfilenodeidsWdirUnsupportedLookupErrorr   r
   rT  s     rE   rE  z
revlog.rev  s    	J:>>$''' 	 	 	  	J 	J 	J *1114-===++#D$/1Z==III	Js
    A,Bc                 H    t          | j        |         d         dz	            S )Nr   r   )intrq   rD  s     rE   rO  zrevlog.start/  s     4:c?1%+,,,rH   c                     | j         |         d         }|dk    r|S d|k    r5| j         |         }|d         dk    r|d         |d         z   S |dz  }d|k    5dS )N   r   	   r   rq   )r   rE  
sd_cut_offes       rE   sidedata_cut_offzrevlog.sidedata_cut_off2  sq    Z_Q'
?? 3hh
3Atqyytad{"1HC	 3hh
 qrH   c                 .    | j         |         d         dz  S )Nr   r   ro  rD  s     rE   rb   zrevlog.flagsC  s    z#q!F**rH   c                 (    | j         |         d         S r>  ro  rD  s     rE   lengthzrevlog.lengthF      z#q!!rH   c                 :    | j         sdS | j        |         d         S )Nr   rn  )r   rq   rD  s     rE   sidedata_lengthzrevlog.sidedata_lengthI  s#     	1z#q!!rH   c                     | j         |         d         }|dk    r|S |                     |          }t          |          S )z?return the length of the uncompressed text for a given revisionr   r   )rq   rawdatar   )r   rE  lr  s       rE   rawsizezrevlog.rawsizeN  s<    JsOA66HLL1vvrH   c                     |                      |          }|t          j        t          z  z  dk    r|                     |          S t          |                     |                    S )z=length of non-raw text (processed by a "read" flag processor)r   )rb   r5   REVIDX_KNOWN_FLAGSr"   r|  r   rP   )r   rE  rb   s      rE   r   zrevlog.sizeW  sW     

3H//ABaGG<<$$$4==%%&&&rH   c                     | j         |         t                   }| j        t          k    s|t          k    rdS |t
          k    rdS |S )a  Return the rank of a revision if already known, or None otherwise.

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

        This method returns the rank retrieved from the revlog in constant
        time. It makes no attempt at computing unknown values for versions of
        the revlog which do not persist the rank.
        Nr   )rq   r   r   r   r   r   )r   rE  ranks      rE   	fast_rankzrevlog.fast_ranka  sD     z#z*;..$,2F2F4'>>1rH   c                     | j                             |          }||S | j        }|}||         d         }||k    r|}||         d         }||k    || j         |<   |S )N   )r   r   rq   )r   rE  baserq   iterrevs        rE   	chainbasezrevlog.chainbases  sx    #'',,K
W~a gooG>!$D goo %)S!rH   c                 (    | j         |         d         S )Nr   ro  rD  s     rE   linkrevzrevlog.linkrev  rv  rH   c                     	 | j         |         }n&# t          $ r |t          k    rt          j         w xY w| j        r!|d         t          k    r|d         |d         fS |d         |d         fS )N      )rq   r   r	   r+   rh  r   r   )r   rE  entrys      rE   
parentrevszrevlog.parentrevs  s    	JsOEE 	 	 	g~~++	
 & 	&58w+>+>8U1X%%8U1X%%s    #3c                 v    	 | j         |         d         S # t          $ r |t          k    rt          j         w xY w)Nr   )rq   r   r	   r+   rh  rD  s     rE   rS   zrevlog.node  sH    	:c?1%% 	 	 	g~~++	s    #8c                 X    |                      |          |                     |          z   S rl   )rO  ru  rD  s     rE   endz
revlog.end  s#    zz#S!1!111rH   c                    | j         }||                     |                   }| j        r9|d         | j        k    r(||d                  d         ||d                  d         fS ||d                  d         ||d                  d         fS )Nr  r  r   )rq   rE  r   r   )r   rS   ir  s       rE   parentszrevlog.parents  s~    Jdhhtnn& 	*1Q44;+>+>QqT71:q1wqz))QqT71:q1wqz))rH   c                 8    |                      |          d         S r  )
_chaininforD  s     rE   chainlenzrevlog.chainlen  s    s##A&&rH   c                 R   | j         }||v r||         S | j        }| j        }|}||         }d}d}||d         k    rW|dz  }||d         z  }|r	|d         }n|dz  }||v r||         }	||	d         z  }||	d         z  }n||         }||d         k    W||d         z  }||f}
|
||<   |
S )Nr   r  r   )r   rq   r   )r   rE  chaininfocacherq   generaldeltar  rq  clencompresseddeltalenr  rs              rE   r  zrevlog._chaininfo  s    -.  !#&&
)'N1ooAID!A$& A$1.(("7+!"ad*"gA 1oo  !A$&%&srH   c                    	 | j                             ||| j                  S # t          $ r Y nw xY wg }| j         }| j        }|}||         }||d         k    rE||k    r?|                    |           |r	|d         }n|dz  }||         }||d         k    r||k    ?||k    rd}n|                    |           d}|                                 ||fS )aW  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)rq   
deltachainr   AttributeErrorappendreverse)	r   rE  stoprevchainrq   r  r  rq  stoppeds	            rE   _deltachainzrevlog._deltachain  s   	:((gt7IJJJ 	 	 	D	  
)'N1oo'W"4"4LL!!! A$1gA 1oo'W"4"4 gGGLL!!!Gg~s    # 
00c                     t          |          }| j        }|D ]} ||           t           | j        j        rt          j        }| j        }nt          j        }| j        } |||||          S )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.N)r  	inclusive)	listrS   rustancestorrq   rust_ext_compatLazyAncestorsr)   lazyancestors_uncheckedparentrevs)r   rR  r  r  checkrevr  r  args           rE   	ancestorszrevlog.ancestors  s     Dzz9 	 	AHQKKKK #
(B#(6M*CC$2M+C}S$9MMMMrH   c                 B    t          j        || j        | j                  S rl   )r*   descendantrevsrR  r  r   rR  s     rE   descendantszrevlog.descendants  s    #D$)T_EEErH   c                     | j         g}|                                 } fd|D             } fd|D             } G d d          } |                     |                                        t                                         |           t                      }t          j        fd|D                       }|ra|	                                }||v r|                    |            
                    |          D ]}|vr|                    |           |at          |          }|                                  fd|D             fS )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.Nc                 :    g | ]}                     |          S rA   rE  .0nr   s     rE   
<listcomp>z,revlog.findcommonmissing.<locals>.<listcomp>   #    ...!$((1++...rH   c                 :    g | ]}                     |          S rA   r  r  s     rE   r  z,revlog.findcommonmissing.<locals>.<listcomp>!  #    ,,,!,,,rH   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS ))revlog.findcommonmissing.<locals>.lazysetc                 :    t                      | _        || _        d S rl   )setaddedvalues
lazyvalues)r   r  s     rE   r   z2revlog.findcommonmissing.<locals>.lazyset.__init__%  s    #&55 ",rH   c                 &    || j         v p|| j        v S rl   r  r  r   values     rE   rF  z6revlog.findcommonmissing.<locals>.lazyset.__contains__)  s     00LET_4LLrH   c              3   N   K   | j         }|D ]}|V  | j        D ]
}||vr|V  d S rl   r  )r   addedr  s      rE   rL  z2revlog.findcommonmissing.<locals>.lazyset.__iter__,  sV      (  AGGGG    A::   rH   c                 :    | j                             |           d S rl   )r  rO   r  s     rE   rO   z-revlog.findcommonmissing.<locals>.lazyset.add4  s     $$U+++++rH   c                 :    | j                             |           d S rl   )r  update)r   valuess     rE   r  z0revlog.findcommonmissing.<locals>.lazyset.update7  s     ''/////rH   N)r[   r\   r]   r   rF  rL  rO   r  rA   rH   rE   lazysetr  $  sb        - - -M M M     , , ,0 0 0 0 0rH   r  c              3   $   K   | ]
}|v|V  d S rl   rA   )r  r  hass     rE   	<genexpr>z+revlog.findcommonmissing.<locals>.<genexpr>@  s'      !C!Casll!llll!C!CrH   c                 :    g | ]}                     |          S rA   rS   )r  missr   s     rE   r  z,revlog.findcommonmissing.<locals>.<listcomp>L  s#    999TYYt__999rH   )r   headsr  rO   r   r  r  collectionsdequepopleftr  r  r  sort)	r   commonr  r  missingvisitr  pr  s	   `       @rE   findcommonmissingzrevlog.findcommonmissing  s    >k]F=JJLLE....v...,,,,e,,,	0 	0 	0 	0 	0 	0 	0 	0, gdnnV,,--

6 %%!!C!C!C!CU!C!C!CCC 	(AG||A++ ( (A||Q  	( w--999999999rH   c                     |t           g}t          ,| j        j        r t                              | j        |          S t          j        | j        |          S )aO  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   r  rq   r  MissingAncestorsr)   incrementalmissingancestorsr  )r   r  s     rE   incrementalmissingrevszrevlog.incrementalmissingrevsN  sM     >YF#
(B#00VDDD3DOVLLLrH   c                     |t           g}||                                 }|                     |          }|                    |          S )ax  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.Nr  )r   headrevsr  missingancestorsr   r  r  incs       rE   findmissingrevszrevlog.findmissingrevs^  sL      >YF=MMOOE)))88##E***rH   c                      | j         g}|                                 } fd|D             } fd|D             }                     |          } fd|                    |          D             S )a.  Return the ancestors of heads that are not ancestors of common.

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

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

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

        'heads' and 'common' are both lists of node IDs.  If heads is
        not supplied, uses all of the revlog's heads.  If common is not
        supplied, uses nullid.Nc                 :    g | ]}                     |          S rA   r  r  s     rE   r  z&revlog.findmissing.<locals>.<listcomp>  r  rH   c                 :    g | ]}                     |          S rA   r  r  s     rE   r  z&revlog.findmissing.<locals>.<listcomp>  r  rH   r  c                 :    g | ]}                     |          S rA   r  r  r  r   s     rE   r  z&revlog.findmissing.<locals>.<listcomp>  s#    BBB		!BBBrH   )r   r  r  r  r  s   `   rE   findmissingzrevlog.findmissingv  s     >k]F=JJLLE....v...,,,,e,,,)))88BBBBc&:&:5&A&ABBBBrH   c                 f    g g g f}|/t          |          }|s|S t           fd|D                       }n j        g}t          }|t          k    r8|6 fd D              j        gt                                                     fS |t                     dz
  }di }nXt          |          }|s|S t                      t                              |d          }t          |          }t           fd|D                       }|r|
                                }| j        k    r"                     |          }||k    rg|vrJ                    |           |                     fd                     |          D                        n||v r|
                    |           |s|S |t          k    r.fd|D             }|rt           fd	|D                       }n|S t          } j        g}t          |          }	|	                                }g }
                     t          |d
          |dz             D ])}                     |          }d}|t          k    rd}n||	v rRd}||v rKt%                               |                    }|d
         |	v s
|d         |	v r|                    |           nMt%                               |                    }|d
         |	v s
|d         |	v r|	                    |           d}|r\|v rV|
                    |           
||v rd||<   3d||<                        |          D ]}|
                    |d           +d |                                D             }t          |          }|
sJ |sJ |sJ |
||fS )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.Nc                 :    g | ]}                     |          S rA   r  r  s     rE   r  z'revlog.nodesbetween.<locals>.<listcomp>  s#    888QTXXa[[888rH   c                 :    g | ]}                     |          S rA   r  r  s     rE   r  z'revlog.nodesbetween.<locals>.<listcomp>  s#    ,,,!1,,,rH   r   Fc                 :    g | ]}                     |          S rA   r  r  s     rE   r  z'revlog.nodesbetween.<locals>.<listcomp>  s#    >>>adhhqkk>>>rH   c                 *    g | ]}|j         k    |S rA   )r   )r  r  r   s     rE   r  z'revlog.nodesbetween.<locals>.<listcomp>  s%    LLL11;K;KQ;K;K;KrH   c                     g | ]}|v |	S rA   rA   )r  rootr  s     rE   r  z'revlog.nodesbetween.<locals>.<listcomp>  s#    EEE$493D3D3D3D3DrH   c                 :    g | ]}                     |          S rA   r  )r  r  r   s     rE   r  z'revlog.nodesbetween.<locals>.<listcomp>  s#    $F$F$FTXXd^^$F$F$FrH   r   rN  Tc                     g | ]	\  }}||
S rA   rA   )r  headr   s      rE   r  z'revlog.nodesbetween.<locals>.<listcomp>)  s!    >>>*$>>>>rH   )r  r   r   r   r  r   r  r   fromkeysmaxpoprE  rO   r  r  copyrR  rS   tupleremover  r   )r   rootsr  nonodes	lowestrev
highestrev
nodestotagr  r  r  
orderedoutisdescendantr  r  s   `            @rE   nodesbetweenzrevlog.nodesbetween  sn   * r2,KKE 8888%88899II[MEI  u} -,,,t,,,TZZ\\"" 
 = TQJIEEKKE I MM%//EUJ>>>>:>>>??J %NN$$## HHQKK	>>	)) "a((("))LLLLQLLL    e 		!+  %,  
 7""
 FEEE%EEE # #$F$F$F$F$F$F$F G GII #N $	%jj   ""
 Y!2!2aHH '	+ '	+A		!A LG###k!!# ::dll1oo..A!++11D1DQ$,,q//** aDK''QqT[-@-@OOA&&&#'L +)"3i!!!$$$)U

  $E!HH&  $E!H!\\!__ + +		!T****>>>>>UE5))rH   c                    |>	 | j                                         S # t          $ r |                                 cY S w xY wt          ,| j         j        r t                              | j         |          S t          j        || j                  S rl   )rq   r  r  	_headrevs	rustdagopr  r*   r  r  s     rE   r  zrevlog.headrevs0  s    <(z**,,,! ( ( (~~'''''( TZ%? %%dj$777~dD$=>>>s    >>c                 6    | j                             |          S rl   )rq   computephasesmapsets)r   r  s     rE   computephaseszrevlog.computephases:  s    z..u555rH   c                     t          |           }|st          gS dg|dz   z  }| j        }| D ]%}d||<   ||         }dx||d         <   ||d         <   &d t          |          D             S )Nr   r   r  r  c                     g | ]	\  }}||
S rA   rA   )r  r  vals      rE   r  z$revlog._headrevs.<locals>.<listcomp>H  s!    999faS9999rH   )r   r   rq   	enumerate)r   countisheadrq   r  rq  s         rE   r
  zrevlog._headrevs=  s    D		 	9	"
 	, 	,AF1IaA*++F1Q4L6!A$<<99	& 1 19999rH   c                 8    |9|7t                     s j        gS  fd                                 D             S |t          }n                     |          } fd|pg D             }t          j         j         j        ||          } fd|D             S )a  return 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
        Nc                 :    g | ]}                     |          S rA   r  r  s     rE   r  z revlog.heads.<locals>.<listcomp>U  s#    :::QDIIaLL:::rH   c                 :    h | ]}                     |          S rA   r  r  s     rE   	<setcomp>zrevlog.heads.<locals>.<setcomp>\  s#    444ADHHQKK444rH   )startrevstoprevsc                 :    g | ]}                     |          S rA   r  )r  rE  r   s     rE   r  z revlog.heads.<locals>.<listcomp>b  s#    ///3		#///rH   )	r   r   r  r   rE  r*   headrevssubsetrR  r  )r   rO  rP  r  rR  s   `    rE   r  zrevlog.headsJ  s     =T\t99 %}$::::$--//::::=EEHHUOOE4444444#It
 
 
 0///$////rH   c                 |   g }|                      |          }|                     |dz             D ]}d |                     |          D             }|r4|D ]0}||k    r(|                    |                     |                     1W|t
          k    r(|                    |                     |                     |S )z!find the children of a given noder   )rO  c                 (    g | ]}|t           k    |S rA   )r   )r  prs     rE   r  z#revlog.children.<locals>.<listcomp>i  s    FFFBgRrH   )rE  rR  r  r  rS   r   )r   rS   r%  r  r  prevsr  s          rE   childrenzrevlog.childrend  s    HHTNNQ'' 	' 	'AFF$//!"4"4FFFE ' / /BQww1.../ g1&&&rH   c                     |                      |          |                      |          }}|                     ||          }t          j        | j        |          S )z@calculate all the heads of the common ancestors of nodes a and b)rE  _commonancestorsheadsr.   maplistrS   r   abancss       rE   commonancestorsheadszrevlog.commonancestorsheadsr  sI    xx{{DHHQKK1))!Q//	4000rH   c                     	  | j         j        | }n.# t          t          f$ r t	          j        | j        g|R  }Y nw xY w|S )z7calculate all the heads of the common ancestors of revs)rq   r)  r  OverflowErrorr)   r  )r   rR  r(  s      rE   r#  zrevlog._commonancestorsheadsx  sb    	I24:2D9DD. 	I 	I 	I0H4HHHDDD	Is    (==c                     |                      |          |                      |          }}|                     ||          S )zgreturn True if node a is an ancestor of node b

        A revision is considered an ancestor of itself.)rE  isancestorrevr   r&  r'  s      rE   
isancestorzrevlog.isancestor  s7     xx{{DHHQKK1!!!Q'''rH   c                     |t           k    rdS ||k    rdS ||k    rdS t          |                     ||g|gd                    S )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   r   reachablerootsr.  s      rE   r-  zrevlog.isancestorrev  sW     <<4!VV4UU5D''A3'GGHHHrH   c                     	 | j                             ||||          S # t          $ r  t          j        | j        ||||          cY S w xY w)zlreturn (heads(::(<roots> and <roots>::<heads>)))

        If includepath is True, return (<roots>::<heads>).)rq   reachableroots2r  r*   _reachablerootspurer  )r   minrootr  r  r1  s        rE   r2  zrevlog.reachableroots  ss    	:--{    	 	 	,%    	s    'A	A	c                 J   |                      |          |                      |          }}	 | j                            ||          }n2# t          t          f$ r t          j        | j        ||          }Y nw xY w|r"t          t          | j	        |                    S | j
        S )z5calculate the "best" common ancestor of nodes a and b)rE  rq   r  r  r+  r)   r  r   maprS   r   r%  s       rE   r)   zrevlog.ancestor  s     xx{{DHHQKK1	=:''1--DD. 	= 	= 	=%doq!<<DDD	= 	-s49d++,,,{s   A ,A76A7c                    t          |t                    r|                     |          S t          |          | j        j        k    r/	 |}|                     |           |S # t          j        $ r Y nw xY w	 t          |          }d|z  |k    rt          |dk     rt          |           |z   }|dk     s|t          |           k    rt          |                     |          S # t          t          f$ r Y nw xY wt          |          d| j        j        z  k    rI	 t          |          }|                     |           |S # t          j        t          j        f$ r Y d S w xY wd S )Ns   %dr   r   )
isinstancerk  rS   r   r   nodelenrE  r+   ri  r   r+  r   r  Error)r   idrS   rE  s       rE   _matchzrevlog._match  s   b# 	!99R== r77d(000$   	b''Cs{b    Qww$ii#oQww#T**  99S>>!M* 	 	 	D	r77a$,44442wwNE$56    54s7   	A" "A43A48A+C$ $C87C8%E E! E!c                 x     j         j                                      }d}	  j                                      }|r                     |          r|rd}n|S |rt          j        d S n:# t          j        $ r t           dd           sd}Y nt          t          f$ r Y nw xY w|r(t          j         j        t          d                     j        v r j                 S t!                    dk    r=t!                    dz  dz  }	 t!                    dz  dk    rd         t"          vrd S t%          d |                   fd	 j        D             } fd
|D             } j         j                                      r|                     j                   t!          |          dk    rUt!          |          dk    r|s|d          j        <   |d         S t          j         j        t          d                    |rt          j        d S # t,          j        $ r Y d S w xY wd S )NFTfilteredrevss   ambiguous identifier(   r   r   r   c                 V    g | ]%}|d                                         |d          &S )r   )
startswith)r  rq  prefixs     rE   r  z(revlog._partialmatch.<locals>.<listcomp>  s2    JJJq!A$//&2I2IJadJJJrH   c                     g | ];}t          |                                        $                    |          9|<S rA   )r   rC  rU  )r  r  r=  r   s     rE   r  z(revlog._partialmatch.<locals>.<listcomp>  sT       SVV%6%6r%:%:?C||A  rH   r   )r   wdirhexrC  rq   partialmatchrU  r+   rh  r   r   r  r   AmbiguousPrefixLookupErrorr   r
   r   r   	hexdigitsr   nullhexr  r   r  r<  )r   r=  	maybewdir	ambiguouspartialr{  nlrD  s   ``     @rE   _partialmatchzrevlog._partialmatch  s   &.99"==			j--b11G 
4<<00 
 # $II"N ++t    	! 	! 	! 466 ! 	
+ 	 	 	D	  	2DOQ'>%?%?   <##r77b==B1q A r77Q;??rFi//#tRV KJJJDJJJJ    !   %-88<< +IIdk***r77Q;;2ww!||I|+-a5R(!!u:DOQ/F-G-G    0//t% >    =s5   7A/ A/ /"B&B&%B&%H$ :H$ $H76H7c                     |                      |          }||S |                     |          }|r|S t          j        || j        t          d                    )z{locate a node based on:
        - revision number or str(revision number)
        - nodeid or subset of hex nodeid
        Ns   no match found)r>  rO  r+   ri  r   r
   )r   r=  r  s      rE   lookupzrevlog.lookup  s]    
 KKOO=Hr"" 	HDOQ7H5I5IJJJrH   r   c                      fd}d t                    }fd}t           dd          s	 t           j                                      |          } |||          S # t
          j        $ r;  j        j        k    r(t          j	         j
        t          d                    Y nt          $ r Y nw xY w j        j        k    r<t          |t          |          dz             D ]}|d|         } ||          r|c S t          |t          |          dz             D ]%}|d|         } ||          r |||          c S &dS )z7Find the shortest unambiguous prefix that matches node.c                     	                      |           }n'# t          j        $ r Y dS t          j        $ r Y dS w xY w|(t          j        j        t          d                    dS )NFTrd  )rO  r+   rH  rh  ri  r   r
   )rD  matchednoderS   r   s     rE   isvalidz revlog.shortest.<locals>.isvalid#  s    "00883   uu(   tt "'doq}}MMM4s    ===c                 X    t          d t          j        |           D                       S )Nc              3   "   K   | ]
}|d k    V  dS )   fNrA   )r  r%  s     rE   r  z5revlog.shortest.<locals>.maybewdir.<locals>.<genexpr>0  s&      GGQqDyGGGGGGrH   )allr.   iterbytestr)rD  s    rE   rK  z"revlog.shortest.<locals>.maybewdir/  s*    GG(*>v*F*FGGGGGGrH   c                     t          |t          |           dz             D ]}| d|         } |          s|c S dS )zDisambiguate against wdirid.r   N)rK  r   )hexnode	minlengthru  rD  rK  s       rE   disambiguatez%revlog.shortest.<locals>.disambiguate4  s_    	3w<<!+;<< " " &) y(( "!MMM"" "rH   r@  Nrd  r   )r   r   r  rq   shortestr+   r   r   rf  ri  r   r
   r  rK  r   )	r   rS   r]  rU  r\  r^  ru  rD  rK  s	   ``      @rE   r_  zrevlog.shortest   s   
	 
	 
	 
	 
	 
		H 	H 	H d))	" 	" 	" 	" 	" t^T22 	
TZ0066	BB#|GV444$   4-444+doq}}   54 "    4%,,,	3w<<!+;<< " " &)76?? "!MMM" Is7||a'788 	5 	5FWfW%Fwv 5#|GV444445	5 	5s   3A' 'AB<0	B<;B<c                 f    |                      |          \  }}t          j        |||          |k    S )zpcompare text with a given file revision

        returns True if text is different than what is stored.
        )r  r;   hashrevisionsha1)r   rS   rD   p1p2s        rE   cmpz
revlog.cmpS  s3    
 d##B+D"b99TAArH   c                 n   | j         }||         }t          |d         dz	            }||k    r||d         z   }n)||         }t          |d         dz	            |d         z   }| j        r*||dz   | j         j        z  z  }||dz   | j         j        z  z  }||z
  }	|| j                            ||	|          fS )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.
        r   r   r   )rq   rk  r   
entry_sizer   
read_chunk)
r   r  endrevdfrq   istartrO  r  iendru  s
             rE   _getsegmentforrevszrevlog._getsegmentforrevs[  s    $ 
xF1IO$$v&)#CC=Dd1gm$$tAw.C< 	8hldj&;;;EFQJ$*"777Cud'225&"EEEErH   c                 4   | j         |         d         }|                     |||          d         }|t          k    r|S |t          k    r|                     |          S |t
          k    r|                     |          S d}||z  }t          j        |          )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.
        
   ri  r      unknown compression mode %d)	rq   rl  r   r   r&  r   r$  r+   r   )r   rE  ri  compression_modero   r  s         rE   _chunkzrevlog._chunk}  s      :c?2.&&sCB&77:..K!222%%d+++!111??4(((0C##C#C(((rH   c                 .    |sg S  j         } j        } j        } j        j        }t
          j        }g }	|	j        }
 j        s|f}nt          j
         ||          }|D ]2}|d         }|ddd         D ]} ||          dk    r n	                      ||          \  }}n!# t          $ r  fd|D             cY c S w xY w j        } j        }|D ]} ||          }|r||dz   |z  z  } ||          } j        |         d         } ||||z
  |          }|t          k    r |
|           _|t           k    r |
 ||                     |t"          k    r |
 ||                     d	}||z  }t%          j        |          4|	S )
a  Obtain decompressed chunks for the specified revisions.

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

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

        Returns a list with decompressed data for each requested revision.
        )
targetsizer   Nr   ro  c                 >    g | ]}                     |           S )ro  )rr  )r  rE  ri  r   s     rE   r  z"revlog._chunks.<locals>.<listcomp>  s)    EEECCB//EEErH   r   rn  rp  )rO  ru  r   rq   rf  r1   r   r  r   	deltautil
slicechunkrl  r+  r$  r&  r   r   r   r+   r   )r   rR  ri  rt  rO  ru  rp   iosizer   r{  laddslicedchunks	revschunkfirstrevlastrevoffsetro   decomp
def_decomprE  
chunkstartchunklength	comp_moder%  r  s   ` `                      rE   _chunkszrevlog._chunks  sE     	I
&x# 	 7LL$/dz  L & !	1 !	1I |H$TTrT?  6'??a''E (F#66xR6PP  F F F FEEEE9EEEEEEEEF
 _F+J  1 1"U3ZZ
 537f"44J$fSkk JsOB/	F4f!4kBB//DGGGG"222DOOOO"333DA''''8C9$C+C000!1$ s   B((CCc                 ^    | j         |         d         }||k    rt          S | j        r|S |dz
  S )z(return deltaparent of the given revisionr  r   )rq   r   r   )r   rE  r  s      rE   deltaparentzrevlog.deltaparent  s9    z#q!3;;N 	K7NrH   c                    | j         s|                     |          t          k    S t          j        | j        d          r&| j        j        | _        |                     |          S |t          k    rdS | j        |         }|d         }||k    rdS |t          k    rdS |d         }|                     |          dk    r7|                     |          }||k    rn|}|                     |          dk    7|d         }|                     |          dk    r7|                     |          }||k    rn|}|                     |          dk    7||k    s||k    rdS |                     |          S )ztells whether rev is a snapshots
   issnapshotTr  r  r   r  F)r   r  r   r1   r   rq   
issnapshotru  )r   rE  r  r  rb  r'  rc  s          rE   r  zrevlog.issnapshot  sw   ! 	(##C((G33dj-88 	("j3DO??3''''>>4
3Qx3;;47??41Xkk"oo""  $$ABwwB	 kk"oo""
 1Xkk"oo""  $$ABwwB	 kk"oo""
 2::5t$$$rH   c                     |                      |          st          j        d          t          |                     |          d                   dz
  S )z/number of snapshot in the chain before this ones   revision %d not a snapshotr   r   )r  r+   ProgrammingErrorr   r  rD  s     rE   snapshotdepthzrevlog.snapshotdepth  sO    s## 	H()FGGG4##C((+,,q00rH   c                    |t           k    r;|                     |          |k    r"t          |                     |                    S t	          j        |                     |          |                     |                    S )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  bytesrr  r,   textdiffrz  )r   rev1rev2s      rE   revdiffzrevlog.revdiff  si     7??t//55==T**+++~dll400$,,t2D2DEEErH   c                 .    |                      ||          S )zreturn an uncompressed revision of a given node or revision
        number.

        _df - an existing file handle to read from. (internal-only)
        _revisiondatar   	nodeorrev_dfs      rE   rP   zrevlog.revision  s     !!)S111rH   c                     t          |t                    r|}n|                     |          }|                     |          S )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:  rk  rE  	_sidedata)r   r  r  rE  s       rE   r:   zrevlog.sidedata  s@     i%% 	&CC((9%%C~~c"""rH   c                    t          |t                    r|}|                     |          }n|}d }|| j        k    rdS |                     |||          \  }}}|r|r|S ||                     |          }|                     |          }|r|t          k    r|S |rt          j	        | ||          }	|}
nt          j
        | ||          }|\  }
}	|	r|                     |
||           |s
|||f| _        |
S )NrH   )r  r  )r:  rk  rS   r   _rawtextrE  rb   r!   r5   processflagsrawprocessflagsread	checkhashr   )r   r  r  rawrE  rS   rawtext	validatedrb   validatehashrD   r  s               rE   r  zrevlog._revisiondata(  s8   i%% 	C99S>>DDDC 4;3 #'--cs-"C"CWi 	9 	 N;((4..C 

3 	"666N 	##3D'5IILDD)$??A!"D, 	0NN43N/// 	7#'g"6DrH   c                    d}d}| j         r.| j         d         |k    r|| j         d         dfS | j         d         }||                     |          }|                     ||          \  }}|r| j         d         }d| _         d}| j        |         d         }	d|	k    rd|	z  }|                     |||          }
|t          |
d                   }|
dd         }
t          j        ||
          }~||d	fS )
zjreturn the possibly unvalidated rawtext for a revision

        returns (rev, rawtext, validated)
        Nr   r   Tr   )r  r   )ri  rt  F)r   rE  r  rq   r  r  r,   patches)r   rS   rE  r  	cachedrevbasetextr  r  rt  r|  binsr  s               rE   r  zrevlog._rawtextT  s     	  	/"1%--T03T::+A.I;((4..C))#y)AAw 	.*1-H #
*S/!$<<WJ||Ecj|AAT!W~~H8D-$//We$$rH   c                 z   | j         |         }|d         }|d         }| j        r|| j         j        d|z   z  z  }|dk    ri S | j        j        ||z   k     r9| j        }| j        j        }|}|}t          ||||fz  }	t          j        |	          | j	        
                    ||          }
| j         |         d         }|t          k    r|
}n]|t          k    r|                     |
          }n<|t          k    r|                     |
          }nd}||z  }t          j        |          t!          j        |          }|S )z0Return the sidedata for a given revision number.rm  rn  r   r      rp  )rq   r   rf  r   sidedata_endr   FILE_TOO_SHORT_MSGr+   r   r   rg  r   r   r&  r   r$  sidedatautildeserialize_sidedata)r   rE  index_entrysidedata_offsetsidedata_sizefilenamer  r~  ru  mcomp_segmentcompsegmentr  r:   s                  rE   r  zrevlog._sidedata  s\   jo%a.#A< 	Atz4C@@OAI<$'FFF)H,+C$F"F"h%DDA#A&&&1<<]
 
 z#r"?"""GG&&&((66GG%%%ool33GG0C4KC#C(((4W==rH   c                 2    |                      ||d          S )zreturn an uncompressed raw data of a given node or revision number.

        _df - an existing file handle to read from. (internal-only)
        T)r  r  r  s      rE   rz  zrevlog.rawdata  s    
 !!)Sd!;;;rH   c                 .    t          j        |||          S )zyCompute a node hash.

        Available as a function so that subclasses can replace the hash
        as needed.
        )r;   ra  )r   rD   rb  rc  s       rE   hashzrevlog.hash  s     +D"b999rH   c                    	 |||                      |          \  }}||                     |||          k    r| j        r| j        d         |k    rd| _        |}|!t          j        t          |                    }t          j        t          d          | j	        t          j        |          fz            dS # t          j        $ r8 | j        r/t          j        |          rt          j        | j	        ||           w xY w)zCheck 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   r0   r   r   r+   r   r
   r   r.   bytestrr   r;   iscensoredtextCensoredNodeError)r   rD   rS   rb  rc  rE  	revornodes          rE   r  zrevlog.checkhash  s%   	zbjd++Btyyr2.... & /4+>q+AT+I+I*.D'	$ / 5c$ii @ @I'899(8(C(CDE   /."   	 	 	 KK$>t$D$D K-dotTJJJ	s   B8B< <ADc           	      ^   t          |           dz
  }|                     |          |                     |          z   }| j        r|t          k     rdS |                    | j                  }|)t          j        t          d          | j        z            d}|
                    | j        d           d}| j        Jd}| j        d         }|                                 |                                 d| _        d| j        _        |                     d          }|                    d           	 |                                 5 }	| D ]`}
|                    |                     |
|
|	          d                    |+||                     |
          |
| j        j        z  z   k    r|
}a|                                 ddd           n# 1 swxY w Y   |d}|                                 5 }| xj        t4           z  c_        d| _        | D ]l}| j                            |          }|dk    r5| j        .| j        | j        z  }| j                            |          }||z   }|                    |           m| j        |                                | j        _         |!                    | j        |                     |                     ddd           n# 1 swxY w Y   |!                    | j        || j        j        z             tE          j#        ||            tI          j$        | j%        | j        | j&                  | _        |r,| '                                }||df| _        || j        _        d}||                                 dS dS # ||                                 w w xY w)	a  Check 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   %s not found in the transactionr   FTr.  ro  )(r   rO  ru  r   
_maxinline
findoffsetr   r+   r   r
   rO   r   r   flushcloser   writing_handler:  truncater+  writerl  rq   rf  _revlog__index_new_fpr   r   entry_binaryr   r   pack_headertellr   replacer   r[  r7   r   r   _revlog__index_write_fp)r   trr@  
total_sizetroffsettrindexexisting_handlesr   new_dfhread_ifhr  r  rq  r  ifhs                  rE   _enforceinlinesizezrevlog._enforceinlinesize  s+    TQZZ''$++f*=*==
| 	zJ66F==11#455G   
t~q!!! +#%a(BHHJJJHHJJJ $(D /3D,
 ,,u%%8	  	 H $ $AMM$"9"9!Q8"9"L"LQ"OPPP$::a==1tz/D+DDE E #$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  $$&& @"""'7&77""$    A
//22AAvv$,"6!%!3d6J!J!%!7!7!?!?"QJHHQKKKK<+-/WWYYDL* 

4>4::g+>+>???#@ @ @ @ @ @ @ @ @ @ @ @ @ @ @, JJt$*2G(GHHH0T::: 0 A$! !D   ++--(+Wd';$3:!0
 " #"w" #sW   2N A8G
>N 
GN GN -C KN KN  K!BN N,c                     dS )z0called when trying to add a node already stored.NrA   )r   r]  rS   s      rE   _nodeduplicatecallbackzrevlog._nodeduplicatecallback1  s      rH   c              #      K   | j                                         5  | j                                        5  dV  ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zCContext manager that keeps data and sidedata files open for readingN)r   readingr   r  s    rE   r  zrevlog.reading4  s       &&(( 	 	+3355                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s3   AAAA	AA	AA#&A#c              #   t  K   | j         r d}|| j        z  }t          j        |          | j        d V  d S d x}x}}	 t          |           }d}|r|                     |dz
            }d }| j        s	 |                     d          }| j	        !|
                    dt          j                   n*|
                    | j	        j        t          j                   n%# t          $ r |                     d          }Y nw xY w|                    | j        |           | j        |J 	 |                     | j        d          }|
                    | j	        j        t          j                   n,# t          $ r |                     | j        d          }Y nw xY w|                    | j        | j	        j                   || j        j        z  }|                                 }| j        r|                    | j        ||z              n|                    | j        |           |||f| _        | j        r|n|| j        _        || j        _        d V  | j	        |                     |           d | _        d | j        _        d | j        _        ||                                 ||                                 ||                                 d S d S # d | _        d | j        _        d | j        _        ||                                 ||                                 ||                                 w w xY w)Ns)   try to write in a `trypending` revlog: %sr   r   r-  r.  r)  )r   r   r+   r  r   r   r  r   r:  r   r/  r0  r1  data_endr2  r   rO   r   r   r   r  rq   rf  r  r   r   r  r   _write_docketr  )	r   r]  r  r  dfhsdfhr  dsizeisizes	            rE   _writingzrevlog._writing;  sV      	.>C4?"C(---+EEEEE##C##6 II , HHQUOOE| 	;2"ll511</HHQ4444HHT\%:BKHHH, 2 2 2"ll5112OODNE:::%1???K#{{4+=E{JJ!:BKHHHH, K K K#{{4+=E{JJKOO*DL,E  
 DJ11++--< <OODOUU]CCCCOODOU;;;(+S$'7$:>,3O33C!0<@*9<+&&{333'+$37!0<@*9?IIKKK#JJLLL ?IIKKKKK #? (,$37!0<@*9?IIKKK#JJLLL ?IIKKKK #sW   4K 3A'C K C=:K <C==)K 'AE. -K .&FK FCK A$L7c                 :    | j                             |           dS )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)r   r  r\  s     rE   r  zrevlog._write_docket}  s      	;'''''rH   c                    |t           k    r)t          j        t          d          | j        z            |
i }
n*|
r(| j        s!t          j        t          d                    |r|p|                     |||          }t          j	        | ||          \  }}||k    rd}t          |          t          k    r8t          j        t          d          | j        t          |          fz            |p|                     |||          }| j                            |          }||S |r|                     ||||           |                     |||||||||	|

  
        S )a  add a revision to the log

        text - the revision data to add
        transaction - the transaction object used for rollback
        link - the linkrev data to add
        p1, p2 - the parent nodeids of the revision
        cachedelta - an optional precomputed delta
        node - nodeid of revision; typically node is not specified, and it is
            computed by default as hash(text, p1, p2), however subclasses might
            use different hashing method (and override checkhash() in such case)
        flags - the known flags to set on the revision
        deltacomputer - an optional deltacomputer instance shared between
            multiple calls
        s!   attempted to add linkrev -1 to %sNs9   trying to add sidedata to a revlog who don't support thems;   %s: size of %d bytes exceeds maximum revlog storage of 2GiB)rb  rc  )
cachedeltadeltacomputerr:   )r   r+   r   r
   r   r   r  r  r5   processflagswriter   _maxentrysizerq   get_revr  addrawrevision)r   rD   r]  linkrb  rc  r  rS   rb   r  r:   r  r  rE  s                 rE   addrevisionzrevlog.addrevision  s   6 7??#677$/I   HH 	d. 	(NOO    	32499T2r22D ( :4u M M d??Jw<<-''#R  ?CLL12   1tyy"b11j  &&?J 	8NN7DRBN777""!' # 
 
 	
rH   c                     |                      |          5  |                     |||||||||	|

  
        cddd           S # 1 swxY w Y   dS )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).
        r  r:   N)r  _addrevision)r   r  r]  r  rb  rc  rS   rb   r  r  r:   s              rE   r  zrevlog.addrawrevision  s    " ]];'' 	 	$$+! %  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA	Ac                 z    |sd|fS | j                             |          }|rd|fS |dd         dk    rd|fS d|fS )z6Generate a possibly-compressed representation of data.rH   r   r          u)r!  compress)r   ro   
compresseds      rE   r  zrevlog.compress  sc     	9%..t44
 	#
?"!99TzrH   c                 ~   |s|S |dd         }|dk    r]	 t          |          S # t          j        $ r;}t          j        t	          d          t          j        |          z            d}~ww xY w|dk    r|S |dk    rt          j        |d          S | 	                    |          }|
                    |          S )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: %sNr  r  )_zlibdecompresszlibr+   r   r
   r<   forcebytestrr1   r   r  r$  )r   ro   r  rq  r  s        rE   r$  zrevlog.decompress	  s      	K. 1I99&t,,,:   '455 -a001   %ZZK$YY;tQ'''++A..
$$T***s   % A/6A**A/c                 
   || j         k    r)t          j        t          d          | j        z            || j        j        k    s|| j        j        v r)t          j        t          d          | j        z            | j        d}t          j	        |          | j
        r| j        d         }n| j        d         }|g}t          |           }|dz
  }|                     |          }| j        r| j        \  }}}| j
        r-|                     || j        ||| j        j        z  z              nE|                     || j        || j        j        z             |                     || j        |           |                     |          |                     |          }}|;t'          j        t*                              | |d                   |d                   }nt          |          }|
&d}| j        r|j        }t3          j        | |          }
t7          j        |||||||          }|
                    ||          }t<          }| j        &| j        j         }t3          j!        ||          }|\  }}t<          }|r| j"        rtF          }tI          j%        |          }| j        j&        } | '                    |          \  }!}"|!dk    r]|"dd         d	k    rOt          |"          t          |          k     r/|!rJ |"dd         | j        j         k    r
tP          }|"}nt<          }|"}nd
}d} tR          }#| j*        tV          k    r||ftX          tX          fk    rd}#n|tX          k    r$|tX          k    rd| -                    |          z   }#n|tX          k    r$|tX          k    rd| -                    |          z   }#nt\          .| j        j/        r"t\          0                    | j        ||          }#n^tc          ||f          \  }$}%d| -                    |%          z   }#|#te          d | 3                    |%g|$g          D                       z  }#t7          j4        |||j5        |||j6        ||||| t          |          ||#          }&| j        7                    |&           | j        8                    |          }'|dk    r5| j        .| j9        | j*        z  }(| j        :                    |(          }(|(|'z   }'| ;                    ||'|j<        ||||            |d         }|	r||
=                    ||          }t}          |          t~          k    r
|||f| _@        |jA        | jB        |<   |S )a  internal function to add revisions to the log

        see addrevision for argument descriptions.

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

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

        invariants:
        - rawtext is optional (can be None); if not set, cachedelta must be set.
          if both are set, they must correspond to each other.
        s    %s: attempt to add null revisions    %s: attempt to add wdir revisionN1   adding revision outside `revlog._writing` contextr   r   write_debugr  r  rH   c              3      K   | ]}d V  dS )r   NrA   )r  r
   s     rE   r  z&revlog._addrevision.<locals>.<genexpr>	  s"      PPaPPPPPPrH   )rb   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  )Cr   r+   r   r
   r   r   rf  rg  r   r  r   r   _get_data_offsetr   r   rq   rf  r   rE  r,   patchedsizer>   r   r   _reportrv  r  r/   revisioninfofinddeltainfor   r   r#  delta_compressionr   r   r  serialize_sidedatar  r  r   r   r   r   r   r  r  r  r  sortedsumr  r  deltalenr  r  r  r   r  _writeentryro   	buildtexttyper  r   r  r   ))r   rS   r  r]  r  rb  rc  rb   r  alwayscacher  r:   r  fhbtextcurrprevr~  r  r  r  p1rp2rtextlenr  revinfo	deltainforq  default_compr  r  serialized_sidedatar  hcomp_sidedatar  pminpmaxrq  r  r  s)                                            rE   r  zrevlog._addrevision4	  s   6 4;#566H   D&---t)999#566H   'FC(---< 	)%a(BB%a(B	4yyax&&t,,# 	F!1NCd| F ((&4$*:O3O*O   
 (($1F*F   ((dnfEEE88B<<"S ? 'D*Q-00*Q- GG 'llG K  2)1%3+  M *
 
 "//<<	+<#<BL+L)DDA*+'i$4! 	 ( 	 (7%"."A("K"K"l7O#}}-@AAA}T		!!A#&%//&&-@)A)AAA!!A#&|>? ? 1B-*7''0@-*7'"%  O;..Szgw///C7NN4>>#...C7NN4>>#...(TZ-G($>>$*c3??DD!'c
!3!3JD$t~~d333DCPP4+?+?+O+OPPPPPPD#,#5%,"2%N+'*+>'?'?&?
 
 
" 	
!
''--199-'$*>>FZ++F33FUNEN	
 	
 	
 ( 	;7?#--gr::G==E!!#'w"7D%.%8T"rH   c                 R    | j         |                     |          S | j         j        S )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.)r   r  r  )r   r  s     rE   r  zrevlog._get_data_offset	  s'     <88D>>!<((rH   c                 F   | j         d}t          j        |          | j         \  }	}
}| j        !|	                    dt
          j                   n*|	                    | j        j        t
          j                   |
rR| j        !|
                    dt
          j                   n*|
                    | j        j	        t
          j                   |r*|                    | j        j
        t
          j                   t          |           dz
  }| j        s|                    | j        |           | j        r|                    | j        |           |                    | j        |t          |          z             |d         r|
                    |d                    |
                    |d                    |r|                    |           |	                    |           n||| j        j        z  z  }|                    | j        |           |	                    |           |	                    |d                    |	                    |d                    |rJ |                     |           | j        | j         d         }| j         d         }| j         d         }|J |J |J |                                | j        _        |                                | j        _	        |                                | j        _
        t-          j        ||            d S )Nr  r   r   r   )r   r+   r  r   r/  r0  r1  r   r2  r  r  r   r   rO   r   r   r   r  rq   rf  r  r  r   r[  )r   r]  r  ro   r  r~  r:   r  r  r  r  r  r  wh1wh2wh3s                   rE   r  zrevlog._writeentry
  s    'FC(----S$<HHQ$$$$HHT\+R[999 	=|#BK((((.<<< 	>IIdl/===4yy1}| 	1OODNF333! E 2ODDDOODOTCJJ->???Aw #		$q'"""IId1g %

8$$$IIedTZ222FOODOV444IIeIId1gIId1g##K000<#&q)C&q)C&q)C?????????%(XXZZDL"$'HHJJDL!(+

DL%,[$?????rH   c                 .   | j         rt          j        d          d| _         d}	 |                     |          5  d}| j        r|j        }t          j        | |          }	|D ]}
|
\  }}}}}}}} ||          }|pt          }| j	        
                    |          }|'|                     ||           |r || |           d}e||fD ]D}| j	                            |          s(t          j        || j        t          d                    E| j	                            |          s(t          j        || j        t          d                    |                     |          }|t$          k    r|                     |          rt)          j        d          }|                     |          }t/          |          |z
  }|d|         t1          j        ||          k    r-t          j        | j        |                     |                    |s |                     ||          r
|t:          z  }|                     |d|||||||f||	|	          }|r || |           d}	 ddd           n# 1 swxY w Y   d| _         n# d| _         w xY w| S )
a\  
        add a delta group

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

        If ``addrevisioncb`` is defined, it will be called with arguments of
        this revlog and the node that was added.
        s   cannot nest addgroup() callsTNr  Fs   unknown parents   unknown delta bases   >lll)r  r  r:   )r   r+   r  r  r   r
  rv  r  r!   rq   r  r  has_noderi  r   r
   r   rE  r   
iscensoredstructcalcsizer|  r   r,   replacediffheaderCensoredBaseErrorrS   _peek_iscensoredr&   r  )r   r3   
linkmapperr]  r  addrevisioncbduplicaterevisioncbemptyr  r  ro   rS   rb  rc  rf   	deltabaserd   rb   r:   r  rE  r  rW  hlenoldlennewlens                             rE   addgroupzrevlog.addgroupH
  s   (  	J()HIII!W	'{++ T" T""$ 6"-"5K ) 7 +! ! !
 # K" K"D 	 ! %:h//D!9%9E*,,T22C33KEEE. ;//c::: %  "X  #z22155 "'"3 !4:q1B/C/C# # 
  :..y99 #/%t:O8P8P   #hhy11G'))doog.F.F)  &w77!%g!6!6!$Ud!2 $<5+B"F, ,   #("9 $71C1C# #  ! 3T%:%:7E%J%J 3!22 ++# %($/&3!) ,  C % 1%dC000!EEWK"T" T" T" T" T" T" T" T" T" T" T" T" T" T" T"l "'DD&&&&ys/   J H-I5)J 5I99J <I9=J 	Jc                 N    | j         sdS |                     |          t          z  S )z%Check if a file revision is censored.F)r   rb   r&   rD  s     rE   r,  zrevlog.iscensored
  s(     	5zz#!222rH   c                 J    | j         sdS t          j        ||| j                  S )z6Quickly check if a delta produces a censored revision.F)r   r;   deltaiscensoredr|  )r   rW  rd   s      rE   r1  zrevlog._peek_iscensored
  s)     	5*5'4<HHHrH   c                     t          j        |t          |           dz
  |                                 | j        | j                  S )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   )r;   resolvestripinfor   r  r  r  )r   minlinks     rE   getstrippointzrevlog.getstrippoint
  s>     +IIMMMOOLO
 
 	
rH   c                 &   t          |           dk    rdS |                     |          \  }}|t          |           k    rdS |                     |          }| j        s+|                    | j        |           || j        j        z  }n||| j        j        z  z   }| j        r0| 	                    |          }|                    | j        |           |                    | j
        |           | j        @|| j        _        || j        _        || j        _        | j                            |d           d| _        t#          j        d          | _        | j                                         | j                                         | j        |d= dS )a7  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   rA  rO  r   rO   r   rq   rf  r   rr  r   r   r   r  r  r  r   r1   r   r   r   ra  r   )r   r@  r]  rE  r
   r  r  r  s           rE   stripzrevlog.strip
  s    t99>>F##G,,Q#d))F ::c??| 	;OODNH555
--CCcDJ$99:C 	>0055LOOD.===---<# &)DL"$,DL!(4DL%L{d;;; ##055%%'''"..000Js2vrH   c                 Z   d}t          |           r3t          d|                     t          |           dz
                      }	 |                                 5 }|                    dt
          j                   |                                }ddd           n# 1 swxY w Y   ||z
  }n# t          $ r d}Y nw xY w	 | 	                    | j
                  }|                    dt
          j                   |                                }|                                 | j        j        }t          d||z            }|||z  z
  }| j        rGd}| D ](}	|t          d|                     |	                    z  })d}|t          |           |z  z
  |z
  }n# t          $ r d}Y nw xY w||fS )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:  r/  ior1  r  r   r   r   r  rq   rf  r   ru  )
r   expectedr3  actualddsr  di	databytesr  s
             rE   	checksizezrevlog.checksize	  s    t99 	71dhhs4yy1}5566H	 "1q"+&&&" " " " " " " " " " " " " " " ("BB  	 	 	BBB		DO,,AFF1bk"""VVXXFGGIII
%AAv{##A1q5!B| 8	 8 8AQA!7!77IIc$ii!m+i7  	 	 	BBB	 BxsI   B, 5BB, BB, "B#B, ,B;:B;?CF F&%F&c                 H   | j         g}| j        "| j        s|                    | j                   n|                    | j                   |                    | j                            d                     | j        j        r|                    | j                   |                    | j        	                    d                     | j        j
        r|                    | j                   |                    | j                            d                     |S )NF)include_empty)r   r   r   r  r   extendr   old_index_filepathsr  old_data_filepathsr  r   old_sidedata_filepaths)r   ress     rE   fileszrevlog.files1  s    $< +

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

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

4-...JJt|:::OOPPP
rH   c                    |dvrt          j        d|z            |	| j        sd}| j        s|t          j        k    rt          j        }t          j        | ||t          | j
        | j        | j        | j        | j        ||||          S )N)s   nodes   storages   linearNs"   unhandled value for nodesorder: %srW  )	deltaparentfn
candeltafn	rawsizefn	revdifffnflagsfn	deltamoderevisiondataassumehaveparentrevisionssidedata_helpers)r+   r  r   r   r2   CG_DELTAMODE_PREVCG_DELTAMODE_FULLr;   emitrevisionsrX   r  rX  r|  r  rb   )r   nodes
nodesorderr^  r_  r]  r`  s          rE   rc  zrevlog.emitrevisionsA  s     DDD(5
B   d&8#J &	5Z999"4I(*}llJ%&?-
 
 
 	
rH      always   samerevs   never   fulladd>   rh  rf  ri  rg  c                    || j         vrt          t          d          |z            t          |          rt          t          d                    t	          | dd          rt          t          d                    t	          |dd          rt          t          d                    |j        }|j        }|j        }		 || j        k    rd|_        d|_        n3|| j	        k    rd|_        d|_        n|| j
        k    rd|_        d|_        |p|	|_        |                     ||||||           ||_        ||_        |	|_        dS # ||_        ||_        |	|_        w xY w)	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   r   DELTAREUSEALWAYSDELTAREUSESAMEREVSDELTAREUSENEVER_clone)
r   r  
destrevlogr3  
deltareuseforcedeltabothparentsr`  oldlazydeltaoldlazydeltabaseoldamds
             rE   clonezrevlog.clonep  s   j T///566C   z?? 	DQABBCCC4.. 	IQFGGHHH:~t44 	NQKLLMMM ",%4-	2T222,0
)(,
%%t666,1
)(,
%%t333,1
)(-
%+@+JFJ(KK%    %1J!(8J%+1J((( %1J!(8J%+1J(1111s   A0E E"c                 R   d}| j         r|j        }t          j        ||          }| j        }	| D ]}
|	|
         }|d         dz  }|d         }|	|d                  d         }|	|d                  d         }|d         }d}d}|| j        k    r||                     |
          }|                     |
          }|/t          j	        | |||
          \  }}||d         |d	          z  z  }|
                    ||||||||||

  
         n|j        rD|                     |
          }|t          k    r$|t          |                     |
                    f}d}|s*|                     |
          }|                     |
          }||                     |
          }|/t          j	        | |||
          \  }}||d         |d	          z  z  }|                    |          5  |                    ||||||||||
  
         ddd           n# 1 swxY w Y   |r || |
|           dS )zBperform the core duty of `revlog.clone` after parameter processingNr  r   r   r   r  r   r  r   )r  rS   rb   r  r:   r  )r   r
  rv  r  rq   DELTAREUSEFULLADDr  r:   r  run_sidedata_helpersr  r   r  r   r  rr  r  r  )r   r  rp  r3  rq  rr  r`  r  r  rq   rE  r  rb   r  rb  rc  rS   r  r  rD   r:   	new_flagsdps                          rE   ro  zrevlog._clone  s     	%*K!/#
 
 
 
 G	/ G	/C#JE !Hv%EAhGuQx#BuQx#B8D JGT333))#..==--#/,8,M.#- -)Xy "IaLIaL=$@@E&&)"/% '     ( C))#..BW}}&(%C0@0@*A*A%B
! 2"0055G#}}S11H##}}S11H#/,8,M.#- -)Xy "IaLIaL=$@@E((,,  ++"&3!) ,                   /dC...OG	/ G	/s    HH	H	rH   c                     | j         t          k    r)t          j        t	          d          | j         z            | j         t
          k    rt          j        | |||           d S t          j        | |||           d S )Ns%   cannot censor with version %d revlogs)	r   r   r+   r   r
   r   r9   	v1_censor	v2_censor)r   r  
censornode	tombstones       rE   censorrevisionzrevlog.censorrevision.  s    8++#:;;&'   !X--dB
I>>>>>dB
I>>>>>rH   c           	   #     K   |                                  \  }}|r"t          t          d          |z            V  |r"t          t          d          |z            V  | j        }||d         k    r0t          t          d          | j        ||d         fz            V  t                      |d<   t                      |d<   | D ]}|                     |          }	 |                    d	d
          }|r||                     |          z  }t          | |||           | 
                    |          }t          |                     |                    }	||	k    r%t          t          d          |	|fz  |          V  # t          j        $ rG |d         r;t          t          d          |          V  |d                             |           Y t           $ rj}
t          t          d          t#          |          t%          j        |
          fz  |          V  |d                             |           Y d}
~
d}
~
ww xY wdS )zVerifies the integrity of the revlog.

        Yields ``revlogproblem`` instances describing problems that are
        found.
        s   data length off by %d bytes)r+   s   index contains %d extra bytess   expectedversions0   warning: '%s' uses revlog format %d; expected %d)rj   rN   s   safe_renameds	   skipflagsr   s    unpacked size is %d, %d expected)r+   rS   s   erroroncensoreds   censored file datas   unpacking %s: %sN)rM  ri   r
   r   r   r  rS   r   rb   rT   r|  r   rz  r+   r  rO   	Exceptionr   r<   r  )r   rR   rI  rK  versionrE  rS   rQ   l1l2rq  s              rE   verifyintegrityzrevlog.verifyintegrity9  s      !!B 	Na(F&G&G"&LMMMMMM 	Pa(H&I&IB&NOOOOOO& e.///MNN?GU3E-FGH     
 !UUk!$o O	- O	-C99S>>Dd-!IIlA66	 1C0I y%>>>\\#&&d++,,88' CDDBxO!     
 * 1 1 1+, 1' 566T      +&**4000 - - -#/00T{{J$;A$>$>?@     
 k"&&t,,,,,,,,-SO	- O	-s!   "B$FAI	I%AI

Ic                     i }|r@ j          j        fg|d<    j        s'|d                              j          j        f           |rg |d<   |rt                     |d<   |r2t          t           j        t                                         |d<   |r0t           fd 
                                D                       |d<   |S )Ns   exclusivefiless   sharedfiless   revisionscounts   trackedsizec              3   V   K   | ]#}j                             |          j        V  $d S rl   )r   statr   )r  pathr   s     rE   r  z%revlog.storageinfo.<locals>.<genexpr>  sG       # #37  &&.# # # # # #rH   s
   storedsize)r   r   r   r  r   r   r  r8  r|  rJ  rU  )r   exclusivefilessharedfilesrevisionscounttrackedsize
storedsizer  s   `      rE   storageinfozrevlog.storageinfo  s     	K%)[$/$B#CA < K#$++T[$.,IJJJ 	# "An 	-#&t99A  	C #Cd4jj$A$A B BAn 	" # # # #;?::<<# # #    Am rH   c                 $   | j         sd S | j        rJ |d         s
|d         sd S g }|                     |          5  | j        \  }}}|                    | j        j        t          j                   |	                                }	t          ||dz             D ]}
| j        |
         }t          j        | |i |
          \  }}t          j        |          }t          }|r| j         r~t           }|                     |          \  }}|dk    rY|d         dk    rMt%          |          t%          |          k     r-|rJ |d         | j        j        k    r
t(          }|}n	t          }|}|d         dk    s|d         dk    rd	}t+          j        |          |d         |d         |d          z  z  }|	t%          |          ||f}|                    |	t          j                   |                    |           |                    |           |	t%          |          z  }	|	                                | j        _        |                    || j        j        z             t5          |          D ]\  }}||z   }
 | j        j        |
g|R   | j                            |
          }|
dk    r5| j        .| j        | j        z  }| j                            |          }||z   }|                    |           	 d d d            d S # 1 swxY w Y   d S )
Nr   r   )storer`  r:   rE  r  r   r  rm  rn  s0   rewriting existing sidedata is not supported yet) r   r   r  r   r/  r   r  r0  r2  r  rK  rq   r  ry  r  r   r   r  r   r#  r   r+   Abortr  r  rf  r  replace_sidedata_infor  r   r   r  )r   r]  helpersr  rh  new_entriesr  r  r  current_offsetrE  r  new_sidedatarb   r   r  r!  r"  r  new_offset_flagsentry_updater  rq  packedr  s                            rE   rewrite_sidedatazrevlog.rewrite_sidedata  s    	F<qz 	'!* 	F]];'' G	" G	"!1NCdHHT\.<<<!YY[[NXvz22 68 68
3&2&G%,	' ' '#e '3&E ' '# -=)& @4+; @0?-'+}}5H'I'I$A}T		)!,55..5H1I1III#$)!,#|FG G 9J52?//8H52?/8q==E!HMM NC+c*** $)8eAh%(.B#B "+,,$-	  		."+666

.///""<000#&9":"::,0IIKK)) HHX
 55666!+.. " "1l0
09q99990055!88 4!/$2FFF!Z33F;;F#f_F		&!!!!"G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	" G	"s   J;LL	L	)	NFFFNFNFTrl   )r(  )r   N)r   F)NN)F)r   r@   )NNN)FNN)rH   )FFFFF)~r[   r\   r]   __doc__r+   r   _flagserrorclassr   r   r   r   r1   propertycacher   r   r  r!  r&  r+  r  r  r:  
contextlibcontextmanagerr<  r@  rB  rF  rH  rL  rR  rU  rX  r^  rb  rE  rO  rr  rb   ru  rx  r|  r   r  r  r  r  r  rS   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r!  r)  r#  r/  r-  r2  r)   r>  rO  rQ  r_  rd  rl  rr  r  r  r  r  r  rP   r:   r  r  r  rz  r  r  r  r  r  r  r  r!   r  r  r  r$  r  r  r  r:  r,  r1  rA  rD  rM  rU  r2   CG_DELTAMODE_STDrc  rl  rm  rn  rx  rk  rv  ro  r  r  r  r  rA   rH   rE   r>   r>      s       + +Z ( #_= _= _= _=BP= P= P=d   2Z! Z! Z! Z!x 
   
     
= = = 
  7 7 7   
 
 
6 6 6 6   # # #( ( ($ $ $  & & &G G G G    H H H> > >*J J J$- - -  "+ + +" " "" " "
  ' ' '  $  " " "& & & &  2 2 2* * *' ' '  >' ' ' 'RN N N N*F F F>: >: >: >:@M M M M + + + +0C C C C4^* ^* ^* ^*@? ? ? ?6 6 6: : :0 0 0 04  1 1 1  ( ( (I I I          D> > >@K K K15 15 15 15fB B B F  F  F  FD) ) ) ),B B B BH  % % %@1 1 1	F 	F 	F2 2 2 2# # # #* * * *X)% )% )% )%V$ $ $L< < < <: : :   >\  \  \ |? ? ?    ?  ?  ? B( ( (  "L
 L
 L
 L
n    >  0+ 0+ 0+x C C C CJ) ) )?@ ?@ ?@L  q q q qf3 3 3I I I
 
 
0 0 0d& & &P  & "'-%
 %
 %
 %
N !$O"BBBM %"a2 a2 a2 a2FY/ Y/ Y/v	? 	? 	? 	?g- g- g-V    >R" R" R" R" R"rH   )mr  r  r  r  rF  r0  r-  r  rS   r   r   r   r   r   r	   i18nr
   r.   r   revlogutils.constantsr   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(    r)   r*   r+   r,   r-   r/   r0   r1   
interfacesr2   interfaceutilr3   rv  r4   r   r5   r6   r   r7   r8   r9   r:   r  utilsr;   r<   	importmodr=   
importrustr  r  r~   r$  r  r  rF   rJ   rL   r   rT   r   HAS_FAST_PERSISTENT_NODEMAPimplementerirevisiondeltarJ  rX   iverifyproblemri   rs   rw   ry   r|   r   r  r  rI  r>   rA   rH   rE   <module>r     s             				 				                                                                          .                       
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	        	                            
&
9
%
% v ,,Fg&&	Vx((
 / 
      
     )4 8H8H9 9 
 :455d% % % % % % %  65% :455t! ! ! ! ! ! !  65!       4G899 "    "/ / / Q;  
 &	b0" b0" b0" b0" b0" b0" b0" b0" b0" b0"rH   