
    6hOT              
      P   S SK Jr  S SKrS SKrSSKJr  SSKJrJrJ	r	  SSK
JrJrJr  SSKJr  SSKJr  SS	KJr  \R*                  " \	R,                  5      rS
rS r\R4                  " S5      rS rS rS rS rS r S r!SS jr"S r#S r$SSSSS\RJ                  SSSS4
S jr&S r'g)    )annotationsN   )_)binnullrevsha1nodeconstants)dagoperrormdiff)
repository)sidedata)hashutil   c                "   U[         R                  :X  a&  [        R                  5       nUR	                  U5        O5X:  a  UnUnOUnUn[
        R                  " U5      nUR	                  U5        UR	                  U 5        UR                  5       $ )zCompute the SHA-1 for revision data and its parents.

This hash combines both the current file contents and its history
in a manner that makes it easy to distinguish nodes with the same
content in the revision graph.
)r   nullid	_nullhashcopyupdater   sha1digest)textp1p2sabs         =/usr/lib/python3/dist-packages/mercurial/utils/storageutil.pyhashrevisionsha1r   #   su     
%%%NN	 7AAAAMM!	HHTN88:       
c                    U SS S:w  a  g[         R                  U S5      R                  5       nU SU n0 nUR                  5        H  nUR	                  SS5      u  pVXcU'   M     X1S-   4$ )zParse metadata header from revision data.

Returns a 2-tuple of (metadata, offset), where both can be None if there
is no metadata.
Nr   r    )NNs   : r   )METADATA_REsearchstart
splitlinessplit)r   r   mtextmetalkvs          r   	parsemetar,   @   sz     BQx94#))+A1IEDwwua Q   Q;r   c                \   ^  [        T 5      nSR                  U 4S jU 5       5      nSX14-  $ )z2Add metadata to fulltext to produce revision text.r   c              3  8   >#    U  H  nS UTU   4-  v   M     g7f)s   %s: %s
N ).0r*   r(   s     r   	<genexpr>packmeta.<locals>.<genexpr>U   s     ADqq$q'l2Ds   s   
%s
%s)sortedjoin)r(   r   keysmetatexts   `   r   packmetar7   R   s.    $<DxxADAAH(!111r   c                :    [        U 5      S   nU=(       a    SU;   $ )Nr   s   censored)r,   )r   r(   s     r   iscensoredtextr9   Y   s     T?1D'K4''r   c                d    U R                  S5      (       d  U $ U R                  SS5      nXS-   S $ )zExtract just the revision data from source text.

Returns ``text`` unless it has a metadata header, in which case we return
a new buffer without hte metadata.
r    r   N)
startswithindex)r   offsets     r   filtermetadatar>   ^   s7     ??9%%ZZ	1%F
r   c                    U R                  U5      S   [        R                  :w  a  g[        U R	                  U5      5      S   nU(       a  SU;   a  SU;   a  US   [        US   5      4$ g)zResolve file revision copy metadata.

Returns ``False`` if the file has no copy metadata. Otherwise a
2-tuple of the source filename and node.
r   Fs   copys   copyrev)parentsr   r   r,   revisionr   )storenoder(   s      r   filerevisioncopiedrD   k   sl     }}T1!2!9!99 U^^D)*1-D
 4J$$6G}c$z"2333r   c                2   UR                  S5      (       a  SU-   nOUnU R                  U5      u  pE[        X4U5      nXa:X  a  gU R                  U R	                  U5      5      (       a  US:H  $ U R                  U5      (       a  U R                  U5      U:H  $ g)aL  Determines whether file data is equivalent to a stored node.

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

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

When a stored revision has copy metadata, it is ignored as part
of the compare.
r    s   

Tr   F)r;   r@   r   
iscensoredrevrenamedread)rB   rC   filedatarevisiontextr   r   computednodes          r   filedataequivalentrM      s     9%%&1]]4 FB#Lb9L 		$((3 }}Tzz$8++r   c                N    SnUb  X:  a  SnX#-  nX :  a  U nOU n[        XU5      $ )z)Iterate over revision numbers in a store.r   )range)storelenr$   stopsteps       r   iterrevsrT      s;    D<D?Dd##r   c                   [        U[        5      (       a   U R                  U5      $ [        U5      [        U R                  5      :X  a   U R                  U5        U$ [        U5      S[        U R                  5      -  :X  a   [        U5      nU R                  U5        U$  [        U5      nSU-  U:w  a  [        e U R                  U5      $ ! [         a%    [        R
                  " SU-  U[        S5      5      ef = f! [        R
                   a     Nf = f! [         a     Nf = f! [        [        4 a     Of = f! [        [        4 a     Of = f[        R
                  " X[        S5      5      e)a  Resolve the file node for a value.

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

``fileid`` can be:

* A binary node of appropiate size (e.g. 20/32 Bytes).
* An integer revision number
* A hex node of appropiate size (e.g. 40/64 Bytes).
* A bytes that can be parsed as an integer representing a revision number.

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

Raises ``error.LookupError`` on failure.
s   %ds   no match foundr   )
isinstanceintrC   
IndexErrorr
   LookupErrorr   lenr   rG   r   	TypeError
ValueErrorOverflowError)rB   fileid
identifierrawnoderG   s        r   fileidlookupra      sj   " &#	::f%% 6{c%,,''	IIfM 6{a#ell+++	&kGIIgN&k3;& 	::c?"7  	##
A.?,@ 	    		  		 I& 		&  

F2C0D
EEs_   C D D #E >D+ /C>DD
D('D(+D>;E =D>>E EEc                   [        5       nUS-   n0 n[        5       nU H'  n	U" U	5      n
XU	'   X:  d  M  UR                  U
5        M)     U(       a  US-  nUR                  U5      nX:  a  UR                  U5        OUR                  U5        U" U5       H3  nU[        :w  d  M  U" U5      nXU'   X:  d  M"  UR                  U5        M5     U(       a  M  Xe4$ )ab  Resolve information needed to strip revisions.

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

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

``tiprev`` is the current tip-most revision. It is ``len(store) - 1``.
``headrevs`` is an iterable of head revisions.
``linkrevfn`` is a callable that receives a revision and returns a linked
revision.
``parentrevsfn`` is a callable that receives a revision number and returns
an iterable of its parent revision numbers.
r   )setaddpopremover   )
minlinkrevtiprevheadrevs	linkrevfnparentrevsfn
brokenrevs
strippointheadsfuturelargelinkrevsheadheadlinkrevlinkrevpplinkrevs                 r   resolvestripinforu      s    " J!JE%o!d$##K0	  a
))J'NN:&&&w/j)AG|$Q<#a)'++H5 * 
  !!r   Fc              #    ^(^)^*#    U R                   nU R                  m*U R                  nUS:X  a  U Vs/ s H  nT*" U5      PM     nnOUUS:X  a:  U Vs1 s H  nT*" U5      iM     nn[        R                  " UU R                  5      nO[        U*4S jU 5       5      nSnU	[        R                  :X  d  U(       a  U" US   5      S   n[        5       m)[        5       m(U(       aE  U VVs1 s H  nU" U5        H  nUiM     M     nnnUR                  U5        U R                  USS9m(U(U)4S jnU GH  nU[        :X  a  M  SnUb  US	==   S
-  ss'   U" U5      nU" U5      u  nnUb'  UU:w  a!  U[        :w  a  U[        :w  a  US==   S
-  ss'   U(       a1  U" U5      nUb%  U[        :X  a  US==   S
-  ss'   OUS==   S
-  ss'   O[        nU	[        R                  :X  a  Ub  SnUnOU	[        R                  :X  a  Ub  Sn[        nOU	[        R                  :X  a  Ub  SnUnOU" U5      (       a  Ub  SnUnOmU[        :X  a  Ub  SnUnO[U[        :w  a  Ub  US==   S
-  ss'   O@U" U5      (       a  Ub  SnUnO+U" U5      (       a  Ub  SnUnOUb  Ub  SnUnOUb  Sn[        nW[        :w  a)  Ub&  U" UU5      (       d  Ub  SnUS==   S
-  ss'   [        nSnSnSn U
(       Ga:  U R                  U5      (       d  U R                  U5      (       aI   U R                  U5      nU[        :w  a+  U(       a
  U" U5      n GO['        U R                  U5      5      n GOU[        :X  aU  U	[        R                  :w  aA  Ub  US==   S
-  ss'   US==   S
-  ss'   U R                  U5      nT)R)                  U5        GOfU(       a  Ub~  US:X  a  US==   S
-  ss'   US==   S
-  ss'   O]US:X  a  US==   S
-  ss'   US==   S
-  ss'   O<US:X  a  US==   S
-  ss'   US==   S
-  ss'   OUS:X  a  US==   S
-  ss'   O S5       eU" UU5      nOUb  US:X  a  US==   S
-  ss'   US==   S
-  ss'   OjUS:X  a  US==   S
-  ss'   US==   S
-  ss'   OIUS:X  a  US==   S
-  ss'   US==   S
-  ss'   O(US:X  a  US==   S
-  ss'   US==   S
-  ss'   O S5       e[*        R,                  " U R                  U5      U R                  U5      5      nT)R)                  U5        Sn"Sn#U(       aI   U R/                  U5      n$[0        R2                  " U UU$US9u  n%n#U%(       a  [0        R4                  " U%5      n"U(       a  U" U5      OSn&Sn'U"(       a  U'[6        -  n'U&U#S   U#S
   ) -  -  n&U" UU" U5      U" U5      U" U5      U&U UUU"U'S9
v   UnGM     gs  snf s  snf s  snnf ! [         R"                   a)  n!Ub  SnUS==   S
-  ss'   U!R$                  n Sn!A!GNSn!A!ff = f! [         R"                   a    0 n% Nf = f7f)a  Generic implementation of ifiledata.emitrevisions().

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

``nodesorder``
``revisiondata``
``assumehaveparentrevisions``
``sidedata_helpers`` (optional)
    If not None, means that sidedata should be included.
    See `revlogutil.sidedata.get_sidedata_helpers`.

``debug_info`
    An optionnal dictionnary to gather information about the bundling
    process (if present, see config: debug.bundling.stats.
s   nodess   linearc              3  4   >#    U  H  nT" U5      v   M     g 7f)Nr/   )r0   nfrevs     r   r1    emitrevisions.<locals>.<genexpr>  s     -u!d1ggus   Nr   T)	inclusivec                <   > U [         :X  a  gU T;   =(       d    U T;   $ )z5Is a delta against this revision usable over the wireF)r   )rG   	availableemitteds    r   is_usable_base%emitrevisions.<locals>.is_usable_base  s!    '>g~1	!11r   zrevision-totalr   zmerge-totalzavailable-fullzavailable-deltaprevfullr   storagezdenied-base-not-availabler   zdenied-delta-candeltafnzdenied-delta-not-availablezcomputed-deltaz
delta-fullzdelta-against-prevzdelta-against-p1zreused-storage-deltaunreachable)r   r   )rB   sidedata_helpersr   rG   )
rC   p1nodep2nodebasenodeflagsbaserevisionsizerA   deltar   protocol_flags)rC   rG   
parentrevsr	   	linearizer3   r   CG_DELTAMODE_PREVrc   difference_update	ancestorsr   CG_DELTAMODE_FULLCG_DELTAMODE_P1rF   rawdatar
   CensoredNodeError	tombstonerZ   rd   r   textdiffr   sidedatamodrun_sidedata_helpersserialize_sidedataCG_FLAG_SIDEDATA)+rB   nodes
