403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /usr/lib64/python3.9/site-packages/mercurial/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/lib64/python3.9/site-packages/mercurial/__pycache__/bundle2.cpython-39.opt-1.pyc
a

�+�b�Z�@sdZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z m!Z!dd	l"m#Z#ej$Z$ej%Z%e	j&Z'e	j(Z)d
Z*d
Z+dZ,dZ-d
Z.d
Z/dZ0e�1d�Z2dd�Z3dd�Z4dd�Z5dd�Z6iZ7d�dd�Z8Gdd�de9�Z:Gdd�de9�Z;Gdd �d e<�Z=d!d"�Z>d�d#d$�Z?Gd%d&�d&e9�Z@d�d(d)�ZAd*d+�ZBd,d-�ZCd.d/�ZDd0d1�ZEd2d3�ZFd4d5�ZGd6dd7d8d9d:�ZHgd;�ZIGd<d=�d=e9�ZJGd>d?�d?e9�ZKd�d@dA�ZLGdBdC�dCeK�ZMdDeMiZNiZOdEdF�ZPePdG�dHdI��ZQGdJdK�dKe9�ZRdLZSGdMdN�dNeK�ZTGdOdP�dPe9�ZUdQdR�ZVGdSdT�dTeK�ZWGdUdV�dVeW�ZXdddWddeYeZej[�\���dXddYdZd[�
Z]d�d]d^�Z^d_d`�Z_dadb�Z`d�dcdd�Zadedf�Zbdgdh�Zcdidj�Zddkdl�Zedmdn�Zfdodp�Zgdqdr�Zhdsdt�Zidudv�Zjd�dxdy�Zkd�dzd{�Zld|d}�Zme8d~d�d�d���ZneYgd��d�d��ej[�\�D��Zoe8d�eo�d�d���Zpe8d�d��d�d���Zqe8d��d�d���Zre8d��d�d���Zse8d��d�d���Zte8d��d�d���Zue8d��d�d���Zve8d��d�d���ZwGd�d��d�ejx�Zye8d�d��d�d���Zze8d�d��d�d���Z{e8d�d��d�d���Z|e8d�d��d�d���Z}e8d�d��d�d���Z~e8d�d��d�d���Ze8d��d�d���Z�e8d��d�d���Z�e8d�d��d�d���Z�e8d��d�dÄ�Z�e8d�dŃd�dDŽ�Z�e8dȃd�dʄ�Z�e	��dˡZ�e8d̃d�d΄�Z�e8dσd�dф�Z�e8d�dӃd�dՄ�Z�d�dׄZ�dS)�a�Handling of the new bundle2 format

The goal of bundle2 is to act as an atomically packet to transmit a set of
payloads in an application agnostic way. It consist in a sequence of "parts"
that will be handed to and processed by the application layer.


General format architecture
===========================

The format is architectured as follow

 - magic string
 - stream level parameters
 - payload parts (any number)
 - end of stream marker.

the Binary format
============================

All numbers are unsigned and big-endian.

stream level parameters
------------------------

Binary format is as follow

:params size: int32

  The total number of Bytes used by the parameters

:params value: arbitrary number of Bytes

  A blob of `params size` containing the serialized version of all stream level
  parameters.

  The blob contains a space separated list of parameters. Parameters with value
  are stored in the form `<name>=<value>`. Both name and value are urlquoted.

  Empty name are obviously forbidden.

  Name MUST start with a letter. If this first letter is lower case, the
  parameter is advisory and can be safely ignored. However when the first
  letter is capital, the parameter is mandatory and the bundling process MUST
  stop if he is not able to proceed it.

  Stream parameters use a simple textual format for two main reasons:

  - Stream level parameters should remain simple and we want to discourage any
    crazy usage.
  - Textual data allow easy human inspection of a bundle2 header in case of
    troubles.

  Any Applicative level options MUST go into a bundle2 part instead.

Payload part
------------------------

Binary format is as follow

:header size: int32

  The total number of Bytes used by the part header. When the header is empty
  (size = 0) this is interpreted as the end of stream marker.

:header:

    The header defines how to interpret the part. It contains two piece of
    data: the part type, and the part parameters.

    The part type is used to route an application level handler, that can
    interpret payload.

    Part parameters are passed to the application level handler.  They are
    meant to convey information that will help the application level object to
    interpret the part payload.

    The binary format of the header is has follow

    :typesize: (one byte)

    :parttype: alphanumerical part name (restricted to [a-zA-Z0-9_:-]*)

    :partid: A 32bits integer (unique in the bundle) that can be used to refer
             to this part.

    :parameters:

        Part's parameter may have arbitrary content, the binary structure is::

            <mandatory-count><advisory-count><param-sizes><param-data>

        :mandatory-count: 1 byte, number of mandatory parameters

        :advisory-count:  1 byte, number of advisory parameters

        :param-sizes:

            N couple of bytes, where N is the total number of parameters. Each
            couple contains (<size-of-key>, <size-of-value) for one parameter.

        :param-data:

            A blob of bytes from which each parameter key and value can be
            retrieved using the list of size couples stored in the previous
            field.

            Mandatory parameters comes first, then the advisory ones.

            Each parameter's key MUST be unique within the part.

