
    	^cD              	       $   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 j        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j#        dddf	dZ$d Z%dS )    N   )_)binnullrevsha1nodeconstants)dagoperrormdiff)
repository)sidedata)hashutil   c                 B   |t           j        k    r/t                                          }|                    |           n8||k     r|}|}n|}|}t          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   "   s     
%%%NN	 77AAAAAM!	HHTNNN88::       
c                    | dd         dk    rdS t                               | d                                          }| d|         }i }|                                D ] }|                    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     BQBx9z4##))++A1IED  wwua  1QQ;r   c                 r     t                     }d                     fd|D                       }d||fz  S )z2Add metadata to fulltext to produce revision text.r   c              3   2   K   | ]}d ||         fz  V  dS )s   %s: %s
N ).0r)   r'   s     r   	<genexpr>zpackmeta.<locals>.<genexpr>T   s0      AAqq$q'l2AAAAAAr   s   
%s
%s)sortedjoin)r'   r   keysmetatexts   `   r   packmetar5   Q   sD    $<<DxxAAAADAAAAAH(D!111r   c                 8    t          |           d         }|od|v S )Nr   s   censored)r+   )r   r'   s     r   iscensoredtextr7   X   s"    T??1D'K4''r   c                 v    |                      d          s| S |                     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<   ]   sC     ??9%% ZZ	1%%F
r   c                     |                      |          d         t          j        k    rdS t          |                     |                    d         }|r%d|v r!d|v r|d         t          |d                   fS dS )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   s     }}T1!2!999 uU^^D))**1-D
  44J$$6$6G}c$z"233335r   c                 Z   |                     d          rd|z   }n|}|                     |          \  }}t          |||          }||k    rdS |                     |                     |                    r|dk    S |                     |          r|                     |          |k    S dS )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99Ltt 		$(( 3 }}T ,zz$8++5r   c                 \    d}|||k    rd}||z  }|| k    r| }n| }t          |||          S )z)Iterate over revision numbers in a store.r   N)range)storelenr#   stopsteps       r   iterrevsrR      sJ    D4<<D(??Dd###r   c                    t          |t                    rJ	 |                     |          S # t          $ r' t	          j        d|z  |t          d                    w xY wt          |          dv r-	 |                     |           |S # t          j        $ r Y nw xY wt          |          dv r7	 t          |          }|                     |           |S # t          $ r Y nw xY w	 t          |          }d|z  |k    rt          	 |                     |          S # 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 20 or 32 byte binary node.
    * An integer revision number
    * A 40 or 64 byte hex node.
    * 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 found)       )(   @   )
isinstanceintrA   
IndexErrorr	   LookupErrorr   lenrE   r   	TypeError
ValueErrorOverflowError)r@   fileid
identifierrawnoderE   s        r   fileidlookuprc      s   " &# 	::f%%% 	 	 	#
A.?,@,@  	
 6{{h	IIfM  	 	 	D	 6{{h	&kkGIIgN 	 	 	D	&kk3;&  	::c??"I& 	 	 	D	&    
FJ2C0D0D
E
EEs]   , 1A2B	 	BB0%C 
C#"C#'D4 D D0-D4 /D00D4 4EEc                    t                      }|dz   }i }t                      }|D ]-}	 ||	          }
|
||	<   |
| k    r|                    |
           .|r|dz  }|                    |          }|| k     r|                    |           n|                    |            ||          D ]8}|t          k    r+ ||          }|||<   || k    r|                    |           9|||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   resolvestripinforw      s1   " J!JE%% 1 1ioo!d*$$##K000  6a
))J''ZNN:&&&&&&w///j)) 	6 	6AG||$9Q<<#az))'++H555  6  z!!r   Fc              #     "#$%K   | j         }| j        $| j        %|dk    r$fd|D             }nJ|dk    r)$fd|D             }t          j        || j                  }nt          $fd|D                       }d}|	t          j        k    s|r %|d                   d         }t                      #t                      "|rGt          %fd|D                       }|	                    |           | 
                    |d	
          ""#fd}|D ]}|t          k    r ||          } %|          \  }}|r ||          }nt          }|	t          j        k    r|}na|	t          j        k    rt          }nI|	t          j        k    r|}n6 ||          r|}n( ||          r|}n ||          r|}n||}nt          }|t          k    r|r |||          st          }d}d}d}|
