
    q&f/T              
       @   d dl Z d dlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ  ej&                  ej(                        Zd	Zd
 Z e j0                  d      Zd Zd Zd Zd Zd Zd ZddZ d Z!d Z"dddddejF                  ddddf
dZ$d Z%y)    N   )_)binnullrevsha1nodeconstants)dagoperrormdiff)
repository)sidedata)hashutil   c                    |t         j                  k(  r&t        j                         }|j	                  |       n4||k  r|}|}n|}|}t        j                  |      }|j	                  |       |j	                  |        |j                         S )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   "   sw     
%%%NN	 7AAAAMM!	HHTN88:       
c                     | dd dk7  ryt         j                  | d      j                         }| d| }i }|j                         D ]  }|j	                  dd      \  }}|||<    ||dz   fS )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+   ?   s     BQx94#))+A1IED wwua 1Q Q;r   c                 \     t               }dj                   fd|D              }d||fz  S )z2Add metadata to fulltext to produce revision text.r   c              3   2   K   | ]  }d ||   fz    yw)s   %s: %s
N ).0r)   r'   s     r   	<genexpr>zpackmeta.<locals>.<genexpr>T   s     Aqq$q'l2As   s   
%s
%s)sortedjoin)r'   r   keysmetatexts   `   r   packmetar5   Q   s0    $<DxxADAAH(D!111r   c                 .    t        |       d   }|xr d|v S )Nr   s   censored)r+   )r   r'   s     r   iscensoredtextr7   X   s     T?1D'K4''r   c                 \    | j                  d      s| S | j                  dd      }| |dz   d 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<   ]   s6     ??9%ZZ	1%F
r   c                     | j                  |      d   t        j                  k7  ryt        | j	                  |            d   }|rd|v rd|v r|d   t        |d         fS y)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   filerevisioncopiedrB   j   sl     }}T1!2!9!99 U^^D)*1-D
 4J$$6G}c$z"2333r   c                    |j                  d      rd|z   }n|}| j                  |      \  }}t        |||      }||k(  ry| j                  | j	                  |            r|dk(  S | j                  |      r| j                  |      |k(  S y)ah  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)r9   r>   r   
iscensoredrevrenamedread)r@   rA   filedatarevisiontextr   r   computednodes          r   filedataequivalentrK      s     9%&1]]4 FB#L"b9Lt 		$(3 }}Tzz$8++r   c                 P    d}|||kD  rd}||z  }|| kD  r| }n| }t        |||      S )z)Iterate over revision numbers in a store.r   )range)storelenr#   stopsteps       r   iterrevsrR      sB    D4<D(?Dd##r   c                    t        |t              r	 | j                  |      S t        |      t        | j                        k(  r	 | j                  |       |S t        |      dt        | j                        z  k(  r	 t        |      }| j                  |       |S 	 t        |      }d|z  |k7  rt        	 | j                  |      S # t        $ r$ t	        j
                  d|z  |t        d            w xY w# t        j
                  $ r Y w xY w# t        $ r Y w xY w# t        t        f$ r Y nw xY wn# t        t        f$ r Y nw xY wt	        j
                  ||t        d            )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intrA   
IndexErrorr	   LookupErrorr   lenr   rE   r   	TypeError
ValueErrorOverflowError)r@   fileid
identifierrawnoderE   s        r   fileidlookupr_      sm   " &#	::f%% 6{c%,,''	IIfM 6{a#ell+++	&kGIIgN&k3;& 	::c?"7  	##
A.?,@ 	    		  		 I& 		&  

FJ2C0D
EEs_   C C7 =D D5 6D -C47DD	DDD1.D5 0D11D5 5EEc                    t               }|dz   }i }t               }|D ]&  }	 ||	      }
|
||	<   |
| k\  s|j                  |
       ( |r||dz  }|j                  |      }|| k  r|j                  |       n|j                  |        ||      D ]0  }|t        k7  s ||      }|||<   || k\  s |j                  |       2 |r|||fS )a  Resolve information needed to strip revisions.

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

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

    ``tiprev`` is the current tip-most revision. It is ``len(store) - 1``.
    ``headrevs`` is an iterable of head revisions.
    ``linkrevfn`` is a callable that receives a revision and returns a linked
    revision.
    ``parentrevsfn`` is a callable that receives a revision number and returns
    an iterable of its parent revision numbers.
    r   )setaddpopremover   )
minlinkrevtiprevheadrevs	linkrevfnparentrevsfn
brokenrevs
strippointheadsfuturelargelinkrevsheadheadlinkrevlinkrevpplinkrevs                 r   resolvestripinfors      s    " J!JE% 1o!d*$##K0	1 a
))J'ZNN:&&&w/j) 	6AG|$Q<#az)'++H5	6   z!!r   Fc              #   T  %&'(K   | j                   }| j                  '| j                  (|dk(  r|D cg c]
  } '|       }}nO|dk(  r6|D ch c]
  } '|       }}t        j                  || j                        }nt        'fd|D              }d}|	t        j                  k(  s|r (|d         d   }t               &t               %|r8t        (fd|D              }|j                  |       | j                  |d      %%&fd	}|D ]0  }|t        k(  rd}||d