:payload:

    payload is a series of `<chunksize><chunkdata>`.

    `chunksize` is an int32, `chunkdata` are plain bytes (as much as
    `chunksize` says)` The payload part is concluded by a zero size chunk.

    The current implementation always produces either zero or one chunk.
    This is an implementation limitation that will ultimately be lifted.

    `chunksize` can be negative to trigger special case processing. No such
    processing is in place yet.

Bundle processing
============================

Each part is processed in order using a "part handler". Handler are registered
for a certain part type.

The matching of a part to its handler is case insensitive. The case of the
part type is used to know if a part is mandatory or advisory. If the Part type
contains any uppercase char it is considered mandatory. When no handler is
known for a Mandatory part, the process is aborted and an exception is raised.
If the part is advisory and no handler is known, the part is ignored. When the
process is aborted, the full bundle is still read from the stream to keep the
channel usable. But none of the part read from an abort are processed. In the
future, dropping the stream may become an option for channel we do not care to
preserve.
�)�absolute_import�divisionN�)�_)�hex�short)�	bookmarks�changegroup�encoding�error�obsolete�phases�pushkey�pycompat�requirements�scmutil�streamclone�tags�url�util)�
stringutil�urlutil)�
repositorys>is>Bs>Is>BB��s[^a-zA-Z0-9_:-]cCs|�dd�r|�d|�dS)z(debug regarding output stream (bundling)�devel�
bundle2.debugsbundle2-output: %s
N��
configbool�debug��ui�message�r"�7/usr/lib64/python3.9/site-packages/mercurial/bundle2.py�outdebug�sr$cCs|�dd�r|�d|�dS)z"debug on input stream (unbundling)rrsbundle2-input: %s
Nrrr"r"r#�indebug�sr%cCst�|�rt|��dS)z9raise ValueError if a parttype contains invalid characterN)�_parttypeforbidden�search�
ValueError��parttyper"r"r#�validateparttype�s
r+cCsdd|S)z�return a struct format to read part parameter sizes

    The number parameters is variable so we need to build that format
    dynamically.
    �>sBBr")Znbparamsr"r"r#�_makefpartparamsizes�sr-r"cst����fdd�}|S)z�decorator that register a function as a bundle2 part handler

    eg::

        @parthandler('myparttype', ('mandatory', 'param', 'handled'))
        def myparttypehandler(...):
            '''process a part of type "my part".'''
            ...
    cs���}|t|<t��|_|S�N)�lower�parthandlermapping�	frozenset�params)�funcZ	lparttype�r2r*r"r#�
_decorator�s
zparthandler.<locals>._decorator)r+)r*r2r5r"r4r#�parthandler�s
r6c@sNeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
e
ZdS)�unbundlerecordsa�keep record of what happens during and unbundle

    New records are added using `records.add('cat', obj)`. Where 'cat' is a
    category of record and obj is an arbitrary object.

    `records['cat']` will return all entries of this category 'cat'.

    Iterating on the object itself will yield `('category', obj)` tuples
    for all entries.

    All iterations happens in chronological order.
    cCsi|_g|_i|_dSr.)�_categories�
_sequences�_replies��selfr"r"r#�__init__
szunbundlerecords.__init__NcCsB|j�|g��|�|j�||f�|dur>|�|��||�dS)z�add a new record of a given category.

        The entry can then be retrieved in the list returned by
        self['category'].N)r8�
setdefault�appendr9�
getreplies�add)r<�category�entryZ	inreplytor"r"r#rAszunbundlerecords.addcCs|j�|t��S)z3get the records that are replies to a specific part)r:r>r7)r<�partidr"r"r#r@szunbundlerecords.getrepliescCst|j�|d��S)Nr")�tupler8�get)r<�catr"r"r#�__getitem__ szunbundlerecords.__getitem__cCs
t|j�Sr.)�iterr9r;r"r"r#�__iter__#szunbundlerecords.__iter__cCs
t|j�Sr.)�lenr9r;r"r"r#�__len__&szunbundlerecords.__len__cCs
t|j�Sr.)�boolr9r;r"r"r#�__nonzero__)szunbundlerecords.__nonzero__)N)�__name__�
__module__�__qualname__�__doc__r=rAr@rHrJrLrN�__bool__r"r"r"r#r7�s


r7c@s*eZdZdZddd�Zdd�Zdd	�Zd
S)�bundleoperationaPan object that represents a single bundling process

    Its purpose is to carry unbundle-related objects and states.

    A new object should be created at the beginning of each bundle processing.
    The object is to be returned by the processing function.

    The object has very little content now it will ultimately contain:
    * an access to the repo the bundle is applied to,
    * a ui object,
    * a way to retrieve a transaction to add changes to the repo,
    * a way to record the result of processing each part,
    * a way to construct a bundle response when applicable.
    T�cCs>||_|j|_t�|_d|_||_i|_||_i|_||_	dSr.)
�repor r7�records�reply�
captureoutput�hookargs�_gettransaction�modes�source)r<rV�transactiongetterrYr]r"r"r#r=?szbundleoperation.__init__cCs.|��}|jr$|j�|j�|j|_d|_|Sr.)r[rZ�update)r<Ztransactionr"r"r#�gettransactionKszbundleoperation.gettransactioncCs$|jdurt�d��|j�|�dS)Ns@attempted to add hookargs to operation after transaction started)rZr�ProgrammingErrorr_)r<rZr"r"r#�addhookargsZs

�zbundleoperation.addhookargsN)TrU)rOrPrQrRr=r`rbr"r"r"r#rT/s
rTc@seZdZdS)�TransactionUnavailableN)rOrPrQr"r"r"r#rccsrccCs
t��dS)z�default method to get a transaction while processing a bundle

    Raise an exception to highlight the fact that no transaction was expected
    to be createdN�rcr"r"r"r#�_notransactiongsrecs�t|t�rdd�jd<|dur0d�jvr0|�jd<|durLd�jvrL|�jd<t||�fdd�|d�St|�fdd�|d�}t||�||fi|��|SdS)	N�1�bundle2ssource�urlcs�Sr.r"r"��trr"r#�<lambda>wrUzapplybundle.<locals>.<lambda>�r]cs�Sr.r"r"rir"r#rkzrU)�
isinstance�
unbundle20rZ�
processbundlerT�_processchangegroup)rV�	unbundlerrjr]r�kwargs�opr"rir#�applybundleos



rtc@s$eZdZdd�Zdd�Zdd�ZdS)�partiteratorcCs(||_||_||_d|_d|_d|_dS)Nr)rVrsrq�iterator�count�current)r<rVrsrqr"r"r#r=�szpartiterator.__init__cs�fdd�}|��_�jS)Nc3sBt�j��d�}|D](\}}|�_|�_|V|��d�_qdS)Nr)�	enumeraterq�	iterpartsrwrx�consume)�itrrw�pr;r"r#r3�sz$partiterator.__enter__.<locals>.func)rv)r<r3r"r;r#�	__enter__�s	zpartiterator.__enter__cCs�|js
dSt|t�r�d}z(|jr*|j��|jD]}|��q0WntyVd}Yn0d|_g}d}|jjdur�|jj��}|jjj	}||_
||_|r�|�|jj
�d|j�dS)NFTs%bundle2-input-bundle: %i parts total
)rvrm�	Exceptionrxr{Zduringunbundle2rsrX�
salvageoutput�capabilitiesZ
_replycapsZ_bundle2salvagedoutputrVr rrw)r<�type�exc�tbZ	seekerror�part�salvagedZ	replycapsr"r"r#�__exit__�s0




�zpartiterator.__exit__N)rOrPrQr=r~r�r"r"r"r#rus
rurUcCs�|dur"|durt}t|||d�}|j|jjr�dg}|jrP|�dt|j��|jdusd|jturp|�d�n
|�d�|�d�|j�d�	|��t
|||�|S)	a,This function process a bundle, apply effect to/from a repo

    It iterates over each part then searches for and uses the proper handling
    code to process the part. Parts are processed in order.

    Unknown Mandatory part will abort the process.

    It is temporarily possible to provide a prebuilt bundleoperation to the
    function. This is used to ensure output is properly propagated in case of
    an error during the unbundling. This output capturing part will likely be
    reworked and this ability will probably go away in the process.
    Nrlsbundle2-input-bundle:s
 %i paramss no-transactions with-transaction�
rU)rerTr2r �	debugflagr?rKr[r�join�processparts)rVrqr^rsr]�msgr"r"r#ro�s 


rocCsDt|||��$}|D]}t||�qWd�n1s60YdSr.)ru�_processpart)rVrsrq�partsr�r"r"r#r��sr�cKs0|j|j|||fi|��}|j�dd|i�|S)N�changegroup�return)ZapplyrVrWrA)rs�cgrjr]rrr�retr"r"r#rp�s��rpc	Cs�d}�zz~t�|j�}|dur0d}tj|jd��t|jd|j�|j|j}|r�t	|�}|�
�dd�|�}tj|j|d��d}Wn�tj�yp}z�|jr��t|jd	|�WYd}~W|jj
�rdd
|jg}|js�|�d�t|j�}t|j�|}|�s|�rD|�d�|�r&|�d
|�|�r:|�d|�|�d�|�d|�|j�d�|��dSd}~00W|jj
�r�d
|jg}|j�s�|�d�t|j�}t|j�|}|�s�|�r�|�d�|�r�|�d
|�|�r�|�d|�|�d�|�d|�|j�d�|��n�|jj
�r�d
|jg}|j�sF|�d�t|j�}t|j�|}|�sj|�r�|�d�|�r�|�d
|�|�r�|�d|�|�d�|�d|�|j�d�|��0|S)Nsunknownsunsupported-typer)sfound a handler for part %ssunsupported-params (%s)s, )r*r2s	supporteds%ignoring unsupported advisory part %ssbundle2-input-part: "%s"� (advisory)�	 (params:�
 %i mandatory� %i advisory�)s %s
rU)r0rFr�r�BundleUnknownFeatureErrorr%r �
mandatorykeysr2�list�sortr��	mandatoryr�r?rKr)	rsr��status�handlerZ
unknownparamsr�r��nbmp�nbapr"r"r#�_gethandler�s��




�




�




r�cCs�t||�}|durdSd}|jr>|jdur>|jjddd�d}zN|||�W|dur^|j��}|r�|jjd|dd�}|jdt�	|j
�dd	�nB|dur�|j��}|r�|jjd|dd�}|jdt�	|j
�dd	�0dS)
z�process a single part from a bundle

    The part is guaranteed to have been fully consumed when the function exits
    (even if an exception is raised).NT)rZsubprocrU�outputF��datar��in-reply-to�r�)r�rYrXr Z
pushbufferZ	popbuffer�newpart�addparamr�bytestr�id)rsr�r��outputZoutpartr"r"r#r�&s.

��
�r�cCsji}|��D]X}|sqd|vr*|d}}n|�dd�\}}|�d�}t�|�}dd�|D�}|||<q|S)z�decode a bundle2 caps bytes blob into a dictionary

    The blob is a list of capabilities (one per line)
    Capabilities may have values using a line of the form::

        capability=value1,value2,value3

    The values are always a list.�=r"r�,cSsg|]}t�|��qSr"��urlreq�unquote��.0�vr"r"r#�
<listcomp>VrUzdecodecaps.<locals>.<listcomp>)�
splitlines�splitr�r�)Zblob�caps�line�key�valsr"r"r#�
decodecapsCs	


r�cCs\g}t|�D]D}||}t�|�}dd�|D�}|rFd|d�|�f}|�|�qd�|�S)z2encode a bundle2 caps dictionary into a bytes blobcSsg|]}t�|��qSr")r��quoter�r"r"r#r�arUzencodecaps.<locals>.<listcomp>�%s=%sr�r�)�sortedr�r�r�r?)r��chunks�car�r"r"r#�
encodecaps[s
r�)rU�UN)�HG10UNr�)�HG10sBZ)�HG10GZsGZ)rU�HG20r��HG10BZr�)r�r�r�c@sneZdZdZdZddd�Zddd�Zed	d
��Zddd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�bundle20z�represent an outgoing bundle2 container

    Use the `addparam` method to add stream level parameter. and `newpart` to
    populate it. Then call `getchunks` to retrieve all the binary chunks of
    data that compose the bundle2 container.r�r"cCs:||_g|_g|_t|�|_tj�d�|_d|_	d|_
dS)Nr�T)r �_params�_parts�dictr�r�compengines�
forbundletype�_compengine�	_compopts�prefercompressed)r<r r�r"r"r#r=s
zbundle20.__init__NcCs0|dvrdS|�d|�tj�|�|_||_dS)z$setup core part compression to <alg>)Nr�NsCompression)r�rr�r�r�r�)r<Zalg�compoptsr"r"r#�setcompression�s
zbundle20.setcompressioncCs
t|j�S)z*total number of parts added to the bundler)rKr�r;r"r"r#�nbparts�szbundle20.nbpartscCsH|st�d��|dd�t�tj�vr4t�d|��|j�||f�dS)zadd a stream level parametersempty parameter namerrsnon letter first character: %sN)rrarr��string�
ascii_lettersr�r?)r<�name�valuer"r"r#r��s
��zbundle20.addparamcCst|j�|_|j�|�dS)z_add a new part to the bundle2 container

        Parts contains the actual applicative payload.N)rKr�r�r?)r<r�r"r"r#�addpart�szbundle20.addpartcOs$t|g|�Ri|��}|�|�|S)aqcreate a new part and add it to the containers

        As the part is directly added to the containers. For now, this means
        that any failure to properly initialize the part after calling
        ``newpart`` should result in a failure of the whole bundling process.

        You can still fall back to manually create and add if you need better
        control.)�
bundlepartr�)r<Ztypeid�argsrrr�r"r"r#r��s	
zbundle20.newpartccs�|jjrTd|jg}|jr.|�dt|j��|�dt|j��|j�d�|��t	|jd|j�|jV|�
�}t	|jd|�ttt|��V|r�|V|j
�|��|j�D]
}|Vq�dS)Nsbundle2-output-bundle: "%s",s (%i params)s %i parts total
rUsstart emission of %s streamsbundle parameter: %s)r r��_magicstringr�r?rKr�rr�r$�_paramchunk�_pack�_fstreamparamsizer��compressstream�
_getcorechunkr�)r<r��param�chunkr"r"r#�	getchunks�s"
�zbundle20.getchunkscCsPg}|jD]:\}}t�|�}|dur:t�|�}d||f}|�|�q
d�|�S)z1return a encoded version of all stream parametersNr�� )r�r�r�r?r�)r<ZblocksZparr�r"r"r#r��s

