
    6hVj                   8   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr  SSKJrJr  SSKJrJrJrJrJrJrJrJrJrJrJrJrJrJr  SSKJ r J!r!  SS	K"J#r#  \
RH                  (       a$  SS
K
J%r%J&r&J'r'J(r(J)r)J*r*  \%\+\*\'\+   \)\+S4   4   4   r,\RZ                  r-\R\                  r.\R^                  r0\Rb                  r2Sr3Sr4Sr5Sr6Sr7Sr8Sr9\Rt                  " S5      r;S r<S r=S r>S r?0 r@SS jrA " S S5      rB " S S5      rC " S S\D5      rES rFSS jrG " S  S!5      rH    SS" jrIS# rJS$ rKS% rLS& rMSS( jrNS) rOS*SS+S,S-S..rP/ S/QrQ " S0 S15      rR " S2 S35      rSSS4 jrT " S5 S6\S5      rUS7\U0rV0 rWS8 rX\X" S95      S: 5       rY " S; S<5      rZS=r[ " S> S?\S5      r\ " S@ SA5      r]SB r^ " SC SD\S5      r_ " SE SF\_5      r`SSSGSS\a" \b" \R                  R                  5       5      5      SHSSISJSK.
reS'\fSL'   SSSM jjrgSSN jrhSSO jri    SSP jrjSQ rkSR rlSS rmST rnSU roSV rpSW rqSX rrSY rsSSZ jrt SS[ jruS\ rv\A" S]S^5      S_ 5       rw\a" / S`Q\R                  R                  5        V s/ s H  n SaU -  PM
     sn -   5      rx\A" Sb\x5      Sc 5       ry\A" SdSe5      Sf 5       rz\A" Sg5      Sh 5       r{\A" Si5      Sj 5       r|\A" Sk5      Sl 5       r}\A" Sm5      Sn 5       r~\A" So5      Sp 5       r\A" Sq5      Sr 5       r " Ss St\GR                  5      r\A" SuSv5      Sw 5       r\A" SxSy5      Sz 5       r\A" S{S|5      S} 5       r\A" S~S5      S 5       r\A" SS5      S 5       r\A" SS5      S 5       r\A" S5      S 5       r\A" S5      S 5       r\A" SSe5      S 5       r\A" S5      S 5       r\A" SS5      S 5       r\A" S5      S 5       r\GR                  " S5      r\A" S5      S 5       r\A" S5      S 5       r\A" SS5      S 5       r\A" SS5      S 5       rS rgs  sn f )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.
    )annotationsN   )_)hexshort)	bookmarkschangegroupencodingerrorobsoletephasespushkeypycompatrequirementsscmutilstreamclonetagsurlutil)
stringutilurlutil)
repository)DictIteratorListOptionalTupleUnion.s   >is   >Bs   >Is   >BB   s   [^a-zA-Z0-9_:-]c                \    U R                  SS5      (       a  U R                  SU-  5        gg)z(debug regarding output stream (bundling)   devel   bundle2.debugs   bundle2-output: %s
N
configbooldebuguimessages     3/usr/lib/python3/dist-packages/mercurial/bundle2.pyoutdebugr*      s+    	}}X/00
(723 1    c                \    U R                  SS5      (       a  U R                  SU-  5        gg)z"debug on input stream (unbundling)r!   r"   s   bundle2-input: %s
Nr#   r&   s     r)   indebugr-      s+    	}}X/00
''12 1r+   c                N    [         R                  U 5      (       a  [        U 5      eg)z9raise ValueError if a parttype contains invalid characterN)_parttypeforbiddensearch
ValueErrorparttypes    r)   validateparttyper4      s#      **"" +r+   c                    SSU -  -   $ )zreturn a struct format to read part parameter sizes

The number parameters is variable so we need to build that format
dynamically.
   >s   BB )nbparamss    r)   _makefpartparamsizesr9      s     58#$$r+   r7   c                .   ^ ^ [        T 5        UU 4S jnU$ )zdecorator that register a function as a bundle2 part handler

eg::

    @parthandler('myparttype', ('mandatory', 'param', 'handled'))
    def myparttypehandler(...):
        '''process a part of type "my part".'''
        ...
c                r   > TR                  5       nU[        ;  d   eU [        U'   [        T5      U l        U $ N)lowerparthandlermapping	frozensetparams)func	lparttyper@   r3   s     r)   
_decoratorparthandler.<locals>._decorator  s:    NN$	 2222(,9%'r+   )r4   )r3   r@   rC   s   `` r)   parthandlerrE      s     X r+   c                  J    \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 r\rSrg)unbundlerecordsi  au  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.
c                .    0 U l         / U l        0 U l        g r<   )_categories
_sequences_repliesselfs    r)   __init__unbundlerecords.__init__  s    r+   Nc                    U R                   R                  U/ 5      R                  U5        U R                  R                  X45        Ub!  U R	                  U5      R                  X5        gg)zpadd a new record of a given category.

The entry can then be retrieved in the list returned by
self['category'].N)rI   
setdefaultappendrJ   
getrepliesadd)rM   categoryentry	inreplytos       r)   rT   unbundlerecords.add  s\    
 	##Hb188?01 OOI&**8; !r+   c                J    U R                   R                  U[        5       5      $ )z3get the records that are replies to a specific part)rK   rQ   rG   )rM   partids     r)   rS   unbundlerecords.getreplies)  s    }}''0ABBr+   c                L    [        U R                  R                  US5      5      $ )Nr7   )tuplerI   get)rM   cats     r)   __getitem__unbundlerecords.__getitem__-  s     T%%))#r233r+   c                ,    [        U R                  5      $ r<   )iterrJ   rL   s    r)   __iter__unbundlerecords.__iter__0      DOO$$r+   c                ,    [        U R                  5      $ r<   )lenrJ   rL   s    r)   __len__unbundlerecords.__len__3  s    4??##r+   c                ,    [        U R                  5      $ r<   )boolrJ   rL   s    r)   __nonzero__unbundlerecords.__nonzero__6  rf   r+   )rI   rK   rJ   r<   )__name__
__module____qualname____firstlineno____doc__rN   rT   rS   r`   rd   ri   rm   __bool____static_attributes__r7   r+   r)   rG   rG     s2    
<C4%$% Hr+   rG   c                  4    \ rS rSrSr   SS jrS rS rSrg)	bundleoperationi<  a(  an 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.
Nc                    Xl         XPl        UR                  U l        [        5       U l        S U l        X0l        0 U l        X l        0 U l	        X@l
        g r<   )reporemoter'   rG   recordsreplycaptureoutputhookargs_gettransactionmodessource)rM   ry   transactiongetterr}   r   rz   s         r)   rN   bundleoperation.__init__L  sI     	''&(
*0
r+   c                    U R                  5       nU R                  (       a6  U R                  R                  UR                  5        U R                  Ul        S U l        U$ r<   )r   r~   update)rM   transactions     r)   gettransactionbundleoperation.gettransactiona  sL    **,== MM  !5!56#'==K  r+   c                    U R                   c  [        R                  " S5      eU R                   R                  U5        g )Ns@   attempted to add hookargs to operation after transaction started)r~   r   ProgrammingErrorr   )rM   r~   s     r)   addhookargsbundleoperation.addhookargsp  s8    == ((7  	X&r+   )
r   r}   r~   r   r{   rz   r|   ry   r   r'   )Tr+   N)	ro   rp   rq   rr   rs   rN   r   r   ru   r7   r+   r)   rw   rw   <  s!    & *'r+   rw   c                      \ rS rSrSrg)TransactionUnavailableiy  r7   N)ro   rp   rq   rr   ru   r7   r+   r)   r   r   y  s    r+   r   c                     [        5       e)zdefault method to get a transaction while processing a bundle

Raise an exception to highlight the fact that no transaction was expected
to be createdr   r7   r+   r)   _notransactionr   }  s    
 !