xx   dz  cc<    ||      } (|      \  }}|$||k7  r|t        k7  r|t        k7  r|dxx   dz  cc<   |r/ ||      }|+|t        k(  r|dxx   dz  cc<   n|dxx   dz  cc<   nt        }|	t        j                  k(  r|d}|}n|	t        j                  k(  r|d}t        }n|	t        j                  k(  r|d}|}ni ||      r|d}|}nZ|t        k(  r|d}|}nJ|t        k7  r||dxx   dz  cc<   n1 ||      r|d}|}n" ||      r|d}|}n||d}|}n
|d}t        }t        k7  r"|  |||      s|d}|dxx   dz  cc<   t        }d}d}d}|
r| j                  |      s| j                  |      rD	 | j                  |      }|t        k7  r|r
 ||      }nt'        | j                  |            }n|t        k(  rS|	t        j                  k7  r@||dxx   dz  cc<   |dxx   dz  cc<   | j                  |      }&j)                  |       nV|r|z|dk(  r|dxx   dz  cc<   |dxx   dz  cc<   nZ|dk(  r|dxx   dz  cc<   |dxx   dz  cc<   n:|dk(  r|dxx   dz  cc<   |dxx   dz  cc<   n|dk(  r|dxx   dz  cc<   nJ d        |||      }n||dk(  r|dxx   dz  cc<   |dxx   dz  cc<   ng|dk(  r|dxx   dz  cc<   |dxx   dz  cc<   nG|dk(  r|dxx   dz  cc<   |dxx   dz  cc<   n'|dk(  r|dxx   dz  cc<   |dxx   dz  cc<   nJ d       t+        j,                  | j                  |      | j                  |            }&j)                  |       d}d} |rE	 | j/                  |      }!t1        j2                  | ||!|      \  }"} |"rt1        j4                  |"      }|r ||      nd}#d}$|r|$t6        z  }$|#| d   | d    z  z  }# || ||       ||       ||      |#|||||$
       |}3 yc c}w c c}w # t         j"                  $ r(}|d}|dxx   dz  cc<   |j$                  }Y d}~d}~ww xY w# t         j"                  $ r i }"Y w xY ww) 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   .   K   | ]  } |        y wNr.   )r/   nfrevs     r   r0   z emitrevisions.<locals>.<genexpr>  s     -!d1g-s   Nr   c              3   <   K   | ]  } |      D ]  }|   y wrv   r.   )r/   rrq   r>   s      r   r0   z emitrevisions.<locals>.<genexpr>  s!     ?GAJ?q1?1?s   T)	inclusivec                 ,    | t         k(  ry| v xs | v S )z5Is a delta against this revision usable over the wireF)r   )rE   	availableemitteds    r   is_usable_basez%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   )r@   sidedata_helpersr   rE   )
rA   p1nodep2nodebasenodeflagsbaserevisionsizer?   deltar   protocol_flags)rA   rE   
parentrevsr   	linearizer1   r   CG_DELTAMODE_PREVra   difference_update	ancestorsr   CG_DELTAMODE_FULLCG_DELTAMODE_P1rD   rawdatar	   CensoredNodeError	tombstonerX   rb   r
   textdiffr   sidedatamodrun_sidedata_helpersserialize_sidedataCG_FLAG_SIDEDATA))r@   nodes
nodesorder	resultclsdeltaparentfn
candeltafn	rawsizefn	revdifffnflagsfn	deltamoderevisiondataassumehaveparentrevisionsr   
debug_infofnoderw   revsprevrevcommon_headsr   rE   debug_delta_sourcerA   p1revp2revdeltaparentrevbaserevr?   r   r   eserialized_sidedatasidedata_flagsold_sidedatar   r   r   r}   r~   rx   r>   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 ?d??&&t,OOLDOA	2  O'>!!'(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+$}}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^-()
 	
 _O5 ('F .. +!--3*"#?@AE@ {{H	+D ** sm   .V(UV(U
IV(1UG*V(-V>BV(V
"V?V(V

V(V%"V($V%%V(c                     t        j                  d      }t        |       |k  ry ||      }t        |       |z
  }| d| t        j                  ||      k7  ryd}t        |      }||k\  xr | |||z    |k(  S )aR  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calcsizerX   r
   replacediffheader)r   r   	baselenfnhlenoldlennewlenrb   addlens           r   deltaiscensoredr   m  s     ??7#D
5zTwFZ$FUd|u..vv>>
CXFVBdTF] ;s BBr   )r   N)&rer   i18nr   rA   r   r   r    r   r	   r
   
interfacesr   revlogutilsr   r   utilsr   r   r   r   r   r   compiler!   r+   r5   r7   r<   rB   rK   rR   r_   rs   CG_DELTAMODE_STDr   r   r.   r   r   <module>r      s    
   
 
 $ 1 HMM+223	  4 bjj#$2(

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