rE|                     |          s|                     |          rv	 |                     |          }n## t           j        $ r}|j        }Y d}~nd}~ww xY w|t          k    r0|r ||          }nt'          |                     |                    }n|t          k    r;|	t          j        k    r+|                     |          }#                    |           n_|r |||          }n;t+          j        |                     |          |                     |                    }#                    |           d}d}|r_	 |                     |          }t1          j        | |||          \  }}n# t           j        $ r i }Y nw xY w|rt1          j        |          }|r ||          nd} d}!|r|!t6          z  }!| |d         |d          z  z  }  || ||           ||           ||          | |||||!
  
        V  |}dS )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`.
    s   nodesc                 &    g | ]} |          S r.   r.   r/   nfrevs     r   
<listcomp>z!emitrevisions.<locals>.<listcomp>|  !    '''AQ'''r   s   linearc                 &    h | ]} |          S r.   r.   rz   s     r   	<setcomp>z emitrevisions.<locals>.<setcomp>~  r~   r   c              3   .   K   | ]} |          V  d S Nr.   rz   s     r   r0   z emitrevisions.<locals>.<genexpr>  s+      --!dd1gg------r   Nr   c              3   8   K   | ]} |          D ]}|V  d S r   r.   )r/   rru   r>   s      r   r0   z emitrevisions.<locals>.<genexpr>  s8      ??GGAJJ??q1???????r   T)	inclusivec                 .    | t           k    rdS | v p| 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%    '>>5g~1	!11r   )r   r   )r@   sidedata_helpersr   rE   r   )
rA   p1nodep2nodebasenodeflagsbaserevisionsizer?   deltar   protocol_flags)rA   rE   
parentrevsr   	linearizer1   r   CG_DELTAMODE_PREVre   difference_update	ancestorsr   CG_DELTAMODE_FULLCG_DELTAMODE_P1rD   rawdatar	   CensoredNodeError	tombstoner\   rf   r
   textdiffr   sidedatamodrun_sidedata_helpersserialize_sidedataCG_FLAG_SIDEDATA)&r@   nodes
nodesorder	resultclsdeltaparentfn
candeltafn	rawsizefn	revdifffnflagsfn	deltamoderevisiondataassumehaveparentrevisionsr   fnoderevsprevrevcommon_headsr   rE   rA   p1revp2revdeltaparentrevbaserevr?   r   r   eserialized_sidedatasidedata_flagsold_sidedatar   r   r   r   r   r|   r>   s&                                     @@@@r   emitrevisionsr   &  sI     b JE9DGX'''''''	y	 	 '''''''tU%566----u-----GJ0004M0'$q'""1% eeGI  B????d?????&&t,,,OOLDOAA	2 2 2 2 2 2   '>>uSzzws||u 	%*]3//NN$N 
444GG *666GG*444GG
 ^N++ 	"$GG ~e$$ "&& " $!! g:jj#6N6NG 	!(( !E,<,<S,A,A !+$}}T22HH. + + + {HHHHHH+ g%%  G+49W+=+=((+.u}}W/E/E+F+F( 7""yJ4P'P'P ==..C     %Igs33EE!Ng..c0B0B E C   " 	O$~~c22
 ,7+K%5)	, , ,(..	 *     O&1&DX&N&N# '.Q 	C..NN1-1B0BBBEi5<<5<<U7^^-()
 
 
 	
 	
 	
  s*   H..I=I		I9M**M>=M>c                 $   t          j        d          }t          |           |k    rdS  ||          }t          |           |z
  }| d|         t          j        ||          k    rdS d}t          |          }||k    o| |||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calcsizer\   r
   replacediffheader)r   r   	baselenfnhlenoldlennewlenrf   addlens           r   deltaiscensoredr     s     ?7##D
5zzTuYwFZZ$FUdU|u.vv>>>>u
CXXF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   rc   rw   CG_DELTAMODE_STDr   r   r.   r   r   <module>r      s   
			                
         
 $ # # # # # 1 1 1 1 1 1      HM+233	    4 bj##  $2 2 2( ( (

 
 
  6" " "J$ $ $ $ 5F 5F 5Fp1" 1" 1"r )#o o o odC C C C Cr   