""r+   c                0  ^ [        U[        5      (       ab  STR                  S'   Ub  STR                  ;  a  UTR                  S'   Ub  STR                  ;  a  UTR                  S'   [        XU4S jX5S9$ [	        U U4S jX5S9n[        XqTX440 UD6  U$ )N   1   bundle2s   source   urlc                    > T $ r<   r7   trs   r)   <lambda>applybundle.<locals>.<lambda>  s    Rr+   r   rz   c                    > T $ r<   r7   r   s   r)   r   r     s    2r+   )
isinstance
unbundle20r~   processbundlerw   _processchangegroup)ry   	unbundlerr   r   r   rz   kwargsops     `     r)   applybundler     s    )Z(("&J)2;;">%+BKK	"?vR[[8"%BKKZ
 	

 T:fLB2vEfE	r+   c                  &    \ rS rSrS rS rS rSrg)partiteratori  c                R    Xl         X l        X0l        S U l        SU l        S U l        g )Nr   )ry   r   r   iteratorcountcurrent)rM   ry   r   r   s       r)   rN   partiterator.__init__  s&    	"
r+   c                @   ^  U 4S jnU" 5       T l         T R                   $ )Nc               3     >#    [        TR                  R                  5       S5      n U  H.  u  pUTl        UTl        Uv   UR                  5         S Tl        M0     g 7f)Nr   )	enumerater   	iterpartsr   r   consume)itrr   prM   s      r)   rA   $partiterator.__enter__.<locals>.func  sN     DNN446:C"
 		#  s   AA)r   )rM   rA   s   ` r)   	__enter__partiterator.__enter__  s    	$ }}r+   c                r   U R                   (       d  g [        U[        5      (       a  Sn U R                  (       a  U R                  R	                  5         U R                    H  nUR	                  5         M     SUl        / nS nU R                  R                  bD  U R                  R                  R                  5       nU R                  R                  R                  nXrl
        Xbl        U(       a  UeU R                  R                  R                  SU R                  -  5        g ! [         a    Sn Nf = f)NFTs%   bundle2-input-bundle: %i parts total
)r   r   	Exceptionr   r   duringunbundle2r   r|   salvageoutputcapabilities
_replycaps_bundle2salvagedoutputry   r'   r%   r   )rM   typeexctb	seekerrorpartsalvaged	replycapss           r)   __exit__partiterator.__exit__  s    }}
 c9%% I	!<<LL((* MMDLLN * #'CHIww}}(77==668 GGMM66	&N)1& 			5

B	
-  ! 	!s   AD' 'D65D6)r   r   r   r   ry   r   N)ro   rp   rq   rr   rN   r   r   ru   r7   r+   r)   r   r     s    .
r+   r   c                   Uc  Uc  [         n[        U UUUS9nUR                    U R                  R                  (       a  S/nUR                  (       a'  UR                  S[        UR                  5      -  5        UR                  b  UR                  [         L a  UR                  S5        OUR                  S5        UR                  S5        U R                  R                  SR                  U5      5        [        XU5        U$ )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.
r   s   bundle2-input-bundle:s
    %i paramss    no-transactions    with-transaction   
r+   )r   rw   r@   r'   	debugflagrR   rh   r   r%   joinprocessparts)ry   r   r   r   r   rz   msgs          r)   r   r     s    ( 
z$ .	
 ww'(JJ}s9+;+;'<<=%););~)MJJ)*JJ+,

5chhsm$9%Ir+   c                x    [        XU5       nU H  n[        X5        M     S S S 5        g ! , (       d  f       g = fr<   )r   _processpart)ry   r   r   partsr   s        r)   r   r     s,    	d		*eD"  
+	*	*s   +
9c                2   U R                   bL  U R                   R                  b5  U R                   R                  nUR                  5       nUR                  US'   UR                  " U R
                  X#U40 UD6nU R                  R                  SSU05        U$ )Ndelta_base_reuse_policy   changegroup   return)rz   pathcopydelta_reuse_policyapplyry   r{   rT   )r   cgr   r   r   r   remote_pathrets           r)   r   r     s    	yy!;iinn,7,J,J()
((277B
6v
6CJJNNs	
 Jr+   c                	   Sn [         R                  UR                  5      nUc   Sn[        R                  " UR                  S9e[        U R                  SUR                  -  5        UR                  UR                  -
  nU(       aN  [        U5      nUR                  5         SSR                  U5      -  n[        R                  " UR                  US9eSn U R                  R                  (       Ga  S
UR                  -  /nUR                  (       d  UR                  S5        [        UR                  5      n[        UR                  5      U-
  nU(       d  U(       aX  UR                  S5        U(       a  UR                  SU-  5        U(       a  UR                  SU-  5        UR                  S5        UR                  SU-  5        U R                  R!                  SR                  U5      5        U$ ! [        R                   GaU  nUR                  (       a  e [        U R                  S	U-  5         S nAU R                  R                  (       Ga  S
UR                  -  /nUR                  (       d  UR                  S5        [        UR                  5      n[        UR                  5      U-
  nU(       d  U(       aX  UR                  S5        U(       a  UR                  SU-  5        U(       a  UR                  SU-  5        UR                  S5        UR                  SU-  5        U R                  R!                  SR                  U5      5        g g S nAff = f! U R                  R                  (       Ga  S
UR                  -  /nUR                  (       d  UR                  S5        [        UR                  5      n[        UR                  5      U-
  nU(       d  U(       aX  UR                  S5        U(       a  UR                  SU-  5        U(       a  UR                  SU-  5        UR                  S5        UR                  SU-  5        U R                  R!                  SR                  U5      5        f f = f)Ns   unknowns   unsupported-typer2   s   found a handler for part %ss   unsupported-params (%s)s   , )r3   r@   s	   supporteds%   ignoring unsupported advisory part %ss   bundle2-input-part: "%s"    (advisory)	    (params:    %i mandatory    %i advisory   )s    %s
r+   )r>   r^   r   r   BundleUnknownFeatureErrorr-   r'   mandatorykeysr@   listsortr   	mandatoryr   rR   rh   r%   )	r   r   statushandlerunknownparamsr   r   nbmpnbaps	            r)   _gethandlerr   $  sP   F#'$((3?(F11499EE5		AB**W^^; /M /%**]2KKF11=   55???.:;C>>

>*t))*Dt{{#d*Dt

<(JJ/$67JJ56

4 JJx&()EEKK&N- ** >>?#EF55???.:;C>>

>*t))*Dt{{#d*Dt

<(JJ/$67JJ56

4 JJx&()EEKK&  55???.:;C>>

>*t))*Dt{{#d*Dt

<(JJ/$67JJ56

4 JJx&()EEKK& s+   CG; ;M%+M ;M(  M%%M( (D"R
c                r   [        X5      nUc  gSnU R                  (       a)  U R                  b  U R                  R	                  SSS9  Sn U" X5        Ub  U R                  R                  5       nU(       aK  U R                  R                  SUSS9nUR                  S[        R                  " UR                  5      SS	9  gg! Ub  U R                  R                  5       nU(       aK  U R                  R                  SUSS9nUR                  S[        R                  " UR                  5      SS	9  f f = f)
zprocess 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)r   subprocr+      outputFdatar      in-reply-tor   )r   r}   r|   r'   
pushbuffer	popbuffernewpartaddparamr   bytestrid)r   r   r   outputoutparts        r)   r   r   N  s    
 "#G F	BHH0
tT2	UU__&Fhh&&yv&OG 0 0 9U    UU__&Fhh&&yv&OG 0 0 9U   s   C A1D6Capabilitiesc                .   0 nU R                  5        Hy  nU(       d  M  SU;  a  USpCO%UR                  SS5      u  p4UR                  S5      n[        R                  U5      nU Vs/ s H  n[        R                  U5      PM     nnXAU'   M{     U$ s  snf )zdecode 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.   =r7   r      ,)
splitlinesspliturlrequnquote)blobcapslinekeyvalsvs         r)   
decodecapsr  k  s     D!tb

4+IC::d#DnnS!+/04aq!40S	 " K 1s   'Bc                .   / n[        U 5       Ho  nX   n[        R                  U5      nU Vs/ s H  n[        R                  U5      PM     nnU(       a  SUSR                  U5      4-  nUR	                  U5        Mq     SR                  U5      $ s  snf )z2encode a bundle2 caps dictionary into a bytes blob   %s=%sr   r   )sortedr   quoter   rR   )r  chunkscar  r  s        r)   
encodecapsr    s    FTlx\\")-.AQ.R411Bb  ::f	 /s   B)r+      UN)   HG10UNr  )   HG10s   BZ)   HG10GZs   GZ)r+      HG20r     HG10BZr  )r  r  r  c                  v    \ rS rSrSrSrSSS jjrSS jr\S 5       r	SS jr
S	 rS
 rSS jrS rS rS rSrg)bundle20i  zrepresent 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  Nc                    Uc  0 nXl         / U l        / U l        [        U5      U l        [
        R                  R                  S5      U l        S U l	        SU l
        g )Nr  T)r'   _params_partsdictr   r   compenginesforbundletype_compengine	_compoptsprefercompressed)rM   r'   r   s      r)   rN   bundle20.__init__  sW    L*.|*<++99%@ !%r+   c                    US;   a  g[        S U R                   5       5      (       a   eU R                  SU5        [        R                  R                  U5      U l        X l        g)z$setup core part compression to <alg>)Nr  Nc              3  L   #    U  H  u  pUR                  5       S :H  v   M     g7f)   compressionN)r=   ).0nr  s      r)   	<genexpr>*bundle20.setcompression.<locals>.<genexpr>  s     L|tqqwwyN2|s   "$s   Compression)anyr  r   r   r  r  r  r  )rM   algcompoptss      r)   setcompressionbundle20.setcompression  sT    -Lt||LLLLLnc*++99#>!r+   c                ,    [        U R                  5      $ )z*total number of parts added to the bundler)rh   r  rL   s    r)   nbpartsbundle20.nbparts  s     4;;r+   c                    U(       d  [         R                  " S5      eUSS [        R                  " [        R
                  5      ;  a  [         R                  " SU-  5      eU R                  R                  X45        g)zadd a stream level parameters   empty parameter namer   r   s   non letter first character: %sN)r   r   r   r   stringascii_lettersr  rR   )rM   namevalues      r)   r   bundle20.addparam  sn    (()@AA!9H,,  
 
 ((1D8  	TM*r+   c                    UR                   b   e[        U R                  5      Ul         U R                  R                  U5        g)zWadd a new part to the bundle2 container

Parts contains the actual applicative payload.N)r   rh   r  rR   rM   r   s     r)   addpartbundle20.addpart  s4     wwdkk"4 r+   c                F    [        U/UQ70 UD6nU R                  U5        U$ )aI  create 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.)
bundlepartr9  )rM   typeidargsr   r   s        r)   r   bundle20.newpart  s)     &24262Tr+   c              #    #    U R                   R                  (       a  SU R                  -  /nU R                  (       a'  UR	                  S[        U R                  5      -  5        UR	                  S[        U R                  5      -  5        U R                   R                  SR                  U5      5        [        U R                   SU R                  -  5        U R                  v   U R                  5       n[        U R                   SU-  5        [        [        [        U5      5      v   U(       a  Uv   U R                  R                  U R                  5       U R                   5       S h  vN   g  N7f)Ns   bundle2-output-bundle: "%s",s    (%i params)s    %i parts total
r+   s   start emission of %s streams   bundle parameter: %s)r'   r   _magicstringr  rR   rh   r  r%   r   r*   _paramchunk_pack_fstreamparamsizer  compressstream_getcorechunkr  )rM   r   params      r)   	getchunksbundle20.getchunks  s    772T5F5FFGC||

?S->>?JJ+c$++.>>?GGMM#((3-(84;L;LLM  "1E9:%s5z22K##22 $..
 	
 	
s   E,E6.E4/E6c                    / nU R                    HI  u  p#[        R                  U5      nUb  [        R                  U5      nSX#4-  nUR                  U5        MK     SR	                  U5      $ )z1return a encoded version of all stream parametersr
      )r  r   r  rR   r   )rM   blocksparr5  s       r)   rB  bundle20._paramchunk  sb    ,,JC,,s#C U+#-MM# ' yy  r+   c              #  :  #    [        U R                  S5        U R                   HG  n[        U R                  SUR                  -  5        UR	                  U R                  S9 Sh  vN   MI     [        U R                  S5        [        [        S5      v   g N17f)zMyield chunk for the core part of the bundle

(all but headers and parameters)s   start of partss   bundle part: "%s"r'   Ns   end of bundler   )r*   r'   r  r   rH  rC  _fpartheadersizer8  s     r)   rF  bundle20._getcorechunk  sx      	+,KKDTWW2TYY>?~~~111   	*+$a(( 2s   A%B'B(2Bc                    / nU R                    HD  nUR                  R                  S5      (       d  M%  UR                  UR	                  5       5        MF     U$ )zreturn 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   
startswithrR   r   )rM   r   r   s      r)   r   bundle20.salvageoutput  sE    
 KKDyy##I..		,   r+   )r  r  r  r  r   r   r'   r<   )r   zOptional[Capabilities])returnzIterator[bytes])ro   rp   rq   rr   rs   rA  rN   r,  propertyr/  r   r9  r   rH  rB  rF  r   ru   r7   r+   r)   r  r    sO    0 L%"    

+!
$	!	)	r+   r  c                  *    \ rS rSrSrS rS rS rSrg)unpackermixini  z6A mixin to extract bytes and struct data from a streamc                    Xl         g r<   _fp)rM   fps     r)   rN   unpackermixin.__init__  s    r+   c                b    U R                  [        R                  " U5      5      n[        X5      $ )zunpack 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rM   formatr   s      r)   rc  unpackermixin._unpack!  s&     vv67v$$r+   c                D    [         R                  " U R                  U5      $ )zread 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\  )rM   sizes     r)   r`  unpackermixin._readexact,  s     &&txx66r+   r[  N)	ro   rp   rq   rr   rs   rN   rc  r`  ru   r7   r+   r)   rY  rY    s    @	%7r+   rY  c                b   Uc  [         R                  " US5      nUSS USS pCUS:w  a4  U R                  SX44-  5        [        R                  " [        S5      5      e[        R                  U5      nUc"  [        R                  " [        S5      U-  5      eU" X5      n[        U SU-  5        U$ )	z7return a valid unbundler object for a given magicstring   r      s   HGs6   error: invalid magic: %r (version %r), should be 'HG'
s   not a Mercurial bundles   unknown bundle version %ss   start processing of %s stream)	r	   rh  r%   r   Abortr   	formatmapr^   r-   )r'   r]  magicstringmagicversionunbundlerclassr   s          r)   getunbundlerrt  7  s    !--b!4 1%{1Q'77~
F	
 kk!5677]]7+Nkk!89GCDDr&IB0;>?r+   c                     ^  \ rS rSrSrSrU 4S jr\R                  S 5       r	S r
S rS rSS	 jrS
 rS rS rSrU =r$ )r   iJ  ztinterpret a bundle2 stream

This class is fed with a binary stream and yields parts through its
`iterparts` methods.r  c                   > Xl         [        R                  R                  S5      U l        SU l        [        TU ]  U5        g)z<If header is specified, we do not read it out of the stream.r  N)r'   r   r  r  r  _compressedsuperrN   rM   r'   r]  	__class__s      r)   rN   unbundle20.__init__R  s6    ++99%@r+   c                    [        U R                  S5        0 nU R                  [        5      S   nUS:  a  [        R
                  " SU-  5      eU(       a"  U R                  U5      nU R                  U5      nU$ )z%dictionary of stream level parameterss!   reading bundle2 stream parametersr      negative bundle param size: %i)r-   r'   rc  rD  r   BundleValueErrorr`  _processallparams)rM   r@   
paramssizes      r)   r@   unbundle20.paramsY  sv     	=>\\"34Q7
>((1J>  __Z0F++F3Fr+   c                J   [         R                  " 5       nUR                  S5       Hs  nUR                  SS5      nU Vs/ s H  n[        R	                  U5      PM     nn[        U5      S:  a  UR                  S5        U R                  " U6   US   X#S   '   Mu     U$ s  snf ) rK  r   r   rm  Nr   )r   sortdictr   r   r  rh   rR   _processparam)rM   paramsblockr@   r   is        r)   r  unbundle20._processallparamsh  s    ""4(Aa A,-.Aq"AA.1vz"Q4FQ4L )  /s    B c                   U(       d  [        S5      eUSS [        R                  " [        R                  5      ;  a  [        SU-  5      e [
        UR                  5          nU" XU5        g! [         aI    USS R                  5       (       a  [        U R                  SU-  5         g[        R                  " U4S9ef = f)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.
zempty parameter namer   r   znon letter first character: %ss   ignoring unknown parameter %s)r@   N)r1   r   r   r2  r3  b2streamparamsmapr=   KeyErrorislowerr-   r'   r   r   )rM   r4  r5  r   s       r)   r  unbundle20._processparamt  s     344!9H,,  
 
 =DEE	''

5G D&  	FAay  ""!AD!HI55dWEE		Fs   A. .;C+Cc              #    #    U R                   v   S[        U 5      ;  d   eU R                  [        5      S   nUS:  a  [        R
                  " SU-  5      eU(       a  U R                  U5      nU R                  U5        / nUR                  S5       H>  nUR                  SS5      u  pVUR                  5       S:w  d  M-  UR                  U5        M@     SR                  U5      n[        [        [        U5      5      v   Uv   O[        [        U5      v   U R                  R                  U R                   5      U l        SnUS:  a  ["        [$        :X  d   eU R                  ["        5      S   n[        ["        U5      v   U(       a  SnOUS-  nMQ  U[&        :X  a  M]  US:  a  [        R
                  " S	5      eU R                  U5      v   US:  a  M  g
g
7f)a0  utility to transfer a bundle2 as binary

This is made necessary by the fact the 'getbundle' command over 'ssh'
have no way to know when the reply ends, 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.
r@   r   r}  rK  r   r   r$  rm  s   negative chunk size: %iN)rA  varsrc  rD  r   r~  r`  r  r   r=   rR   r   rC  rh   r  decompressorreaderr\  rQ  _fpayloadsizeflaginterrupt)	rM   r  r@   	outparamsr   kr  
emptycountri  s	            r)   _forwardchunksunbundle20._forwardchunks  s     tDz)))\\"34Q7
>((1J>  __Z0F""6* I\\$'wwtQ'779.$$Q' ( 		),I)3y>::O):66##66txx@ 
1n#}444<< 01!4D($//
a
}$,,-GHH//$'' 1ns   B<GDGGc              #    #    U(       a  [         O[        nU R                    U R                  R	                  U R
                  5      U l        [        U R                  S5        U R                  5       nUbF  U" U R                  X0R
                  5      nUv   UR                  5         U R                  5       nUb  MF  [        U R                  S5        g7f)z'yield all parts contained in the streams!   start extraction of bundle2 partsNs   end of bundle2 stream)
seekableunbundlepartunbundlepartr@   r  r  r\  r-   r'   _readpartheaderr   )rM   seekableclsheaderblockr   s        r)   r   unbundle20.iterparts  s     &."L##66txx@=>**,%twwXX6DJ LLN..0K % 	12s   B7C;Cc                    U R                  [        5      S   nUS:  a  [        R                  " SU-  5      e[	        U R
                  SU-  5        U(       a  U R                  U5      $ g)Ireads a part header size and return the bytes blob

returns None if emptyr      negative part header size: %is   part header size: %iNrc  rQ  r   r~  r-   r'   r`  rM   
headersizes     r)   r  unbundle20._readpartheader  se     \\"23A6
>((0:=  	0:=>??:..r+   c                2    U R                     U R                  $ r<   )r@   rw  rL   s    r)   
compressedunbundle20.compressed  s    r+   c                n    [        U R                  S5      (       a  U R                  R                  5       $ g)zclose underlying filecloseN)hasattrr\  r  rL   s    r)   r  unbundle20.close  s)    488W%%88>>## &r+   )r  rw  r\  r'   )F)ro   rp   rq   rr   rs   rA  rN   r   propertycacher@   r  r  r  r   r  r  r  ru   __classcell__rz  s   @r)   r   r   J  sW    
 L 
 
'48(t3& $ $r+   r   s   20c                   ^  U 4S jnU$ )z/register a handler for a stream level parameterc                2   > T[         ;  d   eU [        T'   U $ r<   )ro  r  )rA   r4  s    r)   	decorator'b2streamparamhandler.<locals>.decorator  s!    9$$$"&$r+   r7   )r4  r  s   ` r)   b2streamparamhandlerr    s    
 r+   r$  c                    U[         R                  R                  ;  a  [        R                  " U4U4S9e[         R                  R                  U5      U l        Ub  SU l        gg)z<read compression parameter and install payload decompression)r@   valuesNT)r   r  supportedbundletypesr   r   r  r  rw  )r   rG  r5  s      r)   processcompressionr    s[     D$$999--eXuhOO ,,::5AI $	 r+   c                      \ rS rSrSr    SS jrS rS r\S 5       r	\	R                  S 5       r	\S 5       r\S	 5       rSS
 jrS rS rSrg)r<  i  a  A 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.
c                   [        U5        S U l        Xl        X@l        [	        U5      U l        [	        U5      U l        [        5       U l        U R
                  U R                  -    HH  u  pgX`R                  ;   a  [        R                  " SU-  5      eU R                  R                  U5        MJ     S U l        XPl        g )N   duplicated params: %s)r4   r   r   _datar   _mandatoryparams_advisoryparamsset_seenparamsr   r   rT   
_generatedr   )rM   r3   mandatoryparamsadvisoryparamsr   r   pname__s           r)   rN   bundlepart.__init__  s     	"	
 $_ 5#N35..1E1EEIE(((,,-E-MNN  ' F "r+   c                    U R                   R                  < SU R                   R                  < 3nSU[        U 5      U R                  U R                  U R
                  4-  $ )N.z2<%s object at %x; id: %s; type: %s; mandatory: %s>)rz  rp   ro   r   r   r   )rM   r  s     r)   __repr__bundlepart.__repr__8  sR    22DNN4K4KLCtHGGIINNG
 
 	
r+   c                    [        U R                  S5      (       a   eU R                  U R                  U R                  U R
                  U R                  U R                  5      $ )zreturn 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.next)r  r   rz  r   r  r  r  r   rL   s    r)   r   bundlepart.copyB  sS    
 499f----~~II!!  JJNN
 	
r+   c                    U R                   $ r<   )r  rL   s    r)   r   bundlepart.dataQ  s    zzr+   c                V    U R                   b  [        R                  " S5      eXl        g )N   part is being generated)r  r   ReadOnlyPartErrorr  )rM   r   s     r)   r   r  U  s#    ??&))*DEE
r+   c                ,    [        U R                  5      $ r<   )r]   r  rL   s    r)   r  bundlepart.mandatoryparams[  s     T**++r+   c                ,    [        U R                  5      $ r<   )r]   r  rL   s    r)   r  bundlepart.advisoryparams`  s     T))**r+   c                   U R                   b  [        R                  " S5      eXR                  ;   a  [	        SU-  5      eU R                  R                  U5        U R                  nU(       a  U R                  nUR                  X45        g)zadd 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.
Nr  r  )	r  r   r  r  r1   rT   r  r  rR   )rM   r4  r5  r   r@   s        r)   r   bundlepart.addparame  sx     ??&))*DEE###5<==T"%%**Ftm$r+   c           	   #    #    U R                   b  [        R                  " S5      eSU l         UR                  (       Ga  SU R                  -  /nU R
                  (       d  UR                  S5        [        U R                  5      n[        U R                  5      nU(       d  U(       aX  UR                  S5        U(       a  UR                  SU-  5        U(       a  UR                  SU-  5        UR                  S5        U R                  (       d  UR                  S	5        Oo[        U R                  S
5      (       d  [        U R                  S5      (       a  UR                  S5        O'UR                  S[        U R                  5      -  5        UR                  S5        UR                  SR                  U5      5        U R
                  (       a  U R                  R                  5       nOU R                  R                  5       n[!        US["        R$                  " U R&                  5      U4-  5        [)        [*        [        U5      5      U[)        [,        U R&                  5      /nU R                  nU R                  nUR                  [)        [.        [        U5      [        U5      5      5        / n	U H9  u  pU	R                  [        U
5      5        U	R                  [        U5      5        M;     U H9  u  pU	R                  [        U
5      5        U	R                  [        U5      5        M;     [)        [1        [        U	5      S-  5      /U	Q76 nUR                  U5        U H'  u  pUR                  U
5        UR                  U5        M)     U H'  u  pUR                  U
5        UR                  U5        M)      SR                  U5      n[!        US[        U5      -  5        [)        [4        [        U5      5      v   Uv    U R7                  5        H:  n[!        US[        U5      -  5        [)        [8        [        U5      5      v   Uv   M<     [!        US5        [)        [8        S5      v   SU l         g ! [2         a    [3        SU-  5      ef = f! [:         a    UR                  S5        e [<         a  n[>        R@                  " U5      nUR                  SU-  5        [B        RD                  " 5       S   nSU-  n[G        SSU4/SS9nSUl        [)        [8        S5      v   URI                  US9 H  nUv   M	     [!        US5        [)        [8        S5      v   ["        RJ                  " UU5         S nAGN*S nAff = f7f) Ns   part can only be consumed onceFs   bundle2-output-part: "%s"r   r   r   r   r   s    empty payloadr  __next__s    streamed payloads    %i bytes payloadr   r+   s   part %s: "%s"rm  z8Found a non-bytes trying to build bundle part header: %rs   header chunk size: %i   payload chunk size: %is   bundle2-generatorexit
s5   bundle2-input-stream-interrupt: encoding exception %ss   unexpected error: %s   error:abort   messager   r   rP  s   closing payload chunkT)&r  r   r   r   r   r   rR   rh   r  r  r   r  r%   r   upperr=   r*   r   r   r   rC  _fparttypesize_fpartid_fpartparamcountr9   	TypeErrorrQ  _payloadchunksr  GeneratorExitBaseExceptionr   forcebytestrsysexc_infor<  rH  raisewithtb)rM   r'   r   r   r   r3   headermanparadvparparsizesr  r5  
paramsizesheaderchunkchunkr   bexcr   	interparts                      r)   rH  bundlepart.getchunksx  sj    ??&(()JKK<<</$));<C>>

>*t++,Dt**+Dt

<(JJ/$67JJ56

4 99

,-F++wtyy*/M/M

/0

/#dii.@AJJuHHSXXc]# >>yy(Hyy(H%)9)9$'')BH(MMN .#h-0(DGG$
 %%$$e,c&k3v;GH JCOOCH%OOCJ' ! !JCOOCH%OOCJ' ! /H0BCOhO
j! JCMM#MM%  ! !JCMM#MM%  !	((6*K 	-K0@@A$c+&677	*,,.6UCDM3u:66 /< 	-.M1%%U  	/178 	  	 HH/0 	***3/DHHH4O "B)D0C"*c!2 3uI ILr**",,,3 4R12q))  b))%	*sJ   OVR 7VAR &VRV%V
B=V?VV

Vc              #    #    [        U R                  S5      (       d  [        U R                  S5      (       a`  [        R                  " U R                  5      nUR	                  [
        5      nU(       a#  Uv   UR	                  [
        5      nU(       a  M"  gg[        U R                  5      (       a  U R                  v   gg7f)zeyield chunks of a the part payload

Exists to handle the different methods to provide data to a part.r  r  N)r  r   r   chunkbufferreadpreferedchunksizerh   )rM   buffr  s      r)   r  bundlepart._payloadchunks  s      499f%%J)G)G##DII.DII/0E		"34 % ^^))O s   BC,C)r  r  r  r  r  r   r   r   N)r7   r7   r+   T)r+   T)ro   rp   rq   rr   rs   rN   r  r   rW  r   setterr  r  r   rH  r  ru   r7   r+   r)   r<  r<    s    $ #6

   
[[ 
 , , + +%&jXr+   r<  r  c                  8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )interrupthandleri  zread 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,c                0   > [         TU ]  U5        Xl        g r<   )rx  rN   r'   ry  s      r)   rN   interrupthandler.__init__  s    r+   c                    U R                  [        5      S   nUS:  a  [        R                  " SU-  5      e[	        U R
                  SU-  5        U(       a  U R                  U5      $ g)r  r   r  s   part header size: %i
Nr  r  s     r)   r   interrupthandler._readpartheader  se     \\"23A6
>((0:=  	2Z?@??:..r+   c                   U R                   R                  S5        [        U R                   S5        U R                  5       nUc  [        U R                   S5        g [	        U R                   XR
                  5      n[        U R                   5      nSn [        X25         U(       d  UR                  5         U R                   R                  S5        g ! [        [        4 a    Sne f = f! U(       d  UR                  5         f f = f)Ns<   bundle2-input-stream-interrupt: opening out of band context
s0   bundle2 stream interruption, looking for a part.s"   no part found during interruption.FTs<   bundle2-input-stream-interrupt: closing out of band context
)r'   r%   r-   r  r  r\  interruptoperationr   
SystemExitKeyboardInterruptr   )rM   r  r   r   	hardaborts        r)   __call__interrupthandler.__call__  s    L	
 	LM**,DGGBCDGG[((;(		"
 L	
 -. 	I	  s   C C''C* *DrP  )
ro   rp   rq   rr   rs   rN   r  r  ru   r  r  s   @r)   r  r    s    F
 
r+   r  c                  4    \ rS rSrSrS r\S 5       rS rSr	g)r  i*  zhA limited operation to be use by part handler during interruption

It only have access to an ui object.
c                ,    Xl         S U l        SU l        g )NF)r'   r|   r}   )rM   r'   s     r)   rN   interruptoperation.__init__0  s    
"r+   c                .    [         R                  " S5      eNs'   no repo access from stream interruption)r   r   rL   s    r)   ry   interruptoperation.repo5  s    $$%OPPr+   c                    [        S5      er  r   rL   s    r)   r   !interruptoperation.gettransaction9  s    $%OPPr+   )r}   r|   r'   N)
ro   rp   rq   rr   rs   rN   rW  ry   r   ru   r7   r+   r)   r  r  *  s(    
#
 Q QQr+   r  c              #    #    U R                  SS5      nU R                  n[        R                  " [        5      nUR
                  nUR                  n[        R                  nUR                  nU" U" X5      5      S   n	[        U SU	-  5        U	(       a  U	S:  aI  U" U	5      n
[        U
5      U	:  a-  [        R                  " [        S5      [        U
5      U	4-  5      eU
v   O4U	[        :X  a  [!        X5      " 5         O[        R"                  " SU	-  5      eU" U5      n
[        U
5      U:  a-  [        R                  " [        S5      [        U
5      U	4-  5      eU" U
5      S   n	U(       a  U" SU	-  5        U	(       a  M  gg7f)	zReads bundle2 part payload data into chunks.

Part payload data consists of framed chunks. This function takes
a file handle and emits those chunks.
r!   r"   r   r  s6   stream ended unexpectedly  (got %d bytes, expected %d)s   negative payload chunk size: %ss&   bundle2-input: payload chunk size: %i
N)r$   r%   ra  Structr  ri  unpackr	   rh  r  r-   rh   r   rn  r   r  r  r~  )r'   fhdologr%   headerstructr  r  rh  r  	chunksizess              r)   decodepayloadchunksr  =  ss     MM($45EHHE==/L""J  F))K77D{223A6IB)I56 >YA1v	!kk8 1vy)	*  G-' R$&((2Y>  q6J++KLq69%& 
 1IaL	 <yHIC )s   E?FFc                  j   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rSS jrSS jrSrU =r$ )r  iu  z a bundle part read from a bundlec                >  > [         TU ]  U5        [        US5      =(       a    [        US5      U l        Xl        X l        SU l        SU l        SU l        S U l	        S U l
        S U l        S U l        S U l        SU l        U R                  5         S U l        SU l        g )Nseektellr   Fr7   )rx  rN   r  	_seekabler'   _headerdata_headeroffset_initializedconsumedr   r   r  r  r@   r   _readheader
_mandatory_posrM   r'   r  r]  rz  s       r)   rN   unbundlepart.__init__x  s     V,DV1D!!	#"	r+   c                R    U R                   nU R                  X"U-    nX!-   U l         U$ )z+return the next <size> byte from the header)r!  r   )rM   ri  offsetr   s       r)   _fromheaderunbundlepart._fromheader  s0    ##4-9#]r+   c                b    U R                  [        R                  " U5      5      n[        X5      $ )zYread given format from header

This automatically compute the size of the format to read.)r+  ra  rb  rc  rd  s      r)   _unpackheaderunbundlepart._unpackheader  s(      78v$$r+   c                   [        U5      U l        [        U5      U l        [        R                  " U R                  5      U l        U R
                  R                  U R                  5        [        S U 5       5      U l        g)z7internal function to setup all logic related parametersc              3  *   #    U  H	  oS    v   M     g7f)r   Nr7   )r%  r   s     r)   r'  +unbundlepart._initparams.<locals>.<genexpr>  s     &E_t_s   N)	r]   r  r  r   r  r@   r   r?   r   )rM   r  r  s      r)   _initparamsunbundlepart._initparams  s_      %_5#N3mmD$8$894../&&E_&EEr+   c           	     R   U R                  [        5      S   nU R                  U5      U l        [	        U R
                  SU R                  -  5        U R                  [        5      S   U l        [	        U R
                  S[        R                  " U R                  5      -  5        U R                  U R                  R                  5       :g  U l        U R                  R                  5       U l        U R                  [        5      u  p#[	        U R
                  SX#-   -  5        [        X#-   5      nU R                  U5      n[        [        USSS2   USSS2   5      5      nUSU nXRS n/ nU H6  u  pUR!                  U R                  U	5      U R                  U
5      45        M8     / nU H6  u  pUR!                  U R                  U	5      U R                  U
5      45        M8     U R#                  X5        [$        R&                  " U R)                  5       5      U l        SU l        g)	z$read the header and setup the objectr   s   part type: "%s"s   part id: "%s"s   part parameters: %iNrm  r   T)r.  r  r+  r   r-   r'   r  r   r   r   r=   r   r  r9   r   ziprR   r3  r   r  r  _payloadstreamr"  )rM   typesizemancountadvcountfparamsizesr  mansizesadvsizes	manparamsr  r5  	advparamss               r)   r$  unbundlepart._readheader  s   %%n5a8$$X.	+dii78$$X.q1)H,<,<TWW,EEFdiioo&77IIOO%	 "//0@A/83FGH*8+>?''4
#j1oz!$Q$/?@A
ix(i(	"JCd..s3T5E5Ee5LMN #	"JCd..s3T5E5Ee5LMN #."..t/B/B/DE r+   c              #  v   #    U R                    H%  nU =R                  [        U5      -  sl        Uv   M'     g 7fr<   )r7  r&  rh   rM   r  s     r)   rd   unbundlepart.__iter__  s,     ((EIIU#IK )s   79c                B    [        U R                  U R                  5      $ )z+Generator of decoded chunks in the payload.)r  r'   r\  rL   s    r)   r  unbundlepart._payloadchunks  s    "477DHH55r+   c                    U R                   (       a  gU R                  S5      nU(       a9  U =R                  [        U5      -  sl        U R                  S5      nU(       a  M8  gg)zRead 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   )r#  r  r&  rh   rB  s     r)   r   unbundlepart.consume  sF     ==		% IIU#IIIe$E er+   c                   U R                   (       d  U R                  5         Uc  U R                  R                  5       nOU R                  R                  U5      nU =R                  [        U5      -  sl        Ub  [        U5      U:  aQ  U R                  (       d9  U R                  (       a(  U R                  R                  SU R                  -  5        SU l        U$ )zread payload datas*   bundle2-input-part: total payload size %i
T)	r"  r$  r7  r  r&  rh   r#  r'   r%   )rM   ri  r   s      r)   r  unbundlepart.read  s      <&&++-D&&++D1D		SY	<3t9t+==TYYBTYYN !DMr+   c                6    U R                   R                  5       $ )z*the amount of byte read so far in the part)r7  r  rL   s    r)   r  unbundlepart.tell  s    ""''))r+   )r   r!  r"  r%  r7  r&  r  r  r#  r   r   r   r  r@   r   r'   r<   )rV  int)ro   rp   rq   rr   rs   rN   r+  r.  r3  r$  rd   r  r   r  r  ru   r  r  s   @r)   r  r  u  s?    *(%F!!F
6%"* *r+   r  c                  r   ^  \ rS rSrSrU 4S jrSS jrS rS r\	R                  4S jrSS jrS	 rS
rU =r$ )r  i  a  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).
c                4   > / U l         [        TU ]	  XU5        g r<   )_chunkindexrx  rN   r'  s       r)   rN   seekableunbundlepart.__init__  s    R(r+   c              #  ^  #    [        U R                  5      S:X  a9  US:X  d   S5       eU R                  R                  SU R                  5       45        ODU[        U R                  5      :  d
   SU-  5       eU R	                  U R                  U   S   5        U R                  U   S   n[        U R                  U R                  5       H]  nUS-  nU[        U5      -  nU[        U R                  5      :X  a*  U R                  R                  X R                  5       45        Uv   M_     g7f)z/seek to specified chunk and start yielding datar   s   Must start with chunk 0s   Unknown chunk %dr   N)rh   rO  rR   _tellfp_seekfpr  r'   r\  )rM   chunknumposr  s       r)   r  #seekableunbundlepart._payloadchunks  s	    t A%q=<"<<=##Q$78c$"2"233 #h.3 LL))(3A67x(+($((;EMH3u:C3t//00  ''lln(=>K <s   D+D-c                    [        U R                  5       H6  u  nu  p4X1:X  a  US4s  $ X1:  d  M  US-
  XR                  US-
     S   -
  4s  $    [        S5      e)z>for a given payload position, return a chunk number and offsetr   r   s   Unknown chunk)r   rO  r1   )rM   rU  r  pposfposs        r)   
_findchunkseekableunbundlepart._findchunk!  se    #,T-=-=#>E<D{axqy#(8(8(CA(F"FFF	 $?
 )**r+   c                    U R                   $ r<   )r&  rL   s    r)   r  seekableunbundlepart.tell*  s    yyr+   c                   U[         R                  :X  a  UnOU[         R                  :X  a  U R                  U-   nO|U[         R                  :X  aY  U R
                  (       d2  U R                  S5      nU(       a  U R                  S5      nU(       a  M  U R                  S   S   U-
  nO[        SU4-  5      eX0R                  S   S   :  aC  U R
                  (       d2  U R                  S5      nU(       a  U R                  S5      nU(       a  M  SUs=::  a  U R                  S   S   ::  d  O  [        S5      eU R                  U:w  a  U R                  U5      u  pE[        R                  " U R                  U5      5      U l        U R                  U5      n[        U5      U:w  a  [        R                   " [#        S5      5      eX0l        g g )Nr   r  r   s   Unknown whence value: %ri  s   Offset out of ranges   Seek failed
)osSEEK_SETSEEK_CURr&  SEEK_ENDr#  r  rO  r1   rZ  r   r  r  r7  rh   r   rn  r   )rM   r*  whencenewposr  internaloffsetadjusts          r)   r  seekableunbundlepart.seek-  st   R[[ Fr{{"YY'Fr{{"==		%( IIe,E e%%b)!,v5F8F9DEE$$R(++DMMIIe$E		%( % F5d..r215534499$(OOF$;!E"&"2"243F3Fu3M"NDYY~.F6{n,kk!$4"566I r+   c                    U R                   (       a  U R                  R                  X5      $ [        [	        S5      5      e)zmove 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.s   File pointer is not seekable)r  r\  r  NotImplementedErrorr   )rM   r*  rc  s      r)   rS  seekableunbundlepart._seekfpM  s/     >>88==00%a(G&HIIr+   c                    U R                   (       a   U R                  R                  5       $ g! [         a0  nUR                  [        R
                  :X  a  SU l          SnAge SnAff = f)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)r  r\  r  OSErrorerrnoESPIPE)rM   es     r)   rR  seekableunbundlepart._tellfpZ  sZ     >>xx}}&   77ell*%*DNN  	s   . 
A(%A#"A##A()rO  r7  r&  r  )r   )ro   rp   rq   rr   rs   rN   r  rZ  r  r_  r`  r  rS  rR  ru   r  r  s   @r)   r  r    s;    ")*+ #%++ @J r+   r  )s   aborts   unsupportedcontents	   pushraced   pushkey)s   https   https)s   heads)   v2)
r  	   bookmarkss   error   listkeysrq     digests   remote-changegroup   hgtagsfnodes   phases   streamr   c                @   US;  a  [         R                  " S5      e[        R                  5       n[	        [        [        R                  " U 5      5      5      US'   [        R                  " U [        R                  5      (       a$  [	        S [        R                   5       5      nXCS'   U(       a  SUS'   U R                  R                  SS	5      nUS
:X  a  SUS'   SU R                  R                  SS5      ;   a  UR                  S5        US:X  aV  U R                  R!                  SSSS9nU R                  R!                  SS5      nU(       a  U(       d  UR                  S5        U R                  R!                  SS5      (       a  SU;   a  US==   S-  ss'   U$ )aK  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.
)   client   servers&   role argument must be client or serverr   c              3  ,   #    U  H
  nS U-  v   M     g7f)s   V%iNr7   )r%  r  s     r)   r'  getrepocaps.<locals>.<genexpr>  s     E4Dq
4Ds   
   obsmarkersr7   s   pushbackr|  s   concurrent-push-modes   check-related)s   relateds
   checkheadsrx  r!   s   legacy.exchanges   uncompressedT)	untrusteds   bundle2.streamry     experimentals	   stream-v3)   v3-exp)r   r   r   r   r]   r  r	   supportedincomingversionsr   	isenabledexchangeoptformatsr'   config
configlistpopr$   )ry   allowpushbackroler  supportedformatcpmodestreamsupportedfeaturesupporteds           r)   getrepocapsr  ~  so    ))$$%NOOD {44T:;D $ 4 455EH4D4DEE-][WW^^I'>?F!!+]DGG&&x1CDD y'',,$ - 
  77--i9JK&6HHY ww/<88O|+O
 Kr+   c                    U R                  S5      nU(       d  US:w  a  0 $ [        R                  U R                  S5      5      n[        U5      $ )z0return the bundle capabilities of a peer as dictr   r+   )capabler   r  r  )rz   rawcapsblobs      r)   bundle2capsr    s@    
..
$C3#:	~~fnnZ89Hhr+   c                    U R                  SS5      nU Vs/ s H(  o"R                  S5      (       d  M  [        USS 5      PM*     sn$ s  snf )zIextract the list of supported obsmarkers versions from a bundle2caps dictr  r7      Vr   N)r^   rT  rL  )r  obscapscs      r)   obsmarkersversionr    s?    hh}b)G '>1<<+=JC!"J>>>s
   A	A	c           
        UR                  S5      (       a'  [        R                  " XSU5      n[        U UUUUUU	S9$ UR                  S5      (       d  [        R
                  " SU-  5      eUR                  SUR                  5      nU(       aH  U
(       dA  [        UR                  SUR                  5      5      nSnX-  n[        R
                  " U5      e0 nUR                  SS	5      (       a  S
US'   UR                  SS5      nUS:X  a  S/US'   OUS:X  a  S/US'   [        X5      nUR                  X5        [        XUX%U5        UR                  5       n[        R                  " U UX7S9$ )Nr     01)vfscompressionr+  r  s   unknown bundle type: %ss   %ln and _internal()z3backup bundle would contains %d internal changesets   obsolescenceF)s   V1r  ry  r+   rr  r  r  )rT  r	   makechangegroupwritebundler   r   revsancestorsofrh   missingr^   r  r,  _addpartsfromoptsrH  writechunks)r'   ry   r   filename
bundletypeoutgoingoptsr  r  r+  allow_internalr   bundled_internalr   r   r  stream_versionbundle	chunkiters                      r)   writenewbundler    sl    W%%((G#
 	
 ""7++$$%?*%LMM yy!79M9MNDII4h6F6FGHC$$S))Dxx''&]XXi-N 'Y	9	$$+YbF
+0b$?  "I""2y(DDr+   c                X   UR                  SS5      (       Ga)  UR                  S5      nUc  [        R                  " U5      n[        R                  " XXc5      nUR	                  SUR                  5       S9nUR                  SUR                  5        SUR                  ;   a!  UR                  SSUR                  S   -  S	S
9  UR                  S5      (       ag  [        R                  n	UR                   H  n
[        XU
   R                  5       5      n	M!     U	[        R                  :  a  UR                  SSU	-  S	S
9  [        R                  UR                   ;   a  WR                  SS5        UR                  SS5      S:X  a
  [#        X!SS9  UR                  SS5      S:X  a
  [#        X!SS9  UR                  SS5      (       a  [%        XU5        UR                  SS5      (       a  ['        XU5        UR                  SS	5      (       a>  UR(                  R+                  UR,                  S9n[/        UUUR                  SS5      S
9  UR                  SS	5      (       aG  [        R0                  " XR,                  5      n[        R2                  " U5      nUR	                  SUS9  g g )Nr   Ts
   cg.versionr      version   clcount	   nbchanges   %dFr   rx     targetphase   exp-sidedatar   ry  r+   rr  )streamr  s   tagsfnodescaches   revbranchcacher  )nodess   obsolescence-mandatory   phase-heads)r^   r	   safeversionr  r   rH  r   rr  extrasr   draftr  maxphaser   REPO_FEATURE_SIDE_DATAfeaturesaddpartbundlestream2addparttagsfnodescacheaddpartrevbranchcacheobsstorerelevantmarkersr  buildobsmarkerspartsubsetphaseheadsbinaryencode)r'   ry   bundlerr   r  r  	cgversionr   r   target_phasehead
obsmarkersheadsbyphase	phasedatas                 r)   r  r    s@    xx%%HH]+	#//5I((K~BLLNCj"**-"MMebii
&;;u   88I!<<L ,,"<d1A1A1CD -fll*"L(#  
 ((DMM9ot,xx	35(W48xx	39,W48xx"D))th7xx!4((dX6xx'']]229I9I2J
hh8$?	
 xx	5!!..t5E5EF''5	Y7 "r+   c                   [         R                  " U R                  5       5      n/ nUR                   H.  nUR	                  USS9nU(       d  M  UR                  XV/5        M0     U(       a!  UR                  SSSR                  U5      S9  g g )NF)computemissingrw  r+   )r   r   )r   hgtagsfnodescache
unfilteredr  getfnodeextendr   r   )ry   r  r  cacher  nodefnodes          r)   r  r  -  s     ""4??#45EF $$tE:5MM4-(	 % &! 	 	
 r+   c                X  ^	 U R                  5       nU R                  5       R                  n[        R                  " S 5      m	UR
                   H<  nUR                  UR                  U5      5      u  pgT	U   U   R                  U5        M>     U	4S jnUR                  SU" 5       SS9  g )Nc                 *    [        5       [        5       4$ r<   )r  r7   r+   r)   r   'addpartrevbranchcache.<locals>.<lambda>O  s    CE35>r+   c               3  H  >#    [        TR                  5       5       H|  u  n u  p[        R                  " U 5      n[        R                  [        U5      [        U5      [        U5      5      v   Uv   [        U5       S h  vN   [        U5       S h  vN   M~     g  N N7fr<   )r  itemsr
   	fromlocal	rbcstructpackrh   )branchr  closed
utf8branchbranchesdatas       r)   generate'addpartrevbranchcache.<locals>.generateT  s}     '-l.@.@.B'C#FOU!++F3J..Z#e*c&kJJe}$$f~%% (D %%s$   A>B"BB"B 
B" B"   cache:rev-branch-cacheFr   )
revbranchcacher  	changelogcollectionsdefaultdictr  
branchinforevrT   r   )
ry   r  r  r  clr  r  r  r  r  s
            @r)   r  r  J  s     !E			$	$B**+ABL  ((6VU#''- !& OO-HJ%OPr+   c                    U  Vs/ s H  oS:w  d  M
  UPM     n n[         R                  SR                  [        U 5      5      5      $ s  snf )Ns   sharedr   )r   r  r   r  )r   reqs     r)   _formatrequirementsspecr  _  s>    #/D<C)3CC<LD<<		&"6788 Es
   	AAc                P    [        U 5      n S[        R                  S5      U 4-  nU$ )Ns   %s%ss   requirements=)r  r   r  )r   r@   s     r)   _formatrequirementsparamsr  d  s*    *<8L%56EEFMr+   c                    SnU R                   (       a+  SR                  S [        U R                   5       5       5      nU$ )zXFormats a repo's wanted sidedata categories into a bytestring for
capabilities exchange.r+   r   c              3  N   #    U  H  n[         R                  " U5      v   M     g 7fr<   )r   r   )r%  r  s     r)   r'  0format_remote_wanted_sidedata.<locals>.<genexpr>o  s"      
)FAHQ)Fs   #%)_wanted_sidedatar   r  )ry   wanteds     r)   format_remote_wanted_sidedatar  j  s?     F 
)/0E0E)F
 
 Mr+   c                :    U R                  S5      n[        U5      $ )N   exp-wanted-sidedata)r  read_wanted_sidedata)rz   sidedata_categoriess     r)   read_remote_wanted_sidedatar  u  s     ..)?@ 344r+   c                X    U (       a  [        U R                  S5      5      $ [        5       $ )Nr   )r  r   )	formatteds    r)   r  r  z  s     9??4())5Lr+   c                (   UR                  SS5      (       d  g [        R                  " U5      (       d*  [        S5      n[        S5      n[        R
                  " X4S9eSU R                  ;  a*  [        S5      n[        S5      n[        R
                  " X4S9e[        U R                  S   5      n[        [        USS	9R                  S/ 5      5      nXV-  nU(       d[  [        S
5      nSR                  [        U5      5      nSR                  [        U5      5      n	X8U	4-  n[        R
                  " U5      e[        U5      n
SU l        UR                  S5      nUR                  S5      nUR                  R                  SS5      nU(       d  U(       a&  U(       d  [        R
                  " [        S5      5      eSnUR                  (       aW  [!        U R                  5      nU(       d  [        R
                  " [        S5      5      eUR                  R"                  U;   a  SnU
S:X  a  [        R$                  " XX5      u  nnn[        R&                  " U5      n[)        U5      nU R+                  SUS9nUR-                  SSU-  SS9  UR-                  SSU-  SS9  UR-                  SUSS9  g U
S:X  aZ  [        R.                  " XX5      n[        R&                  " U5      n[)        U5      nU R+                  SUS9nUR-                  SUSS9  g g )Nr  Fs<   stream data requested but server does not allow this features   the client seems buggyhintry  sO   stream data requested but supported streaming clone versions were not specifiedr{  )r  s3   no common supported version with the client: %s; %sr   includepatsexcludepatsr  s   server.stream-narrow-cloness,   server does not support narrow stream clonessP   server has obsolescence markers, but client cannot receive them via stream cloneTrr     stream2r  	   bytecountr  r   	   filecount   requirementsr     stream3-exp)r^   r   allowservergenerationr   r   rn  r   r  r  r   r  r  r   r'   r$   r  r  _version
generatev2streamed_requirementsr  r   r   
generatev3)r  ry   r   r   r  client_supportedserver_supportedcommon_supported
str_server
str_clientrr  r  r  narrowstreamincludeobsmarkersremoteversions	filecount	bytecountitr   r   s                        r)   r  r    s   ::h&&,,T22OP*+kk#))---^
 *+kk#))7//	:;;t)<@@BOP':FGYYv&678
YYv&678
J''kk#"#G
  %G **]+K**]+K77%%7L 	{Lkk!KLMM}}*7+?+?@++<  ]]##~5 $%#.#9#9{$
 	9b #88>.|<z3lEI$5FlEI$5Fo|tD	I	##{
 #88>.|<~B7o|tD 
r+   c                    U(       d  g[        U R                  5      n[        R                  " U5      nUc  [	        S5      e[        R
                  " USUS9nU R                  SXRS9$ )zadd 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.
Ns0   bundler does not support common obsmarker formatT)rr  r  r   )r  r   r   commonversionr1   encodemarkersr   )r  markersr   r  rr  r  s         r)   r  r    sb     &w';';<N$$^4GLMM##GT7CF??=v?KKr+   c                  ^^^^ US:X  a  [        U 5      nUR                  UT5        UR                  STR                  5       S9nUR	                  STR
                  5        STR                  ;   a!  UR	                  SSTR                  S   -  SS	9  UR                  5       n	OUb   eTR
                  S
:w  a  [        R                  " [        S5      5      e[        U   u  mn
U
[        R                  R                  ;  a"  [        R                  " [        S5      U
-  5      e[        R                  R                  U
5      mUUUU4S jn	U	" 5       n	[        R                   " X	X$S9$ )zWrite 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: %sc               3  j   >#    Tv   TR                  T R                  5       T5       S h  vN   g  N7fr<   )rE  rH  )r   
compenginer+  r  s   r)   r  writebundle.<locals>.chunkiter  s'     L!00JJJs   (313r  )r  r,  r   rH  r   rr  r  r   rn  r   bundletypesr   r  r  r  r	   r  )r'   r   r  r  r  r  r+  r  r   r  compr$  r  s    `    `    @@r)   r  r    sF    W"k84~~n2<<>~Bj"**-"MMebii
&;;u   $$&	 """::++CD  #:. t''<<<++a FG$NOO%%33D9
	K 	K K	 ""2(DDr+   c                   U R                   S    Vs/ s H  oR                  SS5      PM     nnSnSnU H+  nUS:X  a  Sn  O"US:  a	  X5S-   -  nM  US:  d  M$  X5S-
  -  nM-     US:  a  SU-   nU$ US:  a  SU-   nU$ s  snf )z:logic to combine 0 or more addchangegroup results into oner   r   r   r   r  )r{   r^   )r   rresultschangedheadsresultr   s         r)   combinechangegroupresultsr-    s    ,.JJ~,FG,FquuY",FGGLF!8F8!G#L1W!G#L  a\! M 
	l"M! Hs   A>r   )r  r  r  r     treemanifestr  c                P   SSK Jn  U R                  5       nUR                  R	                  SS5      n[
        R                  " XAS5      nSnSUR                  ;   a$  [        UR                  R	                  S5      5      nSUR                  ;   Ga"  [        R                  " U R                  5      (       d  [        U R                  R                  5      S:w  a  [        R                  " [        S	5      5      eU R                  R                   R#                  [         R$                  5        UR'                  U R                  R(                  U R                  R                   U R                  R*                  5      U R                  R,                  l        [        R0                  " U R                  5        0 nUR                  R	                  S
5      nUb  [        U5      US'   UR                  R	                  S5      n	[3        U	5      US'   [5        U UUU R6                  S4SU0UD6n
U R8                  b]  U R8                  R;                  SSS9nUR=                  S[>        R@                  " URB                  5      SS9  UR=                  SSU
-  SS9  URE                  5       (       a   eg)z$apply a changegroup part on the repor   )	localrepor  r  Nr  r.  r   s[   bundle contains tree manifests, but local repo is non-empty and does not use tree manifestsr  targetphaser  r   r   expectedtotal   reply:changegroupFr   r   r      %i)#r  r0  r   r@   r^   r	   rt  rL  r   istreemanifestry   rh   r  r   rn  r   r   rT   TREEMANIFEST_REQUIREMENTresolvestorevfsoptionsr'   r  svfsoptionswritereporequirementsr  r   r   r|   r   r   r   r   r   r  )r   inpartr0  r   unpackerversionr   nbchangesetsextrakwargsr1  remote_sidedatar   r   s               r)   handlechangegroupr@  !  s/    				Bmm''
E:O		!	!/4	@B Lv}}$6==,,\:;&--'0F0Frww0O0Orww  !Q&++A  	  !F!FG(??GGJJ,,bgg.>.> 
 	%%bgg.K--##N3K%(%5M"mm''(>?O)=o)NK%&




		 # C 
xx xx 4FH,,VYY75 	 	
 	i>{{}}}r+   )r      sizeru  	   digest:%srv  c                    UR                   S   n[
        R                  " U5      nUR                  [        S   ;  a,  [        R                  " [	        S5      UR                  -  5      e [        UR                   S   5      n0 nUR                   R                  SS5      R                  5        H  nS	U-  n UR                   U   nXU'   M     [        R                  " [        R                  " U R                   U5      XE5      n	U R#                  5       n
S
SKJn  UR)                  U R*                  R                   X5      n[-        U[.        R0                  5      (       d6  [        R                  " [	        S5      [
        R2                  " U5      -  5      e[5        XXR6                  S5      nU R8                  b^  U R8                  R;                  S5      nUR=                  S[>        R@                  " URB                  5      SS9  UR=                  SSU-  SS9   U	RE                  5         URI                  5       (       a   eg! [         a#    [        R                  " [	        S5      S-  5      ef = f! [         a#    [        R                  " [	        S5      S-  5      e[         a#    [        R                  " [	        S5      S-  5      ef = f! [         a#    [        R                  " [	        S5      U-  5      ef = f! [        R                   aG  n[        R                  " [	        S5      [
        R2                  " U5      URF                  4-  5      eSnAff = f)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.
r   s&   remote-changegroup: missing "%s" paramrv  s+   remote-changegroup does not support %s urlsrA  s0   remote-changegroup: invalid value for param "%s"ru  r+   rB  r   )exchanges   %s: not a bundle version 1.0r   Nr3  r   Fr   r   r4  s   bundle at %s is corrupted:
%s)%r@   r  r   rn  r   r   r   schemer   rL  r1   r^   r   r   digestcheckeropenr'   r   r  rD  
readbundlery   r   r	   cg1unpackerhidepasswordr   r   r|   r   r   r   r   r   validater(   r  )r   r;  raw_url
parsed_urlri  digeststyprG  r5  	real_partr   rD  r   r   r   ro  s                   r)   handleremotechangegrouprQ  i  s   "Q--' W%J-B CCkk<= 
 	

	
6==)* G}}  S1779s"	MM%(E
  : ""388BEE7#;TKI				B			RWWZZ	<Bb+1122kk-.1E1Eg1NN
 	
 bb))Z
@C	xx xx 45H,,VYY75 	 	
 	i>
 {{}}}s  Qkk!EFOPPQ  
kkABWL
 	
  
kk787B
 	

  	++;<uD 	6 ;; 
kk/0##G,aii89
 	

s=   I +I1 8KK< -I.1AK	-K9<MAMMr3  )r   r   c                    [        UR                  S   5      n[        UR                  S   5      nU R                  R                  SSU0U5        g )Nr   r   r   rL  r@   r{   rT   )r   r;  r   replytos       r)   handlereplychangegrouprU    sA    
fmmI&
'C&--/0GJJNN>Is#3W=r+   s   check:bookmarksc                h   [         R                  " U R                  U5      nSnSnSnU H  u  pgU R                  R                  R	                  U5      nX:w  d  M1  Uc  XV[        U5      4-  n	O-Uc  XF[        U5      4-  n	OUU[        U5      [        U5      4-  n	[        R                  " U	5      e   g)zcheck 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)sb   remote repository changed while pushing - please try again (bookmark "%s" is missing, expected %s)sf   remote repository changed while pushing - please try again (bookmark "%s" set on %s, expected missing)N)r   binarydecodery   
_bookmarksr^   r   r   	PushRaced)
r   r;  bookdatamsgstandard
msgmissingmsgexistbookr  currentnodefinalmsgs
             r)   handlecheckbookmarksra    s     %%bggv6H	. 
	3 
	7  
gg((,,T2|#U;-?&@@$%uT{(;;&$K+&* 
 //(++ r+   s   check:headsc                   UR                  S5      n/ n[        U5      S:X  a3  UR                  U5        UR                  S5      n[        U5      S:X  a  M3  U(       a   eU R                  R	                  SS5      (       a  U R                  5         [        U5      [        U R                  R                  5       5      :w  a  [        R                  " S5      eg)zcheck 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)r  rh   rR   r'   r$   r   r  ry   headsr   rY  )r   r;  hrf  s       r)   handlecheckheadsrh    s     	BAE
a&B,QKKO a&B, L5	uu)>??
e}rww}}//ooI
 	
 0r+   s   check:updated-headsc                   UR                  S5      n/ n[        U5      S:X  a3  UR                  U5        UR                  S5      n[        U5      S:X  a  M3  U(       a   eU R                  R	                  SS5      (       a  U R                  5         [        5       nU R                  R                  5       R                  5        H  nUR                  U5        M     U H  nX$;  d  M
  [        R                  " S5      e   g)a:  check 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.rc  r  rd  re  N)r  rh   rR   r'   r$   r   r  ry   	branchmap	iterheadsr   r   rY  )r   r;  rg  rf  currentheadslss         r)   handlecheckupdatedheadsrn    s     	BAE
a&B,QKKO a&B, L5	uu)>??
5Lgg!++-B .  //$  r+   s   check:phasesc                   [         R                  " U5      nU R                  R                  5       nUR                  nUR
                  nSnUR                  5        H|  u  pxU Hq  n	UR                  X4R                  U	5      5      n
X:w  d  M*  U[        U	5      [         R                  U
   [         R                  U   4-  n[        R                  " U5      e   M~     g)zbcheck that phase boundaries of the repository did not change

This is used to detect a push race.
sQ   remote repository changed while pushing - please try again (%s is %s expected %s)N)r   rW  ry   r  r  _phasecacher  r  r  r   
phasenamesr   rY  )r   r;  phasetonodesunfir  
phasecacher   expectedphaser  r&  actualphaser`  s               r)   handlecheckphasesrw  	  s     &&v.L77D	B!!J	"  !- 2 2 4A$**4;K+!H%%k2%%m4" 
 ooh//  !5r+   r   c                    UR                  5       R                  5        H*  nU R                  R                  [	        S5      U-  5        M,     g)z3forward output captured on the server to the clients   remote: %s
N)r  r   r'   r   r   )r   r;  r  s      r)   handleoutputry  4	  s7     ((*
Q'$./ +r+   s	   replycapsc                    [        UR                  5       5      nU R                  c  [        U R                  U5      U l        gg)zmNotify that a reply bundle should be created

The payload contains the capabilities information for the replyN)r  r  r|   r  r'   )r   r;  r  s      r)   handlereplycapsr{  ;	  s5    
 fkkm$D	xxBEE4( r+   c                      \ rS rSrSrSrg)AbortFromPartiE	  z=Sub-class of Abort that denotes an error from a bundle2 part.r7   N)ro   rp   rq   rr   rs   ru   r7   r+   r)   r}  r}  E	  s    Gr+   r}  r  )r     hintc                b    [        UR                  S   UR                  R                  S5      S9e)z*Used to transmit abort error over the wirer  r~  r  )r}  r@   r^   r   r;  s     r)   handleerrorabortr  I	  s.     j!(9(9'(B r+   s   error:pushkey)	   namespace   key   new   old   retr   c                    0 nS H'  nUR                   R                  U5      nUc  M#  XBU'   M)     [        R                  " UR                   S   40 [        R
                  " U5      D6e)z=Used to transmit failure of a mandatory pushkey over the wirer  r  r  r  r  r   )r@   r^   r   PushkeyFailedr   	strkwargs)r   r;  r   r4  r5  s        r)   handleerrorpushkeyr  Q	  sh     F>!!$' 4L ? 

n%)1););F)C r+   s   error:unsupportedcontent)   parttype   paramsc                   0 nUR                   R                  S5      nUb  X2S'   UR                   R                  S5      nUb  UR                  S5      US'   [        R                  " S0 [
        R                  " U5      D6e)z4Used to transmit unknown content error over the wirer  r      r7   )r@   r^   r   r   r   r   r  )r   r;  r   r3   r@   s        r)   handleerrorunsupportedcontentr  a	  sw     F}}  -H&{]]y)F"LL/y

)
)
GH,>,>v,F
GGr+   s   error:pushraced)r  c                \    [         R                  " [        S5      UR                  S   5      e)z.Used to transmit push race error over the wires   push failed:r  )r   ResponseErrorr   r@   r  s     r)   handleerrorpushracedr  o	  s%     

a0&--
2K
LLr+   rt  )r  c                    UR                   S   n[        R                  " UR                  5       5      nU R                  R                  SX#45        g)z6retrieve pushkey namespace content stored in a bundle2r  rt  N)r@   r   
decodekeysr  r{   rT   )r   r;  	namespacer)  s       r)   handlelistkeysr  u	  s<     l+I6;;=)AJJNN;/r+   rq  r  r  r  r  c                |   [         R                  nU" UR                  S   5      nU" UR                  S   5      nU" UR                  S   5      nU" UR                  S   5      nU R                  R	                  SS5      (       a  U R                  5         U R                  R                  X4XV5      nX4XVS.nU R                  R                  SU5        U R                  b^  U R                  R                  S
5      n	U	R                  S[        R                  " UR                  5      SS9  U	R                  SSU-  SS9  UR                  (       an  U(       df  0 n
S H%  nXAR                  ;   d  M  UR                  U   X'   M'     [         R"                  " SSSUR                  -  0[        R$                  " U
5      D6eg	g	)zprocess a pushkey requestr  r  r  r  r  rd  r  rq  N   reply:pushkeyr   Fr   r   r4  r  rZ   r  r7   )r   decoder@   r'   r$   r   ry   r{   rT   r|   r   r   r   r   r   r   r   r  r  )r   r;  decr  r  oldnewr   recordrpartr   s              r)   handlepushkeyr  }	  s    ..CFMM,/0I
fmmF#
$C
fmmF#
$C
fmmF#
$C 
uu)>??

''//)#
3C%CMFJJNN:v&	xx  !12H,,VYY75 	 	
 	y%#+?ACmm#$mmC0 B !! 
699$
(0(:(:6(B
 	
 !$r+   rs  c                p  ^ ^ [         R                  " T R                  U5      nT R                  R                  R	                  SS5      nT R
                  R                  SS5      nUS:X  Ga  T R                  5       nT R                  R                  nU(       a  / mU Ho  u  pxUR                  R                  5       n	SU	S'   SU	S'   XyS'   [        UR                  US	5      5      U	S
'   [        Ub  UOS	5      U	S'   TR                  U	5        Mq     T H6  n	T R                  R                  "  SSS0[        R                  " U	5      D6  M8     U HD  u  px[         R                   " U5      (       d  M"  [#        S5      U-  n
[$        R&                  " U
5      e   UR)                  T R                  T R                  5       U5        U(       a#  UU 4S jnT R                  R+                  U5        ggUS:X  a,  U H%  u  pxXxS.nT R,                  R/                  SU5        M'     g[$        R0                  " SU-  5      e)a<  transmit 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|  s   bookmarks-pushkey-compatrs  s   applyr   s   pushkeycompatr  r  r+   r  Nr  throwTs$   cannot accept divergent bookmark %s!c                x   > T H3  nTR                   R                  " S0 [        R                  " U5      D6  M5     g )N)rq  )ry   hookr   r  )unused_successr~   allhooksr   s     r)   runhookhandlebookmark.<locals>.runhook	  s+     (HGGLLLx/A/A(/KL !)r+   s   records)s   bookmarks   nodes   unknown bookmark mode: %s)s
   prepushkey)r   rW  ry   r'   r$   r   r^   r   rX  r~   r   r   rR   r  r   r  isdivergentr   r   rn  applychanges
_afterlockr{   rT   r   )r   r;  changespushkeycompatbookmarksmoder   	bookstorer^  r  r~   r   r  r  r  s   `            @r)   handlebookmarkr  	  s   " $$RWWf5GGGJJ)).M HHLLx8M  GG&&	H%
;;++--1)*)5&#' #&y}}T3'?#@ #&t/?tS#I ) & %!)-191C1CH1M %
 "JD$$T**?@4Gkk#&& "
 	rww(9(9(;WEM GGw'  
*	$!JD#'7FJJNN<0 " $$(=8
 	
r+   r  c                    [         R                  " U5      n[         R                  " U R                  R	                  5       U R
                  U5        g)z%apply phases from bundle part to repoN)r   rW  updatephasesry   r  r   )r   r;  r  s      r)   handlephasesr  	  s9     &&v.L
**,b.?.?Nr+   r  c                    [        UR                  S   5      n[        UR                  S   5      nU R                  R                  SSU0U5        g)(retrieve the result of a pushkey requestr   r   rq  NrS  r   r;  r   rZ   s       r)   handlepushkeyreplyr  	  sC     fmmI&
'C~./FJJNN:	3/8r+   r  c                   U R                  5       nUR                  5       nU R                  R                  SS5      (       a'  U R                  R	                  S[        U5      -  5        UR                  (       dK  U R                  R                  R                  (       a&  U R                  R                  R                  S5        gU R                  R                  R                  X#5      nU R                  R                  5         U R                  R                  SSU05        U R                  b_  U R                  R!                  S5      nUR#                  S	[$        R&                  " UR(                  5      S
S9  UR#                  SSU-  S
S9  gg)z&add a stream of obsmarkers to the repor  s   obsmarkers-exchange-debugs&   obsmarker-exchange: %i bytes received
s3   ignoring obsolescence markers, feature not enabled
Nr  r     reply:obsmarkersr   Fr   r4  )r   r  r'   r  writenoi18nrh   r   ry   r  readonlyr%   mergemarkersinvalidatevolatilesetsr{   rT   r|   r   r   r   r   r   )r   r;  r   
markerdatar  r  s         r)   handleobsmarkerr  	  s/    
			BJ	uu||O%ABB
6ZH	

  0 0 9 9


C	
 	
''


'
'
7CGG""$JJNN=63-0	xx  !45H,,VYY75 	 	
 	vus{e< r+   r  )r  r   c                    [        UR                  S   5      n[        UR                  S   5      nU R                  R                  SSU0U5        g)r  r  r   r  NrS  r  s       r)   handleobsmarkerreplyr  

  sB     fmmF#
$C~./FJJNN=63-8r+   rw  c                   U R                   R                  SS5      (       a  U R                  5         [        R                  " U R
                  R                  5       5      nSn UR                  S5      nUR                  S5      n[        U5      S:  d  [        U5      S:  a  U R                   R                  S5        OUR                  XE5        US-  nMt  UR                  5         U R                   R                  SU-  5        g)	ztApplies .hgtags fnodes cache entries to the local repo.

Payload is pairs of 20 byte changeset nodes and filenodes.
r  rd  r   rc  s1   ignoring incomplete received .hgtags fnodes data
r   s'   applied %i hgtags fnodes cache entries
N)r'   r$   r   r   r  ry   r  r  rh   r%   setfnodewrite)r   r;  r  r   r  r  s         r)   handlehgtagsfnodesr  
  s     
uu)>??
""277#5#5#78EE
{{2Bt9r>SZ"_EEKKMNt#
  
KKMEEKK;eCDr+   s   >IIIr  c                    g)zLegacy 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.Nr7   r  s     r)   	handlerbcr  .
  s    r+   s   pushvarsc                    U R                   R                  SS5      (       aB  0 nUR                   H  u  p4UR                  5       nSU-   nXBU'   M      U R	                  U5        gg)z5unbundle a bundle2 containing shellvars on the servers   pushs   pushvars.servers   USERVAR_N)r'   r$   r  r  r   )r   r   r~   r  r5  s        r)   bundle2getvarsr  6
  sd     
uu!344--JC))+C #C!SM . 	x  5r+   r	  )r  r  r
  c                   [         R                  UR                  S   5      nU(       a  UR                  " S5      O/ n[	        UR                  S   5      n[	        UR                  S   5      nU R
                  n[        U5      (       a!  [        S5      n[        R                  " U5      eUR                  R                  S5        [        R                  " XQX4U5        g )Nr  r   r  r
  1   cannot apply stream clone to non empty repository   applying stream bundle
)r   r  r@   r   rL  ry   rh   r   r   rn  r'   r%   r   applybundlev2)r   r   r   r  r  ry   r   s          r)   handlestreamv2bundler  E
  s    >>$++o">?L/;<%%d+LDKK-.IDKK-.I77D
4yyDEkk#GGMM-.d)Mr+   r  )r  c                \   [         R                  UR                  S   5      nU(       a  UR                  " S5      O/ nU R                  n[        U5      (       a!  [        S5      n[        R                  " U5      eUR                  R                  S5        [        R                  " X1U5        g )Nr  r   r  r  )r   r  r@   r   ry   rh   r   r   rn  r'   r%   r   applybundlev3)r   r   r   ry   r   s        r)   handlestreamv3bundler  U
  sz    >>$++o">?L/;<%%d+L77D
4yyDEkk#GGMM-.d,7r+   c                h   [        5       nUR                  n	UR                  SU5       H#  n
UR                  U	R	                  U
5      5        M%     U(       a  [
        R                  " UUUUUS9nUR                  UR                  1[        U5      SSSS9nU R                  SUS9nUR                  SU5        [        R                  " U5      (       a  UR                  S	S
5        [        R                  UR                   ;   a/  WR                  SS
5        [#        U5      nUR                  SU5        U $ )a#  generates 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)
oldmatchermatcher	fullnodesFs   narrow_widen)r  r   r  r  r.  r   r  r  )r  r  r  rT   r  r	   
getbundlerr  nullidr   r   r   r   r5  r   r  r  r  )r  ry   r  
newmatchercommonknownr  ellipsescommonnodesr  r)  packercgdatar   r  s                  r)   widen_bundler  c
  s     %K	BYYx(
# )''!!
 [[M ! 
 ~F;j),!!$''MM/40((DMM9ot,.t4,f5Nr+   )r7   )NN)NNr+   N)r  bytesrV  r   r<   )FN)r  rl   rV  r   )rV  r   )r  r   )NNNF)T)NNN)rs   
__future__r   r  rm  r_  rer2  ra  r  typingi18nr   r  r   r   r  r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   utilsr   r   
interfacesr   TYPE_CHECKINGr   r   r   r   r   r   r  r   urlerrr   r  rC  r  rc  rD  rQ  r  r  r  r  r  compiler/   r*   r-   r4   r9   r>   rE   rG   rw   RuntimeErrorr   r   r   r   r   r   r   r   r   r  r  r&  bundlepriorityr  rY  rt  r   ro  r  r  r  r<  r  r  r  r  r  r  r]   r  DIGESTSkeysr   __annotations__r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r-  r@  _remotechangegroupparamsrQ  rU  ra  rh  rn  rw  ry  r{  rn  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r  s   0r)   <module>r     s  KZ #   	 	   
       #	  uT%[%s
2C%CDDEL		
--    ZZ 23 43#%  ,- -`:' :'z	\ 	#$D
 D
T .b#'T:0
 
 !! 3z zz7 78&f$ f$R J	  n%% &%d dN 0
} 0
fQ Q&5Jp|*= |*~v< vx IfT\\..012.l .b ? 	0Ef98x
:Q*9
5
GETL$ HL.Eb* 
4
4n !!!%!2!2!45!4A|a!456  "$<=K >K\ !#>?> @>  ", !",J ^
 
( #$ %> _0 02 Y0 0 \) )HEKK H ^23 4 B			 (*BC
H D
H /M 0M
 [/*0 +0 Z?@
 A
< \@
 @
F ^O O :;9 <9 ]= =4  ":;9 <9 _E E0 MM'"	 &' ( [! ! ZFGN HN ^/0
8 1
8-} 6s   6P