zbundle20._paramchunkccs`t|jd�|jD]0}t|jd|j�|j|jd�D]
}|Vq6qt|jd�ttd�VdS)zUyield chunk for the core part of the bundle

        (all but headers and parameters)sstart of partssbundle part: "%s"�r s
end of bundlerN)r$r r�r�r�r��_fpartheadersize)r<r�r�r"r"r#r��s

zbundle20._getcorechunkcCs.g}|jD]}|j�d�r
|�|���q
|S)z�return a list with a copy of all output parts in the bundle

        This is meant to be used during error handling to make sure we preserve
        server outputr�)r�r��
startswithr?�copy)r<r�r�r"r"r#r��s

zbundle20.salvageoutput)r")N)N)rOrPrQrRr�r=r��propertyr�r�r�r�r�r�r�r�r"r"r"r#r�vs

	

r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
unpackermixinz6A mixin to extract bytes and struct data from a streamcCs
||_dSr.)�_fp)r<�fpr"r"r#r=�szunpackermixin.__init__cCs|�t�|��}t||�S)aunpack this struct format from the stream

        This method is meant for internal usage by the bundle2 protocol only.
        They directly manipulate the low level stream including bundle2 level
        instruction.

        Do not use it to implement higher-level logic or methods.)�
_readexact�struct�calcsize�_unpack�r<�formatr�r"r"r#r��szunpackermixin._unpackcCst�|j|�S)aread exactly <size> bytes from the stream

        This method is meant for internal usage by the bundle2 protocol only.
        They directly manipulate the low level stream including bundle2 level
        instruction.

        Do not use it to implement higher-level logic or methods.)r	�readexactlyr�)r<�sizer"r"r#r�szunpackermixin._readexactN)rOrPrQrRr=r�r�r"r"r"r#r��sr�cCs�|durt�|d�}|dd�|dd�}}|dkrV|�d||f�t�td���t�|�}|durzt�td�|��|||�}t|d	|�|S)
z7return a valid unbundler object for a given magicstringN�r�sHGs6error: invalid magic: %r (version %r), should be 'HG'
snot a Mercurial bundlesunknown bundle version %ssstart processing of %s stream)	r	r�rr�Abortr�	formatmaprFr%)r r�Zmagicstring�magic�versionZunbundlerclassrqr"r"r#�getunbundlers ��

r�csleZdZdZdZ�fdd�Zejdd��Zdd�Z	d	d
�Z
dd�Zddd�Zdd�Z
dd�Zdd�Z�ZS)rnz|interpret a bundle2 stream

    This class is fed with a binary stream and yields parts through its
    `iterparts` methods.r�cs.||_tj�d�|_d|_tt|��|�dS)z<If header is specified, we do not read it out of the stream.r�N)	r rr�r�r��_compressed�superrnr=�r<r r���	__class__r"r#r=)szunbundle20.__init__cCsPt|jd�i}|�t�d}|dkr4t�d|��|rL|�|�}|�|�}|S)z%dictionary of stream level parameterss!reading bundle2 stream parametersr�negative bundle param size: %i)r%r r�r�r�BundleValueErrorr��_processallparams)r<r2�
paramssizer"r"r#r20s�

zunbundle20.paramscCsft��}|�d�D]N}|�dd�}dd�|D�}t|�dkrF|�d�|j|�|d||d<q|S)	� r�r�rcSsg|]}t�|��qSr"r�)r��ir"r"r#r�DrUz0unbundle20._processallparams.<locals>.<listcomp>r�Nr)r�sortdictr�rKr?�
_processparam)r<Zparamsblockr2r}r"r"r#r?s

zunbundle20._processallparamscCs�|std��|dd�t�tj�vr0td|��zt|��}WnBty�|dd���rpt	|j
d|�ntj|fd��Yn0||||�dS)a�process a parameter, applying its effect if needed

        Parameter starting with a lower case letter are advisory and will be
        ignored when unknown.  Those starting with an upper case letter are
        mandatory and will this function will raise a KeyError when unknown.

        Note: no option are currently supported. Any input will be either
              ignored or failing.
        zempty parameter namerrznon letter first character: %ssignoring unknown parameter %s)r2N)
r(rr�r�r��b2streamparamsmapr/�KeyError�islowerr%r rr�)r<r�r�r�r"r"r#rKs
�zunbundle20._processparamc	cs,|jV|�t�d}|dkr,t�d|��|r�|�|�}|�|�g}|�d�D]*}|�dd�\}}|��dkrR|�	|�qRd�
|�}ttt|��V|Vntt|�V|j
�|j�|_d}|dk�r(|�t�d}tt|�V|r�d}n
|d7}q�|tk�rq�n|dk�rt�d��|�|�Vq�d	S)
aWutility to transfer a bundle2 as binary

        This is made necessary by the fact the 'getbundle' command over 'ssh'
        have no way to know then the reply end, relying on the bundle to be
        interpreted to know its end. This is terrible and we are sorry, but we
        needed to move forward to get general delta enabled.
        rrr�r�r�compressionr�snegative chunk size: %iN)r�r�r�rrr�rr�r/r?r�r�rKr��decompressorreaderr�r��
flaginterrupt)	r<rr2Z	outparamsr}�kr�Z
emptycountr�r"r"r#�_forwardchunkses@�






zunbundle20._forwardchunksFccsv|rtnt}|j|j�|j�|_t|jd�|��}|durf||j||j�}|V|�	�|��}q6t|jd�dS)z'yield all parts contained in the streams!start extraction of bundle2 partsNsend of bundle2 stream)
�seekableunbundlepart�unbundlepartr2r�r
r�r%r �_readpartheaderr{)r<�seekable�cls�headerblockr�r"r"r#rz�s
zunbundle20.iterpartscCsF|�t�d}|dkr$t�d|��t|jd|�|rB|�|�SdS)�Qreads a part header size and return the bytes blob

        returns None if emptyr�negative part header size: %ispart header size: %iN�r�r�rrr%r r��r<�
headersizer"r"r#r�s�
zunbundle20._readpartheadercCs|j|jSr.)r2r�r;r"r"r#�
compressed�szunbundle20.compressedcCst�|jd�r|j��SdS)zclose underlying file�closeN)r�safehasattrr�rr;r"r"r#r�szunbundle20.close)F)rOrPrQrRr�r=rZ
propertycacher2rrrrzrrr�
__classcell__r"r"r�r#rn!s
1
rns20cs�fdd�}|S)z/register a handler for a stream level parametercs|t�<|Sr.)r	)r3�r�r"r#�	decorator�sz'b2streamparamhandler.<locals>.decoratorr")r�r!r"r r#�b2streamparamhandler�sr"rcCs>|tjjvrtj|f|fd��tj�|�|_|dur:d|_dS)z<read compression parameter and install payload decompression)r2�valuesNT)rr��supportedbundletypesrr�r�r�r�)rqr�r�r"r"r#�processcompression�s
r%c@sveZdZdZddd�Zdd�Zd	d
�Zedd��Zej	d
d��Zedd��Z
edd��Zddd�Zdd�Z
dd�ZdS)r�aA bundle2 part contains application level payload

    The part `type` is used to route the part to the application level
    handler.

    The part payload is contained in ``part.data``. It could be raw bytes or a
    generator of byte chunks.

    You can add parameters to the part using the ``addparam`` method.
    Parameters can be either mandatory (default) or advisory. Remote side
    should be able to safely ignore the advisory ones.

    Both data and parameters cannot be modified after the generation has begun.
    r"rUTcCs�t|�d|_||_||_t|�|_t|�|_t�|_|j|jD],\}}||jvrbt	�
d|��|j�|�qBd|_||_
dS)N�duplicated params: %s)r+r�r��_datar��_mandatoryparams�_advisoryparams�set�_seenparamsrrarA�
_generatedr�)r<r*�mandatoryparams�advisoryparamsr�r�Zpname�__r"r"r#r=�s


zbundlepart.__init__cCs0d|jj|jjf}d|t|�|j|j|jfS)Nz%s.%sz2<%s object at %x; id: %s; type: %s; mandatory: %s>)rrPrOr�r�r�)r<rr"r"r#�__repr__s�zbundlepart.__repr__cCs|�|j|j|j|j|j�S)z�return a copy of the part

        The new part have the very same content but no partid assigned yet.
        Parts with generated data cannot be copied.)rr�r(r)r'r�r;r"r"r#r�s�zbundlepart.copycCs|jSr.)r'r;r"r"r#r�szbundlepart.datacCs|jdurt�d��||_dS)N�part is being generated)r,r�ReadOnlyPartErrorr')r<r�r"r"r#r�#s

cCs
t|j�Sr.)rEr(r;r"r"r#r-)szbundlepart.mandatoryparamscCs
t|j�Sr.)rEr)r;r"r"r#r..szbundlepart.advisoryparamscCsX|jdurt�d��||jvr*td|��|j�|�|j}|rF|j}|�||f�dS)z�add a parameter to the part

        If 'mandatory' is set to True, the remote handler must claim support
        for this parameter or the unbundling will be aborted.

        The 'name' and 'value' cannot exceed 255 bytes each.
        Nr1r&)	r,rr2r+r(rAr)r(r?)r<r�r�r�r2r"r"r#r�3s


zbundlepart.addparamc
cs�|jdurt�d��d|_|jr�d|jg}|js<|�d�t|j�}t|j	�}|sX|r�|�d�|rt|�d|�|r�|�d|�|�d�|j
s�|�d	�n<t�|j
d
�s�t�|j
d�r�|�d�n|�d
t|j
��|�d�|�
d�|��|j�r|j��}n
|j��}t|dt�|j�|f�ttt|��|tt|j�g}|j}|j	}|�ttt|�t|���g}	|D]&\}
}|	�t|
��|	�t|���qz|D]&\}
}|	�t|
��|	�t|���q�ttt|	�d�g|	�R�}|�|�|D]\}
}|�|
�|�|��q�|D]\}
}|�|
�|�|��qzd�|�}
Wn t�yjtd|��Yn0t|dt|
��ttt|
��V|
Vz<|��D].}t|dt|��ttt|��V|V�q�Wn�t�y�|�
d��Yn�t�y�}z�t �!|�}|�
d|�t"�#�d}d|}t$dd|fgdd�}d|_ttd�V|j%|d�D]}|V�q^t|d�ttd�Vt�&||�WYd}~n
d}~00t|d�ttd�Vd|_dS) Nspart can only be consumed onceFsbundle2-output-part: "%s"r�r�r�r�r�s empty payload�next�__next__s streamed payloads %i bytes payloadr�rUs
part %s: "%s"r�z8Found a non-bytes trying to build bundle part header: %rsheader chunk size: %i�payload chunk size: %isbundle2-generatorexit
s5bundle2-input-stream-interrupt: encoding exception %ssunexpected error: %s�error:abort�messager�r���r�sclosing payload chunkT)'r,rrar�r�r�r?rKr-r.r�rrrr��upperr/r$rr�r�r��_fparttypesize�_fpartid�_fpartparamcountr-�	TypeErrorr��_payloadchunks�
_fpayloadsize�
GeneratorExit�
BaseExceptionrZforcebytestr�sys�exc_infor�r�Zraisewithtb)r<r r�r�r�r*�headerZmanparZadvparZparsizesr�r��
paramsizesZheaderchunkr�r�Zbexcr�Z	interpartr"r"r#r�Fs�






�


�


��


��

"
zbundlepart.getchunksccs`t�|jd�st�|jd�rJt�|j�}|�t�}|r\|V|�t�}q2nt|j�r\|jVdS)zmyield chunks of a the part payload

        Exists to handle the different methods to provide data to a part.r3r4N)rrr��chunkbuffer�read�preferedchunksizerK)r<Zbuffr�r"r"r#r>�s�

zbundlepart._payloadchunksN)r"r"rUT)rUT)rOrPrQrRr=r0r�r�r��setterr-r.r�r�r>r"r"r"r#r��s&�






nr�r8cs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�interrupthandlerz�read one part and process it with restricted capability

    This allows to transmit exception raised on the producer size during part
    iteration while the consumer is reading a part.

    Part processed in this manner only have access to a ui object,cstt|��|�||_dSr.)r�rJr=r r�r�r"r#r=�szinterrupthandler.__init__cCsF|�t�d}|dkr$t�d|��t|jd|�|rB|�|�SdS)rrrspart header size: %i
Nrrr"r"r#r�s�
z interrupthandler._readpartheaderc	Cs�|j�d�t|jd�|��}|dur8t|jd�dSt|j||j�}t|j�}d}z<zt||�Wntt	fy�d}�Yn0W|s�|�
�n|s�|�
�0|j�d�dS)Ns<bundle2-input-stream-interrupt: opening out of band context
s0bundle2 stream interruption, looking for a part.s"no part found during interruption.FTs<bundle2-input-stream-interrupt: closing out of band context
)r rr%rrr��interruptoperationr��
SystemExit�KeyboardInterruptr{)r<rr�rsZ	hardabortr"r"r#�__call__�s.�


�
�zinterrupthandler.__call__)rOrPrQrRr=rrNrr"r"r�r#rJ�srJc@s,eZdZdZdd�Zedd��Zdd�ZdS)	rKzpA limited operation to be use by part handler during interruption

    It only have access to an ui object.
    cCs||_d|_d|_dS)NF)r rXrY)r<r r"r"r#r=szinterruptoperation.__init__cCst�d��dS�Ns'no repo access from stream interruption)rrar;r"r"r#rVszinterruptoperation.repocCstd��dSrOrdr;r"r"r#r`sz!interruptoperation.gettransactionN)rOrPrQrRr=r�rVr`r"r"r"r#rK�s

rKccs|�dd�}|j}t�t�}|j}|j}tj}|j	}||||��d}	t
|d|	�|	�r|	dkr�||	�}
t|
�|	kr�t�
td�t|
�|	f��|
Vn$|	tkr�t||��nt�d|	��||�}
t|
�|kr�t�
td�t|
�|	f��||
�d}	|rT|d|	�qTdS)	z�Reads bundle2 part payload data into chunks.

    Part payload data consists of framed chunks. This function takes
    a file handle and emits those chunks.
    rrrr5s6stream ended unexpectedly  (got %d bytes, expected %d)snegative payload chunk size: %ss&bundle2-input: payload chunk size: %i
N)rrr��Structr?r��unpackr	r�rGr%rKrr�rrrJr)r ZfhZdologrZheaderstructrrQr�rGZ	chunksize�sr"r"r#�decodepayloadchunkssH
�
���
��rScsZeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�Z�ZS)rz a bundle part read from a bundlecs�tt|��|�t�|d�o&t�|d�|_||_||_d|_d|_	d|_
d|_d|_d|_
d|_d|_d|_|��d|_d|_dS)N�seekstellrFr")r�rr=rr�	_seekabler �_headerdata�
_headeroffset�_initialized�consumedr�r�r-r.r2r��_readheaderZ
_mandatory�_pos�r<r rDr�r�r"r#r=Ks$�zunbundlepart.__init__cCs&|j}|j|||�}|||_|S)z+return the next <size> byte from the header)rWrV)r<r��offsetr�r"r"r#�_fromheaderas
zunbundlepart._fromheadercCs|�t�|��}t||�S)zaread given format from header

        This automatically compute the size of the format to read.)r^r�r�r�r�r"r"r#�
_unpackheaderhszunbundlepart._unpackheadercCsHt|�|_t|�|_t�|j�|_|j�|j�tdd�|D��|_dS)z7internal function to setup all logic related parameterscss|]}|dVqdS)rNr")r�r}r"r"r#�	<genexpr>wrUz+unbundlepart._initparams.<locals>.<genexpr>N)	rEr-r.rrr2r_r1r�)r<r-r.r"r"r#�_initparamsos


zunbundlepart._initparamscCsd|�t�d}|�|�|_t|jd|j�|�t�d|_t|jdt�	|j��|j|j�
�k|_|j�
�|_|�t�\}}t|jd||�t
||�}|�|�}tt|ddd�|ddd���}|d|�}||d�}g}|D]"\}	}
|�|�|	�|�|
�f�q�g}|D]$\}	}
|�|�|	�|�|
�f��q|�||�t�|���|_d|_dS)	z$read the header and setup the objectrspart type: "%s"s
part id: "%s"spart parameters: %iNr�rT)r_r:r^r�r%r r;r�rr�r/r�r<r-r��zipr?rarrFr>�_payloadstreamrX)r<ZtypesizeZmancountZadvcountZfparamsizesrEZmansizesZadvsizesZ	manparamsr�r�Z	advparamsr"r"r#rZys.
"zunbundlepart._readheadercCst|j|j�S)z+Generator of decoded chunks in the payload.)rSr r�r;r"r"r#r>�szunbundlepart._payloadchunkscCs:|jr
dS|�d�}|r6|jt|�7_|�d�}qdS)z�Read the part payload until completion.

        By consuming the part data, the underlying stream read offset will
        be advanced to the next part (or end of stream).
        Nr)rYrGr[rK)r<r�r"r"r#r{�s
zunbundlepart.consumeNcCs||js|��|dur"|j��}n|j�|�}|jt|�7_|dusTt|�|krx|jsr|jrr|j�d|j�d|_|S)zread payload dataNs*bundle2-input-part: total payload size %i
T)	rXrZrcrGr[rKrYr r)r<r�r�r"r"r#rG�s�zunbundlepart.read)N)
rOrPrQrRr=r^r_rarZr>r{rGrr"r"r�r#rHs
#rcsZeZdZdZ�fdd�Zddd�Zdd�Zd	d
�Zej	fdd�Z
dd
d�Zdd�Z�Z
S)ra�A bundle2 part in a bundle that is seekable.

    Regular ``unbundlepart`` instances can only be read once. This class
    extends ``unbundlepart`` to enable bi-directional seeking within the
    part.

    Bundle2 part data consists of framed chunks. Offsets when seeking
    refer to the decoded data, not the offsets in the underlying bundle2
    stream.

    To facilitate quickly seeking within the decoded data, instances of this
    class maintain a mapping between offsets in the underlying stream and
    the decoded payload. This mapping will consume memory in proportion
    to the number of chunks within the payload (which almost certainly
    increases in proportion with the size of the part).
    csg|_tt|��|||�dSr.)�_chunkindexr�rr=r\r�r"r#r=�szseekableunbundlepart.__init__rccs�t|j�dkr$|j�d|��f�n|�|j|d�|j|d}t|j|j�D]@}|d7}|t|�7}|t|j�kr�|j�||��f�|VqTdS)z/seek to specified chunk and start yielding datarrN)rKrdr?�_tellfp�_seekfprSr r�)r<Zchunknum�posr�r"r"r#r>�sz#seekableunbundlepart._payloadchunkscCsbt|j�D]J\}\}}||kr*|dfS||kr
|d||j|ddfSq
td��dS)z>for a given payload position, return a chunk number and offsetrrs
Unknown chunkN)ryrdr()r<rgr�ZpposZfposr"r"r#�
_findchunk�s$zseekableunbundlepart._findchunkcCs|jSr.)r[r;r"r"r#�tell�szseekableunbundlepart.tellcCs(|tjkr|}nb|tjkr&|j|}nL|tjkrd|jsP|�d�}|rP|�d�}q@|jdd|}ntd|f��||jddkr�|js�|�d�}|r�|�d�}q�d|kr�|jddks�ntd��|j|k�r$|�	|�\}}t
�|�|��|_
|�|�}t|�|k�rt�td���||_dS)Nrr8rsUnknown whence value: %ri�sOffset out of rangesSeek failed
)�os�SEEK_SET�SEEK_CURr[�SEEK_ENDrYrGrdr(rhrrFr>rcrKrr�r)r<r]�whenceZnewposr�ZinternaloffsetZadjustr"r"r#rT�s0




 
zseekableunbundlepart.seekcCs$|jr|j�||�Sttd���dS)amove the underlying file pointer

        This method is meant for internal usage by the bundle2 protocol only.
        They directly manipulate the low level stream including bundle2 level
        instruction.

        Do not use it to implement higher-level logic or methods.sFile pointer is not seekableN)rUr�rT�NotImplementedErrorr)r<r]rnr"r"r#rfszseekableunbundlepart._seekfpc
CsR|jrNz|j��WStyL}z"|jtjkr6d|_n�WYd}~n
d}~00dS)a,return the file offset, or None if file is not seekable

        This method is meant for internal usage by the bundle2 protocol only.
        They directly manipulate the low level stream including bundle2 level
        instruction.

        Do not use it to implement higher-level logic or methods.FN)rUr�ri�IOError�errnoZESPIPE)r<�er"r"r#re&szseekableunbundlepart._tellfp)r)r)rOrPrQrRr=r>rhrirjrkrTrfrerr"r"r�r#r�s
	 