nodesorder	resultclsdeltaparentfn
candeltafn	rawsizefn	revdifffnflagsfn	deltamoderevisiondataassumehaveparentrevisionsr   
debug_infofnoder@   rx   revsprevrevrrs   common_headsr   rG   debug_delta_sourcerC   p1revp2revdeltaparentrevbaserevrA   r   r   eserialized_sidedatasidedata_flagsold_sidedatar   r   r   r}   r~   ry   s+                                           @@@r   emitrevisionsr   '  s    l JJE99DGX!&'AQ'	y	 !&'AQ'tU%5%56-u--GJ0004M$q'"1% eGI #'<4aA4<&&t,OOLDOA	2 '>!!'(A-(Szs|u!~%7"2u7G=)Q.)*3/N%!W,/0A5001Q61 %N 
444%%+"G *666%%+"G*444%%)"G
 N++%%."$Gw&%%."$G(Z-C671<7  &&))-&&&))-& $))/&!))/&!
 w&w,,%%+"45:5G((E,<,<S,A,A+$}}T2H g% +4W+=(+.u}}W/E+F( 7"yJ4P4P'P)/0A50|,1, ==.C !--7&'78A=8&|494/69&'78A=8&';<A</47&'78A=8&'9:a?:/9<&'=>!C>7-75%gs3E!--7&'78A=8&|494/69&'78A=8&';<A</47&'78A=8&'9:a?:/9<&'78A=8&'=>!C>7-75!NNg.c0BE C "$~~c2
 ,7+K+K%5)	,(. &1&D&DX&N# 'Q..NN1-1B0BBBE<<7^-()
 	
 _ 5 (' =j .. +!--3*"#?@AE@ {{H	+D ** sz   /YWYW%BY)WHYW%(HY0X%B$Y%X"9XYX""Y%X>;Y=X>>Yc                    [         R                  " S5      n[        U 5      U::  a  gU" U5      n[        U 5      U-
  nU SU [        R                  " XE5      :w  a  gSn[        U5      nXW:  =(       a	    XX7-    U:H  $ )a:  Determine if a delta represents censored revision data.

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

Returns a bool indicating if the result of the delta represents a censored
revision.
s   >lllFNs   
censored:)structcalcsizerZ   r   replacediffheader)r   r   	baselenfnhlenoldlennewlenrd   addlens           r   deltaiscensoredr   n  s}     ??7#D
5zTwFZ$FUd|u..v>>
CXFBT] ;s BBr   )r   N)(
__future__r   rer   i18nr   rC   r   r   r    r	   r
   r   
interfacesr   revlogutilsr   r   utilsr   r   r   r   r   r   compiler"   r,   r7   r9   r>   rD   rM   rT   ra   ru   CG_DELTAMODE_STDr   r   r/   r   r   <module>r      s    # 	   
 
 $ 1 MM+223	  4 jj#$2(

6"J$ 5Fp1"r ))#DN
Cr   