r)sabortsunsupportedcontents	pushraced�pushkey)shttpshttps)sheads)sv2)
r��	bookmarksserror�listkeysrs�digests�remote-changegroup�hgtagsfnodes�phases�streamFcCs�|dvrt�d��t��}ttt�|���|d<t�	|tj
�rZtdd�tjD��}||d<|rfd|d<|j�
d	d
�}|dkr�d|d
<d|j�dd�vr�|�d�|d	kr�|jjd	ddd�}|j�d	d�}|r�|s�|�d�|S)a_return the bundle2 capabilities for a given repo

    Exists to allow extensions (like evolution) to mutate the capabilities.

    The returned value is used for servers advertising their capabilities as
    well as clients advertising their capabilities to servers as part of
    bundle2 requests. The ``role`` argument specifies which is which.
    )sclient�servers&role argument must be client or serverr�css|]}d|VqdS)sV%iNr"r�r"r"r#r`ZrUzgetrepocaps.<locals>.<genexpr>�
obsmarkersr"spushbackr{sconcurrent-push-modes
check-related)srelateds
checkheadsryrslegacy.exchangesuncompressedT)Z	untrustedsbundle2.streamrz)rrar�r�rEr�r	Zsupportedincomingversionsr�	isenabledZexchangeopt�formatsr �configZ
configlist�popr)rVZ
allowpushbackZroler�ZsupportedformatZcpmodeZstreamsupportedZfeaturesupportedr"r"r#�getrepocapsIs0	
�
�
r�cCs2|�d�}|s|dkriSt�|�d��}t|�S)z0return the bundle capabilities of a peer as dictrgrU)�capabler�r�r�)�remote�rawZcapsblobr"r"r#�bundle2capsvs

r�cCs|�dd�}dd�|D�S)zIextract the list of supported obsmarkers versions from a bundle2caps dictr|r"cSs&g|]}|�d�rt|dd���qS)�VrN)r��int�r��cr"r"r#r��rUz%obsmarkersversion.<locals>.<listcomp>�rF)r�Zobscapsr"r"r#�obsmarkersversionsr�c
	Cs�|�d�r0t�||d|�}
t||
|||||	d�S|�d�sHt�d|��i}d|vr\d|d<t||�}|�||	�t||||||�|�	�}
tj
||
||d	�S)
Nr��01)�vfs�compressionr�r�sunknown bundle type: %s�obsolescence)sV1r|�r�)r�r	�makechangegroup�writebundlerrar�r��_addpartsfromoptsr��writechunks)r rVr]�filename�
bundletype�outgoing�optsr�r�r�r�r��bundle�	chunkiterr"r"r#�writenewbundle�s*
�	

r�cCsx|�dd�r�|�d�}|dur(t�|�}t�||||�}|jd|��d�}|�d|j�d|jvr||jdd|jdd	d
�|�d�r�|�	d|j
�r�|jd
dtjd	d
�t
j|jvr�|�dd�|�dd	�r�t||dd�|�dd�r�t|||�|�dd��rt|||�|�dd	��r@|j�|j�}	t||	|�dd�d
�|�dd	��rtt�||j�}
t�|
�}|jd|d�dS)Nr�Ts
cg.version�r��version�clcount�	nbchanges�%dFr�rys%ln and secret()�targetphase�exp-sidedatarfsstreamv2)�streamstagsfnodescachesrevbranchcacher�sobsolescence-mandatory�phase-heads)rFr	Zsafeversionr�r�r�r�r��extras�revs�ancestorsofr
Zsecretr�REPO_FEATURE_SIDE_DATA�features�addpartbundlestream2�addparttagsfnodescache�addpartrevbranchcache�obsstoreZrelevantmarkers�missing�buildobsmarkerspartZsubsetphaseheadsZbinaryencode)r rV�bundlerr]r�r��	cgversionr�r�Z
obsmarkers�headsbyphaseZ	phasedatar"r"r#r��sH



���
�
r�cCsZt�|���}g}|jD]$}|j|dd�}|r|�||g�q|rV|jdd�|�d�dS)NF)ZcomputemissingrxrUr�)r�hgtagsfnodescache�
unfilteredr�Zgetfnode�extendr�r�)rVr�r��cacher��node�fnoder"r"r#r��s
r�c	st|��}|��j}t�dd���|jD]*}|�|�|��\}}�||�|�q&�fdd�}|j	d|�dd�dS)NcSst�t�fSr.)r*r"r"r"r#rk�rUz'addpartrevbranchcache.<locals>.<lambda>c3srt����D]`\}\}}t�|�}t�t|�t|�t|��V|Vt|�D]
}|VqLt|�D]
}|Vq`qdSr.)r��itemsr
Z	fromlocal�	rbcstruct�packrK)�branch�nodes�closedZ
utf8branch�n�Zbranchesdatar"r#�generates
z'addpartrevbranchcache.<locals>.generate�cache:rev-branch-cacheFr�)
Zrevbranchcacher��	changelog�collections�defaultdictr�Z
branchinfo�revrAr�)	rVr�r�r��clr�r�rr�r"r�r#r��s


r�cCs"dd�|D�}t�d�t|���S)NcSsg|]}|dkr|�qS)ssharedr")r�Zreqr"r"r#r�rUz+_formatrequirementsspec.<locals>.<listcomp>r�)r�r�r�r�)rr"r"r#�_formatrequirementsspecsr�cCst|�}dt�d�|f}|S)Ns%s%ss
requirements=)r�r�r�)rr2r"r"r#�_formatrequirementsparamssr�cCs(d}|jr$d�dd�t|j�D��}|S)z\Formats a repo's wanted sidedata categories into a bytestring for
    capabilities exchange.rUr�css|]}t�|�VqdSr.)rr�r�r"r"r#r`sz0format_remote_wanted_sidedata.<locals>.<genexpr>)Z_wanted_sidedatar�r�)rV�wantedr"r"r#�format_remote_wanted_sidedatas
�r�cCs|�d�}t|�S)N�exp-wanted-sidedata)r��read_wanted_sidedata)r��sidedata_categoriesr"r"r#�read_remote_wanted_sidedata%s
r�cCs|rt|�d��St�S)Nr�)r*r�)�	formattedr"r"r#r�*sr�c
Ks|�dd�sdSt�|�s0tjtd�td�d��d|_|�d�}|�d�}|j�dd	�}|s`|rr|srt�td
���d}|j	r�t
|j�}|s�t�td���n|j	j|vr�d}t�
||||�\}}	}
t�|�}t|�}|jd
|
d�}|jdd|	dd�|jdd|dd�|jd|dd�dS)Nr�Fs<stream data requested but server does not allow this featuresrwell-behaved clients should not be requesting stream data from servers not advertising it; the client may be buggy��hint�includepats�excludepats�experimentalsserver.stream-narrow-cloness,server does not support narrow stream clonessPserver has obsolescence markers, but client cannot receive them via stream cloneT�stream2r��	bytecountr�r��	filecount�requirements)rFrZallowservergenerationrr�rr�r rr�r�r�Z_versionZ
generatev2Zstreamed_requirementsr�r�r�)
r�rVrrr�r�ZnarrowstreamZincludeobsmarkers�remoteversions�	filecount�	bytecount�itrr�r"r"r#r�0sN
���

�
���

r�TcCsL|sdSt|j�}t�|�}|dur,td��tj|d|d�}|jd||d�S)z�add an obsmarker part to the bundler with <markers>

    No part is created if markers is empty.
    Raises ValueError if the bundler doesn't support any known obsmarker format.
    Ns0bundler does not support common obsmarker formatT)r�r|r�)r�r�rZ
commonversionr(Z
encodemarkersr�)r�Zmarkersr�r�r�r�r"r"r#r�is

r�cs�|dkrjt|�}|�|��|jd���d�}|�d�j�d�jvr`|jdd�jddd	�|��}	nf�jd
kr�t�t	d���t
|\�}
|
tjj
vr�t�t	d�|
��tj�|
������fd
d�}	|	�}	tj||	||d�S)z�Write a bundle file and return its filename.

    Existing files will not be overwritten.
    If no filename is specified, a temporary file is created.
    bz2 compression can be turned off.
    The bundle file will be deleted in case of errors.
    r�r�r�r�r�r�r�Fr�r�s.old bundle types only supports v1 changegroupss#unknown stream compression type: %sc3s&�V�������D]
}|VqdSr.)r�r�)r��r�Z
compenginer�rDr"r#r��szwritebundle.<locals>.chunkiterr�)r�r�r�r�r�r�r�rr�r�bundletypesrr�r$r�r	r�)r r�r�r�r�r�r�r�r�r��compr"r�r#r�zs*
�

�r�cCs�dd�|jdD�}d}d}|D]>}|dkr4d}q`|dkrJ||d7}q |dkr ||d7}q |dkrrd|}n|dkr�d|}|S)z:logic to combine 0 or more addchangegroup results into onecSsg|]}|�dd��qS)r�rr�)r��rr"r"r#r��rUz-combinechangegroupresults.<locals>.<listcomp>r�rrr8)rW)rs�resultsZchangedheads�resultr�r"r"r#�combinechangegroupresults�s 
r�r�)r�r�r�r��treemanifestr�cCsdddlm}|��}|j�dd�}t�||d�}d}d|jvrNt|j�d��}d|jvr�t�	|j
�s�t|j
j�dkr�t
�td	���|j
j�tj�|�|j
j|j
j|j
j�|j
j_t�|j
�i}|j�d
�}|dur�t|�|d<|j�d�}	t|	�|d
<t||||jdfd|i|��}
|jdu�r`|jjddd�}|jdt� |j!�dd�|jdd|
dd�dS)z$apply a changegroup part on the repor)�	localrepor�r�Nr�r�rs[bundle contains tree manifests, but local repo is non-empty and does not use tree manifestsr��targetphaser�r�rgZ
expectedtotal�reply:changegroupFr�r�r��%i)"�r�r`r2rFr	r�r�r�istreemanifestrVrKr�rr�rrrAZTREEMANIFEST_REQUIREMENTZresolvestorevfsoptionsr r�Zsvfs�optionsZwritereporequirementsr�rpr]rXr�r�rr�r�)rs�inpartr�rjZunpackerversionr�ZnbchangesetsZextrakwargsr�Zremote_sidedatar�r�r"r"r#�handlechangegroup�sV

���
���	�r�)rh�sizervcCsg|]}d|�qS)�	digest:%sr")r�rr"r"r#r�rUr�rwc
Cs.z|jd}Wn$ty2t�td�d��Yn0t�|�}|jtdvr`t�td�|j��zt	|jd�}WnFt
y�t�td�d��Yn$ty�t�td�d��Yn0i}|j�dd���D]J}d	|}z|j|}Wn&t�yt�td�|��Yn0|||<q�t
�t�|j|�||�}	|��}
d
dlm}|�|jj|	|�}t|tj��s�t�td�t�|���t|||
|jd
�}
|jdu�r�|j�d�}|jdt� |j!�dd�|jdd|
dd�z|	�"�WnFtj�y(}z*t�td�t�|�|j#f��WYd}~n
d}~00dS)a�apply a bundle10 on the repo, given an url and validation information

    All the information about the remote bundle to import are given as
    parameters. The parameters include:
      - url: the url to the bundle10.
      - size: the bundle10 file size. It is used to validate what was
        retrieved by the client matches the server knowledge about the bundle.
      - digests: a space separated list of the digest types provided as
        parameters.
      - digest:<digest-type>: the hexadecimal representation of the digest with
        that name. Like the size, it is used to validate what was retrieved by
        the client matches what the server knows about the bundle.

    When multiple digest types are given, all of them are checked.
    rhs&remote-changegroup: missing "%s" paramrws+remote-changegroup does not support %s urlsr�s0remote-changegroup: invalid value for param "%s"rvrUr�r)�exchanges%s: not a bundle version 1.0rgNr�r�Fr�r�r�sbundle at %s is corrupted:
%s)$r2r
rr�rrr�schemer�r�r(rFr�rZ
digestchecker�openr r`r�r�Z
readbundlerVrmr	Zcg1unpackerZhidepasswordrpr]rXr�r�rr�r�Zvalidater!)rsr�Zraw_urlZ
parsed_urlr�Zdigests�typr�r�Z	real_partrjr�r�r�r�rrr"r"r#�handleremotechangegroupsn
��
�
�

�

����r�r�)r�r�cCs4t|jd�}t|jd�}|j�dd|i|�dS)Nr�r�r��r�r2rWrA)rsr�r�Zreplytor"r"r#�handlereplychangegroupSsr�scheck:bookmarksc
Cs�t�|j|�}d}d}d}|D]r\}}|jj�|�}||kr|durV||t|�f}	n0|durp||t|�f}	n||t|�t|�f}	t�|	��qdS)z�check location of bookmarks

    This part is to be used to detect push race regarding bookmark, it
    contains binary encoded (bookmark, node) tuple. If the local state does
    not marks the one in the part, a PushRaced exception is raised
    s]remote repository changed while pushing - please try again (bookmark "%s" move from %s to %s)sbremote repository changed while pushing - please try again (bookmark "%s" is missing, expected %s)sfremote repository changed while pushing - please try again (bookmark "%s" set on %s, expected missing)N)r�binarydecoderV�
_bookmarksrFrr�	PushRaced)
rsr�ZbookdataZmsgstandardZ
msgmissingZmsgexist�bookr�Zcurrentnode�finalmsgr"r"r#�handlecheckbookmarksZs(����r�scheck:headscCsj|�d�}g}t|�dkr0|�|�|�d�}q|j�dd�rF|��t|�t|j���krft	�
d��dS)z�check that head of the repo did not change

    This is used to detect a push race when using unbundle.
    This replaces the "heads" argument of unbundle.�r��bundle2lazylocking�:remote repository changed while pushing - please try againN)rGrKr?r rr`r�rV�headsrr�)rsr��hrr"r"r#�handlecheckheads�s

�rscheck:updated-headscCs�|�d�}g}t|�dkr0|�|�|�d�}q|j�dd�rF|��t�}|j���	�D]}|�
|�qZ|D]}||vrnt�d��qndS)aNcheck for race on the heads touched by a push

    This is similar to 'check:heads' but focus on the heads actually updated
    during the push. If other activities happen on unrelated heads, it is
    ignored.

    This allow server with high traffic to avoid push contention as long as
    unrelated parts of the graph are involved.r�r�r�rN)
rGrKr?r rr`r*rVZ	branchmapZ	iterheadsr_rr�)rsr�rrZcurrentheadsZlsr"r"r#�handlecheckupdatedheads�s


�rscheck:phasescCs�t�|�}|j��}|j}|j}d}t�|�D]T\}}|D]F}	|�||�	|	��}
|
|kr:|t
|	�tj|
tj|f}t�
|��q:q.dS)zjcheck that phase boundaries of the repository did not change

    This is used to detect a push race.
    sQremote repository changed while pushing - please try again (%s is %s expected %s)N)r
r�rVr�r�Z_phasecacherZ	iteritemsZphaser�rZ
phasenamesrr�)rsr�ZphasetonodesZunfir�Z
phasecacher�Z
expectedphaser�r�Zactualphaser�r"r"r#�handlecheckphases�s 

��rr�cCs*|����D]}|j�td�|�qdS)z3forward output captured on the server to the clientsremote: %s
N)rGr�r r�r)rsr�r�r"r"r#�handleoutput�srs	replycapscCs(t|���}|jdur$t|j|�|_dS)zqNotify that a reply bundle should be created

    The payload contains the capabilities information for the replyN)r�rGrXr�r )rsr�r�r"r"r#�handlereplycaps�s
rc@seZdZdZdS)�
AbortFromPartz=Sub-class of Abort that denotes an error from a bundle2 part.N)rOrPrQrRr"r"r"r#r�srr6)r7�hintcCst|jd|j�d�d��dS)z*Used to transmit abort error over the wirer7r	r�N)rr2rF�rsr�r"r"r#�handleerrorabort�s�rs
error:pushkey)�	namespace�key�new�old�retr�cCsLi}dD] }|j�|�}|dur|||<qtj|jdfit�|����dS)z=Used to transmit failure of a mandatory pushkey over the wire�rr
rrrNr�)r2rFr�
PushkeyFailedr�	strkwargs)rsr�rrr�r�r"r"r#�handleerrorpushkey�s
��rserror:unsupportedcontent)�parttype�paramscCs\i}|j�d�}|dur ||d<|j�d�}|durB|�d�|d<tjfit�|����dS)z4Used to transmit unknown content error over the wirerNr�)r2rFr�rr�rr)rsr�rrr*r2r"r"r#�handleerrorunsupportedcontent�srserror:pushraced)r7cCst�td�|jd��dS)z.Used to transmit push race error over the wirespush failed:r7N)rZ
ResponseErrorrr2r
r"r"r#�handleerrorpushraced
	srru)rcCs.|jd}t�|���}|j�d||f�dS)z6retrieve pushkey namespace content stored in a bundle2rruN)r2rZ
decodekeysrGrWrA)rsr��	namespacer�r"r"r#�handlelistkeys	s
rrs�rr
rrcCstj}||jd�}||jd�}||jd�}||jd�}|j�dd�rT|��|j�||||�}||||d�}|j�d|�|j	d	ur�|j	�
d
�}	|	jdt�
|j�dd
�|	jdd|dd
�|j�r|�si}
dD]}||jvr�|j||
|<q�tjfdd|jit�|
����d	S)zprocess a pushkey requestrr
rrr�r�rrsN�
reply:pushkeyr�Fr�r�r�rrDr�)r�decoder2r rr`rVrWrArXr�r�rr�r�r�rrr)rsr�Zdecrr��old�newr��record�rpartrrr"r"r#�
handlepushkey	s4
�
��r#rtc
s�t��j|�}�jj�dd�}�j�dd�}|dk�r>���}�jj}|r�g�|D]`\}}|j	�
�}	d|	d<d|	d<||	d<t|�|d	��|	d
<t|dur�|nd	�|	d<��|	�qR�D] }	�jj
dddit�|	���q�|D](\}}t�|�r�td�|}
t�|
��q�|��j���|�|�r���fdd�}�j�|�nB|dk�rr|D]"\}}||d�}�j�d|��qLnt�d|��dS)adtransmit bookmark information

    The part contains binary encoded bookmark information.

    The exact behavior of this part can be controlled by the 'bookmarks' mode
    on the bundle operation.

    When mode is 'apply' (the default) the bookmark information is applied as
    is to the unbundling repository. Make sure a 'check:bookmarks' part is
    issued earlier to check for push races in such update. This behavior is
    suitable for pushing.

    When mode is 'records', the information is recorded into the 'bookmarks'
    records of the bundle operation. This behavior is suitable for pulling.
    r{sbookmarks-pushkey-compatrtsapplyrfs
pushkeycompatrr
rUrNr�
prepushkey�throwTs$cannot accept divergent bookmark %s!cs&�D]}�jjdit�|���qdS)Nrs)rs)rV�hookrr)Zunused_successrZ�Zallhooksrsr"r#�runhookk	szhandlebookmark.<locals>.runhooksrecords)sbookmarksnodesunknown bookmark mode: %s)r$)rr�rVr rr\rFr`r�rZr�rr?r&rrZisdivergentrrr�ZapplychangesZ
_afterlockrWrAra)
rsr�ZchangesZ
pushkeycompatZ
bookmarksmoderjZ	bookstorer�r�rZr�r(r!r"r'r#�handlebookmark7	sR�

���


�r)r�cCs$t�|�}t�|j��|j|�dS)z%apply phases from bundle part to repoN)r
r�ZupdatephasesrVr�r`)rsr�r�r"r"r#�handlephases{	s
r*rcCs4t|jd�}t|jd�}|j�dd|i|�dS)�(retrieve the result of a pushkey requestr�r�rsNr��rsr�r�rDr"r"r#�handlepushkeyreply�	sr-r|cCs�|��}|��}|j�dd�r2|j�dt|��|jsT|jjj	rT|jj�
d�dS|jj�||�}|j��|j
�dd|i�|jdur�|j�d�}|jd	t�|j�d
d�|jdd|d
d�dS)
z&add a stream of obsmarkers to the repor�sobsmarkers-exchange-debugs&obsmarker-exchange: %i bytes received
s3ignoring obsolescence markers, feature not enabled
Nr|r�reply:obsmarkersr�Fr�r�)r`rGr rZwritenoi18nrKr�rVr��readonlyrZmergemarkersZinvalidatevolatilesetsrWrArXr�r�rr�r�)rsr�rjZ
markerdatar r"r"r"r#�handleobsmarker�	s(
��

�r0r.)rr�cCs4t|jd�}t|jd�}|j�dd|i|�dS)r+rr�r|Nr�r,r"r"r#�handleobsmarkerreply�	sr1rxcCs�|j�dd�r|��t�|j���}d}|�d�}|�d�}t|�dksVt|�dkrd|j�	d�qz|�
||�|d7}q*|��|j�	d|�dS)	z|Applies .hgtags fnodes cache entries to the local repo.

    Payload is pairs of 20 byte changeset nodes and filenodes.
    r�r�rr�s1ignoring incomplete received .hgtags fnodes data
rs'applied %i hgtags fnodes cache entries
N)r rr`rr�rVr�rGrKrZsetfnode�write)rsr�r�rwr�r�r"r"r#�handlehgtagsfnodes�	s


r3s>IIIr�cCsdS)z�Legacy part, ignored for compatibility with bundles from or
    for Mercurial before 5.7. Newer Mercurial computes the cache
    efficiently enough during unbundling that the additional transfer
    is unnecessary.Nr"r
r"r"r#�	handlerbc�	sr4spushvarscCsH|j�dd�rDi}|jD] \}}|��}d|}|||<q|�|�dS)z5unbundle a bundle2 containing shellvars on the serverspushspushvars.serversUSERVAR_N)r rr.r9rb)rsr�rZr�r�r"r"r#�bundle2getvars�	s
r5r�)r�r�r�cCs�t�|jd�}|r|�d�ng}t|jd�}t|jd�}|j}t|�r^td�}t�	|��|j
�d�t�
|||||�dS)Nr�r�r�r�s1cannot apply stream clone to non empty repositorysapplying stream bundle
)r�r�r2r�r�rVrKrrr�r rrZ
applybundlev2)rsr�rr�r�rVr�r"r"r#�handlestreamv2bundle�	s
r6cCs�t�}|j}	|�d|�D]}
|�|	�|
��q|r�tj|||||d�}|j|jht	|�dddd�}|j
d|d�}
|
�d|�t�
|�r�|
�d	d
�tj|jvr�|
�dd
�t|�}|
�d|�|S)
aKgenerates bundle2 for widening a narrow clone

    bundler is the bundle to which data should be added
    repo is the localrepository instance
    oldmatcher matches what the client already has
    newmatcher matches what the client needs (including what it already has)
    common is set of common heads between server and client
    known is a set of revs known on the client side (used in ellipses)
    cgversion is the changegroup version to send
    ellipses is boolean value telling whether to send ellipses data or not

    returns bundle2 of the data required for extending
    s::%ln)�
oldmatcherZmatcherZ	fullnodesFsnarrow_widen)r�r�r�r�r�rfr�r�)r*r�r�rAr�r	Z
getbundlerr�Znullidr�r�r�rr�rr�r�r�)r�rVr7Z
newmatcher�commonZknownr�ZellipsesZcommonnodesr�r�ZpackerZcgdatar�r�r"r"r#�widen_bundle�	s8��
r9)r")N)NNrU)N)FN)NNN)T)NNN)�rRZ
__future__rrr�rqrj�rer�r�rBZi18nrr�rrr�rr	r
rrr
rrrrrrrrZutilsrrZ
interfacesrZurlerrr�r�r�rQr�r�r�r:r;r?r<rH�compiler&r$r%r+r-r0r6�objectr7rT�RuntimeErrorrcrertruror�rpr�r�r�r�r�Zbundlepriorityr�r�r�rnr�r	r"r%r�rrJrKrSrrrEr�ZDIGESTS�keysr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Z_remotechangegroupparamsr�r�r�rrrrrr�rrrrrrr#r)r*r-r0r1r3rPr�r4r5r6r9r"r"r"r#�<module>sF@
	
04
G
%*�|
!
	l48x|�
-	�
%59
�
-�
7��
N

%




	
�






C










Youez - 2016 - github.com/yon3zu
LinuXploit