
    	^c|                       d dl Z d dlZddlmZ ddlmZmZ ddlmZ	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlm Z m!Z!m"Z" ddl#m$Z$ ej%        Z%ej&        Z&dZ'dod	Z(d
 Z)d Z*d Z+d Z,d Z- G d d          Z. ed           ed          f ed           ed          f ed           ed          fdZ/	 	 	 	 	 	 dpdZ0g Z1i Z2d Z3d Z4d Z5 e3d          d             Z6 e3d           d!             Z7 e3d"          d#             Z8 e3d$          d%             Z9d& Z:d' Z;g Z<i Z=dod(Z>d) Z?d* Z@ e>d+          d,             ZA e>d-          d.             ZB e>d          d/             ZC e>d           d0             ZDd1 ZEd2 ZF e>d3          d4             ZG e>d$          d5             ZHd6 ZId7 ZJd8 ZKd9 ZL e>d:d ;          d<             ZMd= ZNd> ZOd? ZPejQ        fd@ZRdA ZSdB ZT G dC dD          ZU G dE dFejV                  ZWdG ZXdH ZYdI ZZ	 	 	 	 	 	 	 	 	 	 dqdJZ[g Z\i Z]dK Z^dL Z_ e^dM          dN             Z` e^dO          dP             ZadQ ZbdR ZcdS ZddT ZedU ZfdV ZgdW ZhdX ZidodYZjdZ Zkg Zli Zmdod[Znd\ Zo	 	 	 	 drd]Zp end^          d_             Zq endO          	 	 	 	 	 dsd`            Zr end$          	 dtda            Zs endb          	 dtdc            Zt end3          	 dudd            Zu ende          	 dudf            Zv endg          	 	 	 	 drdh            Zw endi          	 	 	 	 drdj            Zxdk Zydl Zzdm Z{dn Z|dS )v    N   )_)hexnullrev)	bookmarksbundle2bundlecacheschangegroup	discoveryerrorlocklogexchange
narrowspecobsoleteobsutilphasespushkeypycompatrequirementsscmutilstreamcloneurlutilwireprototypes)hashutil
stringutilurlutil)
repositorys	   narrowaclc                    t          j        |d          }d }|sFd}|                    d          s.|                    d          rt          j        ||          }d}d}n|r|                    |          }|dd         |dd         }}|dk    r$t          j        t          d	          |z            |d
k    r,|t          j        |d          }t          j        ||          S |                    d          rt          j
        | |||z             S |dk    rt          j        |          S t          j        t          d          ||fz            )N      streams   HG    s   HG10s   UNr      s   %s: not a Mercurial bundles   10   2)magicstrings   S1s   %s: unknown bundle version %s)r
   readexactly
startswithheaderlessfixupjoinr   Abortr   cg1unpackerr   getunbundlerr   streamcloneapplier)uifhfnamevfsheaderalgmagicversions           4/usr/lib/python3/dist-packages/mercurial/exchange.py
readbundler7   4   sr   $R++F
C    '' 	F,=,=e,D,D 	,R88BFC	  AaC[&1+7E~~k!9::UBCCC%;)"a00C&r3///			D	!	! 
#BHHHH	E		-b111k.//5'2BB
 
 	
    c                     g }t          |                                           D ]9\  }}t                              |          }|                    d||fz             :d                    |          S )Ns   %s=%s   ;)sorteditemsurlreqquoteappendr)   )paramspartskeyvalues       r6   _format_paramsrD   S   sk    EV\\^^,, . .
UU##Xe,----99Ur8   c                    d }i }t          | |d          }t          |t          j                  rE|j        }|dk    rd} ||          }|s$t          j        t          d          |z            d|z  S t          |t          j	                  r|d|j
        v r= ||j
        d                   }|s$t          j        t          d          |z            nd}d}|                                D ]}|j        d	k    rS|j
        d
         }	|	dv rd}!|	dv rd}|	|d<   -t          j        t          d          |z  t          d                    |j        dk    rQ|Ot                              |j
        d                   }
 |
j                    }t          j        |          }d|z  c S |j        dk    rd|d<   |j        sd|d<   |s!t          j        t          d                    d||fz  }|r|dz  }|t%          |          z  }|S t          |t&          j                  r3t'          j        |          d         }
t          j        |
          }d|z  S t          j        t          d          |z            ) zInfer the bundlespec from a bundle file handle.

    The input file handle is seeked and the original seek position is not
    restored.
    c                     	 t           j                            |                                           d         S # t          $ r Y d S w xY wNr   )r   compenginesforbundletype
bundletypeKeyError)r3   s    r6   speccompressionz&getbundlespec.<locals>.speccompressionb   sQ    	#11#66AACCAFF 	 	 	44	s   69 
AANs   _truncatedBZs   BZs!   unknown compression algorithm: %ss   %s-v1s   Compressions   none   changegroup   version)   01s   02s   v2)s   03s
   cg.versions7   changegroup version %s does not have a known bundlespecs#   try upgrading your Mercurial clienthint   stream2s   requirementss   none-v2;stream=v2;%s
   obsmarkerss   yess   obsolescences   nos   obsolescence-mandatorys0   could not identify changegroup version in bundles   %s-%sr:   r#   s   none-packed1;%ss   unknown bundle type: %s)r7   
isinstancer
   r+   _typer   r*   r   r   
unbundle20r@   	iterpartstyper=   unquotesplit_formatrequirementsparams	mandatoryrD   r   r-   readbundle1header)r.   r/   rL   r@   br3   compr5   part	cgversionr   splittedspec	formatteds                 r6   getbundlespecre   [   s      F2r4  A![,-- >=g/!!Cs## 	M+a DEEKLLL$	Aw)	*	* 6=QX%%"?18N#;<<D k:;;dB  
 DKKMM 	> 	>DyN** K
3	..#GG(**#G,5F=))+2  "	"
 EFF    j((W_%~~dk/.JKK-<-// :8DD.7777m++*0'~ >8=F45 	+EFF   4/) 	+DLDN6***D	A{5	6	6 ="4R88;5lCC	!I--k!677!;<<<r8   c                     | j         }|r|j        fd|D             }n| j        g}|s|                                }t	          j        | ||          S )zComputes which revs are outgoing given a set of common
    and a set of heads.

    This is a separate function so extensions can have access to
    the logic.

    Returns a discovery.outgoing object.
    c                 *    g | ]} |          |S  rh   ).0nhasnodes     r6   
<listcomp>z$_computeoutgoing.<locals>.<listcomp>   s&    222wwqzz2!222r8   )	changelogrk   nullidheadsr   outgoing)reporo   commonclrk   s       @r6   _computeoutgoingrt      si     
B *2222V222+ 

dFE222r8   c                 N   | j         }|j        }|                    dd          }| j        s|dvrd S t	          | j        d          }|                    dd          sd S | j        )|                    d                              d          }n3|                    d	| j                  }||                    d          z  }|r|d
k    r4|	                    t          d          t          |          z             d S |dk    rU|                    t          d          t          |          z            r!t          j        t          d                    d S |dk    rFt          d          t          |          z  }t          d          }t          j        ||          d S d S )N   experimentals   auto-publish)   warn   confirm   abort   phases
   publishingFs   serveds   not public()s   ::%ln - public()rw   s$   %i changesets about to be published
rx   s2   push and publish %i changesets (yn)?$$ &Yes $$ &Nos	   user quitry   s    push would publish %i changesetss:   use --publish or adjust 'experimental.auto-publish' configrP   )rq   r.   configpublishlistkeysremotegetrevsfilteredwarnr   lenpromptchoicer   CanceledErrorr*   )pushoprq   r.   behaviorremotephases	publishedmsgrQ   s           r6   _checkpublishr      s   ;D	Byy/::H~ )HHHFM955LM511 {MM),,11/BB		II16;??	 	T]]9---	 .wGG:;;c)nnL     ##GHHi..!  ; )!L//:::	; ;
 !!7883y>>IC D +c----#. . "!r8   c                     | j         j        }|                    dd          }d|vod|v }|p| j                            d           S )zsreturn true if a pull/push must use bundle1

    This function is used to allow testing of the older bundle version   devel   legacy.exchange   bundle2s   bundle1)rq   r.   
configlistr   capable)opr.   exchangeforcebundle1s       r6   _forcebundle1r      sU     
B }}X'9::HX-H*2HL<ry00<<<<r8   c                   |    e Zd ZdZ	 	 	 	 	 	 d	dZej        d             Zej        d             Ze	d             Z
dS )
pushoperationzA object that represent a single push operation

    Its purpose is to carry push related state and very common operations.

    A new pushoperation should be created at the beginning of each push and
    discarded afterward.
    FNrh   c	                    || _         |j        | _        || _        || _        || _        || _        || _        t                      | _        d | _	        d | _
        d | _        d | _        d | _        d | _        d | _        d | _        d | _        t                      | _        g | _        d | _        i | _        || _        || _        d S N)rq   r.   r   forcer   r   	newbranchset	stepsdonecgresultbkresultrp   remoteheadspushbranchmapincomingr   outdatedphasesfallbackoutdatedphasesoutobsmarkersoutbookmarks	trmanagerpkfailcbpushvarsr}   )	selfrq   r   r   r   r   r   r}   r   s	            r6   __init__zpushoperation.__init__   s     	'
	""   " "&*# UU  r8   c                     | j         j        S )z2future remote heads if the changeset push succeeds)rp   ancestorsofr   s    r6   futureheadszpushoperation.futureheadsJ  s     }((r8   c                 b   | j         | j        j        S | j                                        }| j        j        | j        j        j        j        fd| j         D             }|	                    d| j        j        | j        j
                  }|                    d |D                        |S )z/future remote heads if the changeset push failsNc                 .    g | ]} |          v |S rh   rh   )ri   noderr   revs     r6   rl   z/pushoperation.fallbackheads.<locals>.<listcomp>f  s+    DDD4D		V0C0C$0C0C0Cr8   s   %ln and parents(roots(%ln))c              3   >   K   | ]}|                                 V  d S r   r   ri   cs     r6   	<genexpr>z.pushoperation.fallbackheads.<locals>.<genexpr>n  s*      //1affhh//////r8   )r   rp   commonheadsrq   
unfilteredrr   rm   indexr   r   missingextend)r   unficheadsrevsetrr   r   s       @@r6   fallbackheadszpushoperation.fallbackheadsO  s     9=,,y##%% %i!'+DDDDD49DDD *M%M!
 

 	////////r8   c                 ,    | j         r| j        S | j        S )z3set of all common heads after changeset bundle push)r   r   r   r   s    r6   r   zpushoperation.commonheadsq  s      = 	&##%%r8   FNFrh   FN)__name__
__module____qualname____doc__r   r   propertycacher   r   propertyr   rh   r8   r6   r   r      s          I I I IV 
) ) ) 
  B & & X& & &r8   r   s   updating bookmark %s
s   updating bookmark %s failed
s   exporting bookmark %s
s   exporting bookmark %s failed
s   deleting remote bookmark %s
s#   deleting remote bookmark %s failed
)   update   export   deleteFrh   c           	      T   |i }t          | ||||||fi t          j        |          }|j                                        rt          |j        j                  |j                                        j        z
  }	|	rFt          d          d
                    t          |	                    z  }
t          j        |
          |j                                        s!t          j        t          d                    |j                            d          s!t          j        t          d                    t          t!          j        |j                            D ]n}| j                                        D ]\  }}|                    |          r n7t          j        t          d          t          j        |          z            odx}}	 |j                            dd	          }t1          |          s/|r-t3          j        |           s|j                                        }|j                                        }t;          |j        d
|j                                                  |_        nM# t          j         $ r;}dtC          j"        |          z  }
|j        #                    |
           Y d}~nd}~ww xY w|ptI          j%                    5  |ptI          j%                    5  |j        ptI          j%                    5  |j        &                    |           tO          |           tQ          |           |j)        stU          |           t1          |          stW          |           tY          |           t[          |           t]          |           t_          |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   | j                            dd          rta          j1        | |           |S )aW  Push outgoing changesets (limited by revs) from a local
    repository to remote. Return an integer:
      - None means nothing to push
      - 0 means HTTP error
      - 1 means we pushed and remote head count is unchanged *or*
        we have outgoing changesets but refused to push
      - other values as described by addchangegroup()
    N:   required features are not supported in the destination: %s   , s!   destination does not support push   unbundlesL   cannot push: destination does not support the unbundle wire protocol commandsJ   cannot push: required sidedata category not supported by this client: '%s'rv      bundle2.pushbacks   push-responses"   cannot lock source repository: %s
   remotenames)2r   r   	strkwargsr   localr   rq   r   	supportedr   r)   r;   r   r*   canpushr   r   read_remote_wanted_sidedata_sidedata_computersr<   r   bytestrr.   
configboolr   bookmodbookmarksinstorewlockr   transactionmanagerr   r   LockUnavailabler   forcebytestrdebugr   nullcontextmanager	checkpushr   _pushdiscoveryr   _checksubrepostate_pushbundle2_pushchangeset_pushsyncphase_pushobsolete_pushbookmarkr   pullremotenames)rq   r   r   r   r   r   r}   opargsr   r   r   categorykind	computersr   r   maypushbackerrs                     r6   pushr     s   $ ~	 	 
V
$
$	 	F } 
#())FM,?,?,A,A,KK 	  	#  F7OO,,	.C
 +c"""=  "" Ck!@AABBB=  -- 
k2 
 
 	
 7>v}MMNN    $7==?? 
	 
	OD)}}X&&  +-  "8,,	-    ED i**?<OPPv&&	(	( ,T22	(
 K%%''E{!!-K)6=+<+<+>+>
 
      5z7N8
 8
 
 		 
	+$)++ & &.T,.. 	& 	&!>T%<%>%> & &%%f---f%%%v&&&| /&v...$V,, ) (((v&&&v&&&f%%%f%%%& & & & & & & & & & & & & & &	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&& & & & & & & & & & & & & & & w/>:: 2#D&111Mst   B$I7 7K1J<<KO-/O
B)N?3O?OOOO
O-O	O-O	O--O14O1c                       fd}|S )a|  decorator for function performing discovery before push

    The function is added to the step -> function mapping and appended to the
    list of steps.  Beware that decorated function will be added in order (this
    may matter).

    You can only use this decorator for a new step, if you want to wrap a step
    from an extension, change the pushdiscovery dictionary directly.c                 f    t           vsJ | t           <   t                                         | S r   )pushdiscoverymappingpushdiscoveryorderr?   funcstepnames    r6   deczpushdiscovery.<locals>.dec  9    33333)-X&!!(+++r8   rh   r   r   s   ` r6   pushdiscoveryr     #         Jr8   c                 J    t           D ]}t          |         } ||            dS zRun all discovery stepsN)r   r   )r   r   steps      r6   r   r     4    &  #H-V r8   c                    | j         }t          |                    d                    r"t          |                    d                    sdS | j        j        D ]x}||         }d|                                v rXd|                                v rBt          |j                  D ]-}|	                    |          }|
                    d           .ydS )zDEnsure all outgoing referenced subrepo revisions are present locallys   .hgsubs   .hgsubstateNT)onpush)rq   r   filerp   r   manifestfilesr;   substatesubverify)r   rq   rj   ctxsubpathr
  s         r6   r   r     s     ;D tyy##$$ C		.0I0I,J,J _$ ( (1g&&>SYY[[+H+H!#,// ( (ggg&&

$
''''( (r8   s	   changesetc                 D   t           j        }| j        r$ || j        | j        | j        | j                  }n || j        | j        | j                  }|\  }}}t           j        } || j        | j        | j        || j                  }|| _        || _        || _	        dS )z-discover the changeset that need to be pushed)r   r   )r   )	onlyheads	commonincr   N)
r   findcommonincomingr   rq   r   r   findcommonoutgoingrp   r   r   )r   fcir  rr   incr   fcorp   s           r6   _pushdiscoverychangesetr  1  s     
&C{ HCKM,	
 
 
		 CV]&,GGG	(FC

&Cs+l  H FO$FFOOOr8   s   phasec                 R   | j         }| j                                        }t          | j        d          }| j                            dd          r4|r2| j         j        s&|                    dd          rg | _	        g | _
        dS t          j        | j        | j        |          | _        | j        j        }d}| j        j        sd}d	|z  }t#          |                    ||| j                            }| j        j        s1| j        r*t#          |                    d
| j        |                    }nh|j        s|}n^t#          |                    d|j        |                    }	d |	D             }	t#          |                    ||	| j                            }|| _	        || _
        dS )zpdiscover the phase that needs to be pushed

    (computed for both success and failure case for changesets push)rz      ui   _usedassubrepor{   FNr8   s    and public()s   heads((%%ln::%%ln) %s)s   %ln and (not public() or %ln::)s   roots(%ln  + %ln::)c                 6    g | ]}|                                 S rh   r   )ri   fs     r6   rl   z'_pushdiscoveryphase.<locals>.<listcomp>  s     ---16688---r8   )rp   rq   r   r~   r   r.   r   r   r   r   r   r   remotephasessummaryr   r   
draftroots
publishinglistr   r}   r   )
r   rp   r   r   droots	extracondr   fallbackfuturefdrootss
             r6   _pushdiscoveryphaser%  L  s   
 H;!!##DFM955L 		U$566 ' ]E22	 !#(*% 4V)< F  +FI) %$	&2F DHHVVV-ABBCCH) Efn EHH2F4F 
 

  E HH+X-=vFF
 
 .-W---dhhvw0BCCDD"F$,F!!!r8   s	   obsmarkerc                 @   t          j        | j        t           j                  sd S | j        j        sd S dt          | j        d          vrd S | j        }d |                    d| j                  D             }| j        j        	                    |          | _
        d S )N   obsoletes
   namespacesc              3   >   K   | ]}|                                 V  d S r   r   r   s     r6   r   z+_pushdiscoveryobsmarkers.<locals>.<genexpr>  s*      FF!QVVXXFFFFFFr8      ::%ln)r   	isenabledrq   exchangeoptobsstorer~   r   r   r   relevantmarkersr   )r   rq   nodess      r6   _pushdiscoveryobsmarkersr/    s    fk8+?@@ ; (6=-@@@@;D GFtxx&2DEEFFFE!;/??FFFr8   	   bookmarksc                    | j         }| j                                        | j        }|                    d           d}| j        r@t          j        j        j	        | j                  }j        
                    |d          }t          j        t          |d                    }fd| j        D             }t          j        j        |          }t#          | ||||          S )Ns   checking for updated bookmarks
rh   T)	inclusiver0  c                 D    h | ]}j                             |          S rh   
_bookmarks
expandnameri   bookmarkrq   s     r6   	<setcomp>z*_pushdiscoverybookmarks.<locals>.<setcomp>  s6       19""8,,  r8   )r.   rq   r   r   r   r   r   maplistrm   r   	ancestorsr   unhexlifybookmarksr~   r   comparebookmarksr5  _processcompared)	r   r.   r   r;  revnumsremotebookmarkexplicitr_   rq   s	           @r6   _pushdiscoverybookmarksrB    s    	B;!!##D]FHH0111I{ F"4>#5v{CCN,,W,EE	/0N0NOON   =C=M  H #D$/>JJDFIxNNNr8   c                 J   |\  }}}}}	}
}}| j         }|D ]Z\  }}}||v r|                    |           |r||                                         |v r| j                            |||f           [|D ]\  }}}||v rx|                    |           t          j        |          r2| j                            t          d          |z             d| _
        e| j                            |d|f           t          |          t          |	          z   t          |
          z   D ]<\  }}}||v r2|                    |           | j                            |||f           =|D ]<\  }}}||v r2|                    |           | j                            ||df           =|D ]\  }}}||v r|                    |            |rFt          |          }| j                            t          d          |d         z             d| _
        | j                                         dS )zntake decision on bookmarks to push to the remote repo

    Exists to help extensions alter this behavior.
    s#   cannot push divergent bookmark %s!
r#   r8   s>   bookmark %s does not exist on the local or remote repository!
r   N)rq   remover   r   r?   r   isdivergentr.   r   r   r   r  r;   sort)r   pushedrA  	remotebmsr_   addsrcadddstadvsrcadvdstdivergedifferinvalidsamerq   r^   sciddcids                    r6   r>  r>    sw   
 FJBFFFFGVWd;D 8 84==OOA 	8d))V33&&4777 ; ;4==OOA"1%% ;	q!HIIAMNNN"##**AsD>:::fW5VD 8 84==OOA&&4777 7 74==OOA&&4~666  4==OOA 
(##	+  qk		
 	
 	
 
r8   c                 h   | j         }| j                                        }|j        s"t	          j        |j        ||j                   dS | j        s|j	        rt          d          }t          d          }t          d          }t          d          ||d}|j        D ]~}||         }|                                rt          j        ||z            |                                r5t          j        ||                                d                  |z            t#          j        |            dS )	NFs%   push includes obsolete changeset: %s!s,   push includes phase-divergent changeset: %s!s.   push includes content-divergent changeset: %s!s#   push includes orphan changeset: %s!)s   orphans   phase-divergents   content-divergentr   T)rp   rq   r   r   r   nochangesfoundr.   excludedr   r,  r   r   r   r   r*   
isunstableinstabilitiesr   
checkheads)	r   rp   r   msomspdmscdmstr   r  s	            r6   _pushcheckoutgoingr]    sG   H;!!##D twh.?@@@u< % = 	I<==CDEEDFGGDCDD$(&* C !, I I4j<<>> I+cCi000^^%% I  +c#*;*;*=*=a*@&AC&GHHHI
 	V$$$4r8   c                       fd}|S )aw  decorator for function generating bundle2 part

    The function is added to the step -> function mapping and appended to the
    list of steps.  Beware that decorated functions will be added in order
    (this may matter).

    You can only use this decorator for new steps, if you want to wrap a step
    from an extension, attack the b2partsgenmapping dictionary directly.c                     t           vsJ | t           <   t                                         nt                                         | S r   )b2partsgenmappingb2partsgenorderr?   insertr   idxr   s    r6   r   zb2partsgenerator.<locals>.dec!  sW    00000&*(#;""8,,,,""3111r8   rh   r   rd  r   s   `` r6   b2partsgeneratorrf    )          Jr8   c                 ,   | j         s| j        j        rd|j                            dd          v }| j        du }|r|r+|                    dt          | j                             dS t                      }| j        
                                D ]G\  }}|\  }}}	}
|9t          |          }|t          |
          |z  z  }||t          |          z
  z  }H|r9t          t          |                    }|                    d|           dS dS dS dS )zdGenerate race condition checking parts

    Exists as an independent function to aid extensions
    s   relateds
   checkheadsrh   Ns   check:headsdatas   check:updated-heads)r   rp   r   capabilitiesr   r   newpartiterr   r   r<   r;   )r   bundlerallowunrelatedemptyremoteaffectedbranchro   r   newheadsunsyncedheadsdiscardedheadsr   rj  s                r6   _pushb2ctxcheckheadsrv  -  s_    < CFO7 C#w';'?'?2(
 (
 
 *d2 	C 	COONf6H1I1IOJJJJJuuH!'!5!;!;!=!= 7 7GLDX}n* --FN 3 3f <<HX 66H CF8,,-- 6TBBBBB#C C C CC Cr8   c                 ^    t          | j        j        p| j        p| j        p| j                  S )z&return True if we are pushing anything)boolrp   r   r   r   r   )r   s    r6   _pushingry  H  s?     	 		 	  r8   s   check-bookmarksc                 6   t          |           r| j        rdS t          j        | j                  }d|v }| j        r|sdS g }| j        D ]\  }}}|                    ||f           t          j        | j	        |          }|
                    d|           dS )zinsert bookmark move checkingNr0  s   check:bookmarksri  )ry  r   r   bundle2capsr   r   r?   r   binaryencoderq   rl  )	r   rn  b2capshasbookmarkcheckrj  bookoldnew	checkdatas	            r6   _pushb2checkbookmarksr  R  s     F v|  //F#v- $4 D - ! !c3T3K    $V[$77IOO&YO77777r8   s   check-phasesc                 t   t          |           r| j        rdS t          j        | j                  }d|                    dd          v }| j        |rd t          j        D             }|t          j	                 
                    | j        j                   |t          j                 
                    | j        j                   t          |                                          rP|D ]}||                                          t          j        |          }|                    d|           dS dS dS dS )zinsert phase move checkingN   headsrz   rh   c                     i | ]}|g S rh   rh   ri   ps     r6   
<dictcomp>z&_pushb2checkphases.<locals>.<dictcomp>k  s    222A!R222r8   s   check:phasesri  )ry  r   r   r{  r   r   r   r   	allphasespublicr   publicheadsdraftr  anyvaluesrF  r|  rl  )r   rn  r}  hasphaseheadschecksphaser  s          r6   _pushb2checkphasesr  b  s6    F v|  //F

9b 9 99M&=&22!1222v}$$V%8%DEEEv|##F$7$BCCCv}} 	= % %u""$$$$+F33IOOO)O<<<<< '&&&
	= 	=r8   c                 L    d j         v rdS  j                             d           t                     sdS  j                                        t           |           t          j         j                  }d}|	                    d          }|r@ fd|D             }|s!t          j        t          d                    t          |          }t          j         j                  }t          j         j         j        |d||          }|                    d|	          |r                    d
|           t)          j         j                  r                    dd           t,          j         j        j        v r                    dd            fd}|S )zwhandle changegroup push through bundle2

    addchangegroup result is stored in the ``pushop.cgresult`` attribute.
    
   changesetsNrO   rM   c                 J    g | ]}|t          j        j                  v | S rh   )r
   supportedoutgoingversionsrq   )ri   vr   s     r6   rl   z_pushb2ctx.<locals>.<listcomp>  s;     
 
 
K9&+FFFF FFFr8      no common changegroup version   push
bundlecapsremote_sidedatari  rN      treemanifest   1   exp-sidedatac                     | j                             j                  }t          |d                   dk    sJ |d         d         d         _        dS )z0extract addchangegroup returns from server replyrM   r   r      returnN)records
getrepliesidr   r   )r   	cgrepliescgpartr   s     r6   handlereplyz_pushb2ctx.<locals>.handlereply  sR    J))&)44	9^,--2222#N3A6yAr8   )r   addr]  rq   prepushoutgoinghooksrv  r   r{  r   r   r   r*   r   maxr   r
   
makestreamrp   rl  addparamr   istreemanifestr   REPO_FEATURE_SIDE_DATAfeatures)	r   rn  r}  r5   
cgversionsr  cgstreamr  r  s	   `       @r6   
_pushb2ctxr  u  s    (((
'''f%% 
K$$V,,,))) //FGN++J "
 
 
 

 
 


  	C+a @AABBBj//9&-HHO%'  H __^(_;;F -
G,,,fk** /...(FK,@@@...B B B B B B r8   c                    d| j         v rdS t          j        | j                  }| j        j        }d|                    dd          v }d|v }d|                    dd          v }|r|st          | |          S |rt          | |          S dS )z!handle phase push through bundle2rz   Nr   r      pushkeyr  rh   )
r   r   r{  r   rq   r.   r   r   _pushb2phaseheads_pushb2phasespushkey)r   rn  r}  r.   legacyphase
haspushkeyr  s          r6   _pushb2phasesr    s     F$$$ //F	Br}}X7IJJJKv%J

9b 9 99M 5[ 5 111	 5#FG4445 5r8   c                 "   | j                             d           | j        rmd t          j        D             }|d                             d | j        D                        t          j        |          }|                    d|           dS dS )z6push phase information through a bundle2 - binary partrz   c                     i | ]}|g S rh   rh   r  s     r6   r  z%_pushb2phaseheads.<locals>.<dictcomp>  s    333Q1b333r8   r   c              3   >   K   | ]}|                                 V  d S r   r   ri   hs     r6   r   z$_pushb2phaseheads.<locals>.<genexpr>  s*      BBq!&&((BBBBBBr8      phase-headsri  N)r   r  r   r   r  r   r|  rl  )r   rn  updates	phasedatas       r6   r  r    s    
### 833&"2333
BBF,ABBBBBB'00	Y77777	8 8r8   c                 T     j                             d           g fd}t          j        } j        D ]}|                    d          }|                    d |d                     |                    d ||                                                     |                    d |dt          j	        z                       |                    d |dt          j
        z                                           |j        |f           | j        |j        <    fd	}|S )
z7push phase information through a bundle2 - pushkey partrz   c                     t          |j                  }D ]/\  }}||k    r$t          j        t	          d          |z            0d S )Ns   updating %s to public failed)intpartidr   r*   r   )r   exctargetidr  r   	part2nodes        r6   handlefailurez+_pushb2phasespushkey.<locals>.handlefailure  s_    sz??% 	M 	MLFD!!k!$C"D"Dt"KLLL "	M 	Mr8   r  	   namespace   key   old   %d   newc                 F   D ]\  }}| j                             |          }|d         }t          |          dk    sJ d }|st          d          |z  }n-t	          |d         d                   st          d          |z  }|j                            |           d S )Nr  r   s'   server ignored update of %s to public!
r   r     updating %s to public failed!
)r  r  r   r   r  r.   r   )r   r  r   partrepresultsr   r  r   s         r6   r  z)_pushb2phasespushkey.<locals>.handlereply  s    % 
	$ 
	$LFDj++F33Gj)Gw<<1$$$$C CCDDtKI.// C:;;dB	s###
	$ 
	$r8   )r   r  r   encoder   rl  r  r   r   r  r  r?   r  r   )r   rn  r  encnewremoteheadr`   r  r  s   `      @r6   r  r    sL   
###IM M M M M .C. 1 1z**lCC	NN333fcc-"3"3"5"566777fcc%&,"677888fcc%&-"788999$'=1222#0  $ $ $ $ $ $ r8   rS   c                    d| j         v rd S t          j        |j                  }t	          j        |          d S | j                             d           | j        r0t          j	        | j                  }t          j
        ||           d S d S )NrS   )r   r   obsmarkersversionrk  r   commonversionr  r   r   sortedmarkersbuildobsmarkerspart)r   rn  remoteversionsmarkerss       r6   _pushb2obsmarkersr    s    (((.w/CDDNn--5
''' 6'(<==#GW555556 6r8   c                     d| j         v rdS t          j        | j                  }| j        j                            dd          }d|v }|sd|v rt          | |          S d|v rt          | |          S dS )z$handle bookmark push through bundle2r0  Nr   r   r  )	r   r   r{  r   rq   r.   r   _pushb2bookmarkspart_pushb2bookmarkspushkey)r   rn  r}  legacylegacybookss        r6   _pushb2bookmarksr    s     v''' //F[^&&x1CDDF&(K 8<611#FG444	v		&vw777 
	r8   c                     | sdS |sdS dS )z"small utility for bookmark pushingr   r   r   rh   )r  r  s     r6   	_bmactionr  
  s!     y y9r8   c                     |rQ| j         |                                         t          j        k    r&t	          j        t          d          |z            dS dS )z6abort if a given bookmark points to a secret changesets:   cannot push bookmark %s as it points to a secret changesetN)rq   r  r   secretr   r*   r   )r   r   r^   s      r6   _abortonsecretctxr    s^     
D!''))V]::kKLLqP
 
 	

 
::r8   c                 |     j                             d            j        sd S g g } j        D ]S\  }}}t           ||           |                    ||f                               |t          ||          f           Tt          j         j        |          }|	                    d|            fd}|S )Nr0  ri  c                 x    j         }D ].\  }}|                    t          |         d         |z             /d S rG   )r.   status
bookmsgmap)r   r.   r  action
allactionsr   s       r6   r  z)_pushb2bookmarkspart.<locals>.handlereply)  sK    Y& 	4 	4LD&IIj(+d23333	4 	4r8   )
r   r  r   r  r?   r  r   r|  rq   rl  )	r   rn  rj  r  r  r  r  r  r  s	   `       @r6   r  r    s    
&&& JD - 7 7c3&#t,,,T3K   43!4!456666$V[$77IOOLyO1114 4 4 4 4 4 r8   c           	      r   
  j                             d           g 
t          j        }
fd} j        D ]\  }}}t           ||           |                    d          }|                    d |d                     |                    d ||                     |                    d |t          |                               |                    d |t          |                               d}|sd	}n|sd
}
	                    |j
        ||f           | j        |j
        <   
 fd}	|	S )Nr0  c                     t          |j                  }D ]F\  }}}||k    r:t          j        t          |         d                                         |z            GJ )Nr   )r  r  r   r*   r  rstrip)r   r  r  r  r  r  	part2books         r6   r  z._pushb2bookmarkspushkey.<locals>.handlefailure7  sj    sz??$- 	I 	I FD&!!k*V"4Q"7">">"@"@4"GHHH " 	r8   r  r  r  r  r  r   r   r   c                    	j         }D ]\  }}}| j                            |          }|d         }t          |          dk    sJ |s+	j                             t          d          |z             jt          |d         d                   }|r*|                    t          |         d         |z             |                    t          |         d         |z             	j	        d	_	        d S )Nr  r   s"   server ignored bookmark %s update
r   r  )
r.   r  r  r   r   r   r  r  r  r   )
r   r.   r  r  r  r  r  retr  r   s
           r6   r  z,_pushb2bookmarkspushkey.<locals>.handlereplyN  s    Y$- 	, 	, FD&j++F33Gj)Gw<<1$$$$ 	,	q!GHH4OPPPP'!*Y/00 ,IIj03d:;;;;GGJv.q1D89992*+	, 	,r8   )r   r  r   r  r   r  rl  r  r   r?   r  r   )r   rn  r  r  r  r  r  r`   r  r  r  s   `         @r6   r  r  2  sp   
&&&I
.C     !- 1 1c3&#t,,,z**lCC$5$5666fcc$ii(((fcc#c((mm,,,fcc#c((mm,,, 	FF 	F$'40111#0  , , , , , ," r8      pushvars)rd  c                 .   | j         }|ri }|D ]=}d|vrd}t          j        ||z            |                    dd          \  }}|||<   >|                    d          }|                                D ]\  }	}
|                    |	|
d           dS dS )zsend shellvars via bundle2   =sI   unable to parse variable '%s', should follow 'KEY=VALUE' or 'KEY=' formatr   r  Fr\   N)r   r   r*   rZ   rl  r<   r  )r   rn  r   	shellvarsrawr   kr  r`   rB   rC   s              r6   _getbundlesendvarsr  b  s     H 7	 	 	C34  k#),,,99T1%%DAqIaLL{++#//++ 	7 	7JCMM#uM66667 7	7 	7r8   c                 T   t          j        | j        t          j        | j                            }| j        o| j                            dd          }t          j        t          j        | j	        |d                    }|
                    d|           g }t          D ]?}t          |         } || |          }t          |          r|                    |           @|j        dk    rdS t!          j        |                                          }	 	 | j                                        5 }	|	                    d	|d
g| j                                        d                                          }
ddd           n# 1 swxY w Y   n;# t.          j        $ r)}t/          j        t5          d          |z            d}~ww xY w	 d}|r| j        j        }t          j        | j	        |
|          }n# t.          j        $ r)}t/          j        t5          d          |z            d}~wt           j        $ r}| j                            t5          d          |z             |j        2| j                            t5          d          d|j        z  z             t/          j        t5          d                    d}~ww xY wnQ# t.          j        $ r?}tA          |j!                  }|| j"        vr  | j"        |         | |           Y d}~nd}~ww xY w|D ]} ||           dS )zpush data to the remote using bundle2

    The only currently supported type of data is changegroup but this will
    evolve in the future.rv   r      client)allowpushbackroles	   replycapsri  r   Nr      force)s   bundler     url   missing support for %ss   remote: %s
s   (%s)s   push failed on remote)#r   bundle20r.   r{  r   r   r   
encodecapsgetrepocapsrq   rl  ra  r`  callabler?   nbpartsr   chunkbuffer	getchunkscommandexecutorcallcommandr   resultr   BundleValueErrorRemoteErrorr   transactionprocessbundleAbortFromPartrQ   PushkeyFailedr  r  r   )r   rn  pushbackcapsblobreplyhandlerspartgennamepartgenr  streamereplyr  trgetterr   r  rephands                   r6   r   r   x  s   
 vy'*=fm*L*LMMG FI$8$8,% %H
 !FKxiPPP H OOLxO000M& & &#K0gfg&&C== 	&  %%%!g//1122F-	H..00 A#)#+* & 1 1 3 3   &((                % 	H 	H 	H#A&?$@$@3$FGGG	H	AH 8!+7&v{E8DDBB% 	H 	H 	H#A&?$@$@3$FGGG$ 	A 	A 	AIOOAo..4555x#	/ 2 2g6H IJJJ#A&>$?$?@@@		A   - - -SZ((,,,,,,,,	-
 !   s   F 0AF5F FF F	F K G$G  GK 	+G5 4K 5K$H((K:BJ>>KK L5LLc                 >   d| j         v rdS | j                             d           t          |           sdS | j                            d          sJ | j                            |            | j        }d}| j        8|j	        s1| j        j
        j        s t          j        | j        |ddd|          }nt          j        | j        |dd|          }| j        rd	g}n| j        }| j                            ||| j                                                  | _        dS )
z7Make the actual push of changeset bundle to remote repor  Nr   rO   r  T)fastpathr  r  r  )r   r  r]  r   r   rq   r  rp   r   rU  rm   filteredrevsr
   makechangegroupr   r   unbundler   r   )r   rp   r  cgr   s        r6   r   r     sC   (((
'''f%%  =  -----
K$$V,,,HJ{ #[2? 
 (K!
 
 
 (K5'j
 
 
 | )j( m,,Rfkoo>O>OPPFOOOr8   c           
        	 | j         }t          | j        d          }| j                            dd          r#|r!| j        |                    dd          rddi}|st          | |           dS t          j	        | j
        ||          }|\  	}|                    dd          rt          | |           n+t          | 	           t          | |t          j                   | j        rd| j        v rdS | j        }n| j        }| j                            d           	fd|D             }|D ]}| j                                        5 }|                    d	d|                                d
t          j        z  d
t          j        z  d                                          }ddd           n# 1 swxY w Y   |s*| j                            t-          d          |z             dS )z2synchronise phase information locally and remotelyrz   r  r  Nr{   Fs   Truec                 @    g | ]}|                                 v|S rh   r   )ri   r   pheadss     r6   rl   z"_pushsyncphase.<locals>.<listcomp>  s+    BBB!166886+A+AA+A+A+Ar8   r  r  r  r  r  r  r  )r   r~   r   r.   r   r   r   _localphasemover   analyzeremotephasesrq   r  r   r   r   r  r  r  r   r  r  r   r   )
r   r   r   anar   outdatedr  r  rr(  s
            @r6   r   r     sf   FFM955L	U$56600 O#]E22 $ &w/ *''''' (flKKM511 	:FF++++FF+++FFFL999 ? 	5F,,,,HH4HY''' CBBBxBBB% 	 	M..00 	AMM&/ - 1 1 3 3 % 4 % 5	   &(( 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  	899MI  	 	s   AF..F2	5F2	c                       j         r5t          j         j         j                                         |           dS  fd|D             }t          j                 }|r, j                            t          d          |z             dS dS )z0move <nodes> to <phase> in the local source repoc                 Z    g | ]'}j         |                                         k     %|(S rh   )rq   r  )ri   rj   r  r   s     r6   rl   z#_localphasemove.<locals>.<listcomp>/  s5    JJJQ56;q>3G3G3I3I+I+Iq+I+I+Ir8   s8   cannot lock source repo, skipping local %s phase update
N)	r   r   advanceboundaryrq   r  
phasenamesr.   r  r   )r   r.  r  actualmovesphasestrs   ` `  r6   r*  r*  %  s     K)5577	
 	
 	
 	
 	
 KJJJJ%JJJ$U+ 	I/  	    	 	r8   c           	         d| j         v rdS | j        }| j        }| j                             d           | j        r| j                            d           g }t          j        | j                  }t          j
        |          }t          |d          D ]5}||         }|                    |                    d|d|                     6d |D             r-t          d	          }|j                            |           dS dS dS )
z5utility function to push obsolete markers to a remoterS   Ns'   try to push obsolete markers to remote
Treverser'  r8   c                     g | ]}||S rh   rh   )ri   r.  s     r6   rl   z!_pushobsolete.<locals>.<listcomp>K  s    &&&!A&A&&&r8   s&   failed to push some obsolete markers!
)r   rq   r   r  r   r.   r   r   r  r   _pushkeyescaper;   r?   r   r   r   )	r   rq   r   rsltsr  
remotedatarB   rj  r   s	            r6   r   r   ;  s"   (((;D]F
''' 	CDDD'(<==,W55
*d333 	F 	FCc?DLLS#tDDEEEE&&u&&& 	>??CGLL 	 	r8   c                 `   | j         dk    s	d| j        v rdS | j                            d           | j        }| j        }| j        D ]\  }}}d}|sd}n|sd}|                                5 }|                    dd|t          |          t          |          d          	                                }ddd           n# 1 swxY w Y   |r*|
                    t          |         d         |z             |                    t          |         d	         |z             | j        d	| _        dS )
z"Update bookmark position on remoter   r0  Nr   r   r   r  r)  r   )r   r   r  r.   r   r   r  r  r   r  r  r  r   r   )	r   r.   r   r^   r  r  r  r  r.  s	            r6   r   r   P  s   !|v/???
&&&	B]F* $ $3 	FF 	F##%% 		".HHHH	   fhh 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		  	$IIj(+a/0000GGJv&q)A-...*"#1$ $s   +AB??C	C	c                       e Zd ZdZ	 	 	 	 	 	 	 	 	 d
dZej        d             Zej        d             Zej        d             Z	d	 Z
dS )pulloperationzA object that represent a single pull operation

    It purpose is to carry pull related state and very common operation.

    A new should be created at the beginning of each pull and discarded
    afterward.
    NFrh   c                 4   | _         || _        || _        || _        fd|D             | _        || _        || _        d | _        d | _        d | _	        d | _
        || _        d | _        t                      | _        d| _        || _        |	| _        |
| _        d S )Nc                 D    g | ]}j                             |          S rh   r4  r7  s     r6   rl   z*pulloperation.__init__.<locals>.<listcomp>  s6     "
 "
 "
5=DO&&x00"
 "
 "
r8   F)rq   r   remote_pathro   explicitbookmarksr   streamclonerequestedr   rr   rheadsfetchremotebookmarksr   r   r   clonebundleattemptedincludepatsexcludepatsdepth)r   rq   r   ro   r   r   rF  rC  rH  rI  rJ  paths    `          r6   r   zpulloperation.__init__|  s     	  
"
 "
 "
 "
AJ"
 "
 "
 
$8!
.$)!&&


r8   c                     | j         Mt          | j                  }t          | j                  }| j        D ]}||vr|                    |           |S | j         S )z0heads of the set of changeset target by the pull)ro   r   rr   r  rD  r?   )r   r   r  rj   s       r6   pulledsubsetzpulloperation.pulledsubset  se     : DK  At{##C[ " "A::JJqMMMJ :r8   c                 "    t          |            S r   )r   r   s    r6   canusebundle2zpulloperation.canusebundle2  s     &&&&r8   c                 4    t          j        | j                  S r   )r   r{  r   r   s    r6   remotebundle2capszpulloperation.remotebundle2caps  s    "4;///r8   c                 4    | j                                         S r   )r   r  r   s    r6   gettransactionzpulloperation.gettransaction  s    ~))+++r8   )	NFrh   NNNNNN)r   r   r   r   r   r   r   rM  rO  rQ  rS  rh   r8   r6   r>  r>  s  s          !5 5 5 5n 
  " 
' ' ' 
0 0 0, , , , ,r8   r>  c                   *    e Zd ZdZd Zd Zd Zd ZdS )r   zAn object to manage the life cycle of a transaction

    It creates the transaction on demand and calls the appropriate hooks when
    closing the transaction.c                 >    || _         || _        || _        d | _        d S r   )rq   sourcer   _tr)r   rq   rV  r   s       r6   r   ztransactionmanager.__init__  s"    	r8   c                     | j         sjd| j        t          j        | j                  fz  }| j                            |          | _         | j        | j         j        d<   | j        | j         j        d<   | j         S )z<Return an open transaction object, constructing if necessarys   %s
%s   sourcer  )rW  rV  r   hidepasswordr   rq   r  hookargs)r   trnames     r6   r  ztransactionmanager.transaction  sj    x 	1$+w/CDH/M/M!NNFy,,V44DH+/;DHi((,DHf%xr8   c                 J    | j         | j                                          dS dS )zclose transaction if createdN)rW  closer   s    r6   r^  ztransactionmanager.close  s*    8HNN  r8   c                 J    | j         | j                                          dS dS )zrelease transaction if createdN)rW  releaser   s    r6   r`  ztransactionmanager.release  s,    8H  r8   N)r   r   r   r   r   r  r^  r`  rh   r8   r6   r   r     sZ           
      
    r8   r   c                     |                                  5 }|                    dd|i                                          cd d d            S # 1 swxY w Y   d S )N   listkeysr  )r  r  r  )r   	namespacer  s      r6   r~   r~     s    				!	! NQ}}[<*CDDKKMMN N N N N N N N N N N N N N N N N Ns   *AAAc                    |                                  j        fd}fd}	                                 }t                    }t	          |           t
          j        | j        v rd S |t                    k    rd S t          fd|j        D                       rd S  |                                |          } |||j	                  |_	        t          |j                  |j	        z
  |_        )Nc                 J                         d| |          }d |D             S )zReturns heads(h1 % h2)s   heads(%ln %% %ln)c                 6    h | ]}|                                 S rh   r   ri   r  s     r6   r9  z8_fullpullbundle2.<locals>.headsofdiff.<locals>.<setcomp>       ***s

***r8   r   h1h2resr   s      r6   headsofdiffz%_fullpullbundle2.<locals>.headsofdiff  s-    hh+R44**c****r8   c                 J                         d| |          }d |D             S )zReturns heads((h1 + h2) - null)s   heads((%ln + %ln - null))c                 6    h | ]}|                                 S rh   r   rg  s     r6   r9  z9_fullpullbundle2.<locals>.headsofunion.<locals>.<setcomp>  rh  r8   ri  rj  s      r6   headsofunionz&_fullpullbundle2.<locals>.headsofunion	  s-    hh3R<<**c****r8   Tc              3   B   K   | ]}                     |          V  d S r   )rk   )ri   rj   unficls     r6   r   z#_fullpullbundle2.<locals>.<genexpr>  s/      88Qv~~a  888888r8   )r   rm   ro   r   _pullbundle2r   NARROW_REQUIREMENTallrD  rr   r   )	rq   pulloprn  rq  	old_headsclstart	new_headsr   rs  s	          @@r6   _fullpullbundle2r{    s    ??D^F+ + + + +
+ + + + +
;LLNN	f++V*d.???
 Ec&kk!!E8888&-88888 	EK	::	$Y>>FM**V]:!;r8   c                     |j                                         }t          j        | |dd           t	          j        |                                           fd}|                    d|           dS )zadds a finalize callback to transaction which can be used to show stats
    to user and confirm the pull before committing transaction   pullT)txnnameas_validatorc                                  }t          d          }|j                            |          rt          j        d          d S )Ns+   accept incoming changes (yn)?$$ &Yes $$ &Nos   user aborted)r   r.   r   r   r*   )trrq   cmreporefs      r6   promptz$add_confirm_callback.<locals>.prompt+  sN    wyy=>>7## 	/+o...	/ 	/r8   s   900-pull-promptN)r   r  r   registersummarycallbackweakrefrefr   addvalidator)rq   rw  r  r  r  s       @r6   add_confirm_callbackr  !  s     
		%	%	'	'B#b'    k$//++,,G/ / / / / OO&/////r8   c                    |i }|s|	r!|pt                      }|	pt                      }	n
| j        \  }}	t          j        |           t          j        |	           t	          | |f|||||||	|
dt          j        |          }|j                                        }|rit          |j	                  |j
        j        z
  }|rFt          d          d                    t          |                    z  }t          j        |          | j        D ]n}| j                                        D ]\  }}|                    |          r n7t          j        t          d          t          j        |          z            ot/          | d|                                          |_        t5          j                    }t9          j        |           s|                                 }|5  |                                 5  |j        5  |s4| j         !                    dd          r)| j         "                                stG          | |           tI          |           tK          j&        |           tO          |           |j(        rtS          | |           tU          |           tW          |           tY          |           t[          |           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   | j         !                    dd	          rt]          j/        | |           |S )
a  Fetch repository data from a remote.

    This is the main function used to retrieve data from a remote repository.

    ``repo`` is the local repository to clone into.
    ``remote`` is a peer instance.
    ``heads`` is an iterable of revisions we want to pull. ``None`` (the
    default) means to pull everything from the remote.
    ``bookmarks`` is an iterable of bookmarks requesting to be pulled. By
    default, all remote bookmarks are pulled.
    ``opargs`` are additional keyword arguments to pass to ``pulloperation``
    initialization.
    ``streamclonerequested`` is a boolean indicating whether a "streaming
    clone" is requested. A "streaming clone" is essentially a raw file copy
    of revlogs from the server. This only works when the local repository is
    empty. The default value of ``None`` means to respect the server
    configuration for preferring stream clones.
    ``includepats`` and ``excludepats`` define explicit file patterns to
    include and exclude in storage, respectively. If not defined, narrow
    patterns from the repo instance are used, if available.
    ``depth`` is an integer indicating the DAG depth of history we're
    interested in. If defined, for each revision specified in ``heads``, we
    will fetch up to this many of its ancestors and data associated with them.
    ``confirm`` is a boolean indicating whether the pull should be confirmed
    before committing the transaction. This overrides HGPLAIN.

    Returns the ``pulloperation`` created for this pull.
    N)rK  ro   r   r   rC  rH  rI  rJ  r   r   sD   sidedata category requested by local side without localsupport: '%s'r}  rx   rv   r   )0r   
narrowpatsr   validatepatternsr>  r   r   r   r   r   rq   r   r   r)   r;   r   r*   _wanted_sidedatar   r<   r   ProgrammingErrorr   r   r   r   r   r   r   r   r   r   r.   r   plainr  _maybeapplyclonebundler   maybeperformlegacystreamclone_pulldiscoveryrO  r{  _pullchangeset
_pullphase_pullbookmarks_pullobsoleter   r   )rq   r   rK  ro   r   r   r   rC  rH  rI  rJ  confirmrw  	peerlocalr   r   r   r   r   r   s                       r6   pullr  4  s4   T ~  3k 3!*SUU!*SUU#'? [,,,,,, 1  
V
$
$ F ##%%I #i,--0EE 	#  F7OO,,	.C
 +c""")    $7==?? 	 	OD)}}X&& 
 (%  "8,,	-  	  *$FFF#%%E#D)) 

	  		  V-   	/Gw
33	/<@GMMOO	/ !v... 	v&&&1&999v 	+T6***v6vf!                                            & w/>:: 2#D&111Ms[   $L9K0CKK0KK0 K!K0$L0K4	4L7K4	8LLLc                       fd}|S )a|  decorator for function performing discovery before pull

    The function is added to the step -> function mapping and appended to the
    list of steps.  Beware that decorated function will be added in order (this
    may matter).

    You can only use this decorator for a new step, if you want to wrap a step
    from an extension, change the pulldiscovery dictionary directly.c                 f    t           vsJ | t           <   t                                         | S r   )pulldiscoverymappingpulldiscoveryorderr?   r   s    r6   r   zpulldiscovery.<locals>.dec  r   r8   rh   r   s   ` r6   pulldiscoveryr    r   r8   c                 J    t           D ]}t          |         } ||            dS r  )r  r  )rw  r   r  s      r6   r  r    r  r8   s   b1:bookmarksc                     | j         dS | j        rd| j        v rdS t          | j        d          }t          j        |          | _         dS )zfetch bookmark data in bundle1 case

    If not using bundle2, we have to fetch bookmarks before changeset
    discovery to reduce the chance and impact of race conditions.Nrb  r0  )rF  rO  rQ  r~   r   r   r<  )rw  bookss     r6   _pullbookmarkbundle1r    s[     ) v/G G G 	V]L11E$7>>Fr8   rM   c                    t          j        | j        | j        | j        | j                  }|\  }}}| j                                        j        j        j	        }|rk|rit          |          }|D ]&} ||          r||vr|                    |           't          |                              t          |                    rg }|| _        || _        || _        dS )z~discovery phase for the pull

    Current handle changeset discovery only, will change handle all discovery
    at some point.)ro   r   N)r   r  rq   r   ro   r   r   rm   r   has_noder   r?   issubsetrr   rE  rD  )rw  tmprr   rE  rD  r  scommonrj   s           r6   _pulldiscoverychangegroupr    s     
&V]&,fl  C  FE6{%%''17@H   f++ 	% 	%Ax{{ %G##MM!$$$v;;F,, 	EFMFLFMMMr8   c                    dt          | j        d          i}| j        j        }t          j        | d          d         }| j        |d<   | j        p| j        |d<   | j        	                    t          j                  }|r| j        r
| j        |d	<   |r| j        r
| j        |d
<   |r?d|d<   d|d<   | j                            d           | j                            d           n| j                            d           | j        |d<   d|                    dd          v }d| j                            dd          v }|s!|rd|d<   | j                            d           d| j        v rd| j        vrdg|d<   d}d|                    dd          v }d| j        v }	| j        | j                            d           d| j        vr| j        |s	|	rd|d<   d}d| j        v rLd| j        vrC| j                            d           |                    dg                               d           | j        	                    d          r4| j        -t/          | j                  | j        j        gk    r
| j        |d<   |r-| j        j                            t7          d                     n| j        s4| j        j                            t7          d                     d| _        nV| j        Ot/          | j                  | j        j        gk    r,| j        j                            t7          d                     t;          j        | j        t:          j                  rLtA          j!        | j                  }
t;          j"        |
          d|d<   | j                            d           tG          | |           tA          j$        | j                  }|r||d<   | j        %                                5 }tM          |          }d|d<   |'                    d |          (                                }	 tA          j)        | j        | j*        d!          }d"|j+        d<   tA          j,        | j        ||#           n# t@          j-        $ r\}| j        j        .                    t7          d$          |z             t]          j/        t7          d%          |j0        &          d}~wt\          j1        $ r)}t]          j/        t7          d'          |z            d}~ww xY w	 ddd           n# 1 swxY w Y   | j        rtA          j2        |          | _        |j3        d         D ]\  }}|dk    rti          | |           |r+i }|j3        d         D ]}|d(         ||d)         <   || _        n2|j3        d         D ]$\  }}|dk    rtk          j6        |          | _        %| j        to          |            dS dS )*zNpull data using bundle2

    For now, the only supported data are changegroup.s
   bundlecapsr  r  T)r   r      commonr  s   includepatss   excludepatsF   cgr!   rM   rz   r   r   rh   rb  r0  Ns   request-bookmarks   clonebundless   cbattempteds   streaming all changes
   no changes found
   requesting all changes
rS   s   remote_sidedatar}  rY  	   getbundle)rV  s   recordsr   s   remote: abort: %s
s   pull failed on remoterP   r  s   nodes   bookmark)8
caps20to10rq   r.   r   canperformstreamclonerr   ro   rD  r   r   r   	NARROWCAPrH  rI  r   r  rE  r   rQ  r   rF  
setdefaultr?   r  rn   rG  r  r   r   r   r*  r+  r   r  r  _pullbundle2extrapreparer   r  dictr  r  bundleoperationrS  modesr  r  r   r  rQ   r  combinechangegroupresultsr  _pullapplyphasesr   r<  r  )rw  kwargsr.   	streamingservernarrowr  hasbinaryphasebookmarksrequestedlegacybookmarkhasbinarybookr  r  r  argsbundler   r  rc  rC   r  records                        r6   rt  rt    s    Z)DDDEF 
B 1&$GGGJI F9|4v}F8 =(()ABBL 4* 4!'!3~ 4* 4!'!3~ 2u y^,,,Y'''' 	^,,,u2==;M#N#NN!V%=%A%A)R%P%PP 	,~ 	, $F9  +++&222 000'0k{#!R]]8=O%P%PPN F$<<M)1222 	F$444"* + +  $|!f...v'777   !5666k2..55lCCC 	o..=L FK$6#777!'!<~ Ba :;;<<<<\ Ba 566777<D$7$7FK<N;O$O$OKN!!!$?"@"@AAA&+x';<< 0 263KLL!.11=$(F=!  ///VV,,,9&-HHO 5%4!"		&	&	(	( HAF||!Y|T2299;;
	H(V27  B &0BH\"!&+v"=====$ 	P 	P 	PKN  #9!:!:S!@AAA#A&>$?$?chOOOO% 	H 	H 	H#A&?$@$@3$FGGG	H	 >H H H H H H H H H H H H H H H" | @!;B?? J{3 , ,	5	!!VU+++  Kj. 	9 	9F)/E&%&&!& "
; 7 	K 	KIuL(()0)CE)J)J& )v *)sD   6=T-4AQ<;T-<TAS""T4$TTT--T14T1c                     dS )z>hook function so that extensions can extend the getbundle callNrh   )rw  r  s     r6   r  r    s      r8   c                 <   d| j         v rdS | j                             d           | j        s5| j        j                            t          d                     d| _        dS |                                 }| j	        Pt          | j                  | j        j        gk    r-| j        j                            t          d                     n-| j	        &| j                            d          r| j        | _	        | j                            d          r0| j                            d| j        | j	        p| j        	          }n| j	        b| j                                        5 }|                    d| j        dd
                                          }ddd           n# 1 swxY w Y   n| j                            d          s!t)          j        t          d                    | j                                        5 }|                    d| j        | j	        dd                                          }ddd           n# 1 swxY w Y   t-          j        | j        ||d| j                                                  }t-          j        |          | _        dS )z0pull changeset from unbundle into the local reporM   Nr  r   r  s   changegroupsubsetr  r}  rr   ro   )s   nodesrY  sW   partial pull cannot be done because other repository doesn't support changegroupsubset.)s   basesr  rY  )r   r  rE  rq   r.   r  r   r   rS  ro   r  rr   rn   r   r   rD  	getbundler  r  r  r   r*   r   applybundler   r  )rw  r  r%  r  bundleops        r6   r  r    s   
 )))
(((< a 566777				 	 B|V] 3 38J7K K Ka ;<<====		&-"7"78L"M"M	}}\**  ]$$FM1N % 
 
 
	]**,, 	$l&   fhh 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]""#788 k& 
 
 	
 ]**,, 	$$l$l&   fhh 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 "RWfm&7&7&9&9 H 7AAFOOOs$   $1F!!F%(F%7IIIc                 f    d| j         v rd S t          | j        d          }t          | |           d S )Nrz   )r   r~   r   r  )rw  r   s     r6   r  r    s<    F$$$FM955LV\*****r8   c                   	
 d| j         v rdS | j                             d           t          |                    dd                    }|r-|s+t	          j        | j        | j        |          \  }}| j        }n	| j        }g }| j                                        j	        j
        j        j        j        
t          j        	t          j        	
fd|D             }|r0|                                 }t	          j        | j        |	|           
fd|D             }|r2|                                 }t	          j        | j        ||           dS dS )z/apply phase movement from observed remote staterz   Nr{   Fc                 F    g | ]}  |                    k    |S rh   rh   )ri   pnr  r  r   r   s     r6   rl   z$_pullapplyphases.<locals>.<listcomp>  s7    CCCRUU4R%9%9F%B%Bb%B%B%Br8   c                 F    g | ]}  |                    k    |S rh   rh   )ri   r  r  r  r   r   s     r6   rl   z$_pullapplyphases.<locals>.<listcomp>  s7    BBBRUU4R%9%9E%A%Ab%A%A%Ar8   )r   r  rx  r   r   r+  rq   rM  r   _phasecacher  rm   r   get_revr  r  rS  r1  )rw  r   r  r(  _drdheadsr  r  r  r  r   r   s          @@@@@r6   r  r    s   F$$$
###l&&}e<<==J 
J 
0K,l
 
 $ $;!!##D"E
.

&C]FLE DCCCCCC6CCCF @""$$v{B??? CBBBBBB6BBBF ?""$$v{Bv>>>>>? ?r8   c           	         d| j         v rdS | j                             d           | j        }| j        }d}| j        | j        j        }t          j        |j        ||| j	        
                                | j        | j        |           dS )z?process the remote bookmark information to update the local oner0  N)rA  mode)r   r  rq   rF  rA  bookmarks_moder   updatefromremoter.   r   r   rS  rB  )rw  rq   rF  r  s       r6   r  r    s    v'''
&&&;D,ON%+:)     r8   c                 l   d| j         v rdS | j                             d           d}t          j        | j        t          j                  r| j        j                            d           t          | j	        d          }d|v r| 
                                }g }t          |d          D ]M}|                    d          r6t          j        ||                   }t          j        |          \  }}||z  }N|r | j        j                            ||           | j                                         |S )	aV  utility function to pull obsolete markers from a remote

    The `gettransaction` is function that return the pull transaction, creating
    one if necessary. We return the transaction to inform the calling code that
    a new transaction have been created (when applicable).

    Exists mostly to allow overriding for experimentation purposerS   Ns!   fetching remote obsolete markers
r'  s   dump0Tr6  s   dump)r   r  r   r*  rq   r+  r.   r   r~   r   rS  r;   r'   r   	b85decode_readmarkersr,  invalidatevolatilesets)rw  r  	remoteobsr  rB   rj  r5   newmarkss           r6   r  r    s7    (((
'''	B&+x';<< 1BCCCV]K88	y  &&((BGi666 ( (>>'** (>)C.99D(0(=d(C(C%GXx'G 6$((W555K..000Ir8   c                    | j         }|                    |j                            d          p|                                          }|                    t          |dz   |                    t          d                    }|                    t          |dz   |                    t          d                    }|s+t          j        t          d          t          |fz            d |D             }d |D             }t          |                    d	g                     }t          |                    d
g                     }t          j        ||||          \  }}}|r8t          j        t          d          |t          j        |          fz            i }	|	                    |           d|	d<   d|	d<   ||	d	<   |r||	d
<   |	S )zApply narrow fetch access control.

    This massages the named arguments for getbundle wire protocol commands
    so requested data is filtered through access control rules.
    s   REMOTE_USERs	   .includess   default.includess	   .excludess   default.excludess%   %s configuration for user %s is emptyc                 (    g | ]}|d k    rdnd|z   S    *s   path:.s   path:rh   r  s     r6   rl   z"applynarrowacl.<locals>.<listcomp>J  5       56Q$YY		HqL  r8   c                 (    g | ]}|d k    rdnd|z   S r  rh   r  s     r6   rl   z"applynarrowacl.<locals>.<listcomp>M  r  r8   rH  rI  s4   The following includes are not accessible for %s: %sTnarrow
narrow_acl)r.   	shortuserenvironr   usernamer   _NARROWACL_SECTIONr   r*   r   r   r   restrictpatternsr   pprintupdate)
rq   r  r.   r  user_includesuser_excludesreq_includesreq_excludesinvalid_includesnew_argss
             r6   applynarrowaclr  1  s    
B||BJNN>::KbkkmmLLHMM<
(*=>> M
 MM<
(*=>> M
  
k677!8,-
 
 	

 :G  M :G  M vzz-4455Lvzz-4455L3=3NlM=4 40L, 0  
kEFF*+;<<=>
 
 	

 HOOFHX!H\*H] /".Or8   c           
            j          j        }j        fd|D             t          hz  }fd|D             }|rd |D             }	t	          j        t                    }
t	          j        t                     fd}fd  fdt                              ||                    }t          |          }t                      }fd|D             }t          |          |z  }|D ]V}
                    |          d	                     |          D             }|:|	|         }|D ]/}t          |dz   |	                    ||dz                       |	|<   0d}|d
u p|	|         |k    }|r|j                                                 }|r|
                    |d                   j                                                 }t!          |                    ||                    }|snt%          |          dk    r[|
                    |d                   j                                                 }t!          |                    ||                    }n"t'          |                    |                    }|r[|
|         D ]} |||           |D ]}|                    |           |                                        |                     |st          g}||v r9|
|         D ]} |||           |D ]}|
|                             |           ;|D ]}|
|xx         |
|         z  cc<   X|D ]}|
|         D ]} |||           ||fS )a  Compute the shape of a narrowed DAG.

    Args:
      repo: The repository we're transferring.
      common: The roots of the DAG range we're transferring.
              May be just [nullid], which means all ancestors of heads.
      heads: The heads of the DAG range we're transferring.
      match: The narrowmatcher that allows us to identify relevant changes.
      depth: If not None, only consider nodes to be full nodes if they are at
             most depth changesets away from one of heads.

    Returns:
      A tuple of (visitnodes, relevant_nodes, ellipsisroots) where:

        visitnodes: The list of nodes (either full or ellipsis) which
                    need to be sent to the client.
        relevant_nodes: The set of changelog nodes which change a file inside
                 the narrowspec. The client needs these as non-ellipsis nodes.
        ellipsisroots: A dict of {rev: parents} that is used in
                       narrowchangegroup to produce ellipsis nodes with the
                       correct parents.
    c                 &    h | ]} |          S rh   rh   ri   rj   clrevs     r6   r9  z#_computeellipsis.<locals>.<setcomp>  s!    +++q%%((+++r8   c                 &    h | ]} |          S rh   rh   r  s     r6   r9  z#_computeellipsis.<locals>.<setcomp>  s!    )))aq)))r8   c                     i | ]}|d S )r   rh   r  s     r6   r  z$_computeellipsis.<locals>.<dictcomp>  s    ,,,QAq,,,r8   c                     |                               |           t          |                    dk    r8 |           \  }} | ||           |} t          |                    dk    6dS dS )z=Add a root to an ellipsis head, splitting heads with 3 roots.r#   N)r  r   )head	curchangechildrootsellipsisroots	splithead
splitrootss       r6   addrootz!_computeellipsis.<locals>.addroot  s    d	***
 -%&&**$9T??LE5JtUE***D -%&&******r8   c                     |                               |           |                              |           |                             |           |                             |           d S r   )difference_updater  r  discard)r  r  r  r   s      r6   r  z$_computeellipsis.<locals>.splitroots  sm    d--e444d&&&e##E***e$$U+++++r8   c                 R   t          |                    \  }}}||f||f||ffD ]Z\  }}	                    d|| ||           }|D ]9}||k    r
|||ffc c S |vst          |                   dk     r
|||ffc c S :[t          j        t          d          | |||fz            )Ns%   sort(merge() & %d::%d & %d::%d, -rev)r#   s;   Failed to split up ellipsis node! head: %d, roots: %d %d %d)r;   r   r   r   r*   r   )
r  r1r2r3nr1nr2midjr   rq   s
           r6   r  z#_computeellipsis.<locals>.splithead  s   M$/00
BbB8b"X6 	) 	)HC))8#tS$ C  ) )88c
?*****M))Sq1A-B-BQ-F-FsCj=((((( .G)
 k#  RR 	!
 
 	
r8   r  c                 :    g | ]}                     |          S rh   r   )ri   mrs   s     r6   rl   z$_computeellipsis.<locals>.<listcomp>  s#    ..."''!**...r8   c                 (    g | ]}|t           k    |S rh   )r   )ri   prevs     r6   rl   z$_computeellipsis.<locals>.<listcomp>  s    EEEtTW__d___r8   Nr   Fr   )rm   manifestlogr   r   collectionsdefaultdictr   r  findmissingrevsreversedchangelogrevision
parentrevsminr   r  readrx  diffr   r  walkr  r   )!rq   rr   ro   knownmatchrJ  mfl
commonrevs	headsrevsrevdepthellipsisheadsr  r   visitrelevant_nodes
visitnodesrequiredr   pscurdepthr  neededshallow_enoughcurmfp1mfp2mfr  r   rs   r  r   r  r  s!   `                           @@@@@r6   _computeellipsisr0  i  sJ   . 
B

CFE++++F+++wi7J))))5)))I -,,),,,+C00M+C00M
 
 
 
 
 
 
, , , , ,
 
 
 
 
 
& 2%%Zy%IIJJGWEUUN....g...J9~~%H -; -;$$S))EEr}}S11EEE}H L L!(Q,Q	0J0JKK$@(3-5*@ 	0',,..E 0 2//166?@EEGGejju5566 ;#b''A++
 r33BqE::CDIIKKD!%**T5"9"9::F UZZ..// 	;%c* # #c""""    Qrwws||,,,, Yh)#. ' 'DGD#&&&& . .A!!$((----.  ; ;A!!$$$c(::$$$$;   !!$ 	 	DGD!	~}44r8   c                     dh}t          j        t          j        | |                    }|                    dt                              |          z              |S )zFreturn a set with appropriate options to use bundle20 during getbundles   HG20r     bundle2=)r   r  r  r  r=   r>   )rq   r  capsr  s       r6   r  r    sQ    9D!'"5d"F"F"FGGHHH[6<<111222Kr8   c                       fd}|S )a  decorator for function generating bundle2 part for getbundle

    The function is added to the step -> function mapping and appended to the
    list of steps.  Beware that decorated functions will be added in order
    (this may matter).

    You can only use this decorator for new steps, if you want to wrap a step
    from an extension, attack the getbundle2partsmapping dictionary directly.c                     t           vsJ | t           <   t                                         nt                                         | S r   )getbundle2partsmappinggetbundle2partsorderr?   rb  rc  s    r6   r   z%getbundle2partsgenerator.<locals>.dec		  sW    55555+/x(; ''1111 ''X666r8   rh   re  s   `` r6   getbundle2partsgeneratorr8    rg  r8   c                 <    | t          d | D                       S dS )Nc              3   @   K   | ]}|                     d           V  dS )s   HG2N)r'   )ri   caps     r6   r   z#bundle2requested.<locals>.<genexpr>	  s.      @@c3>>&))@@@@@@r8   F)r  r!  s    r6   bundle2requestedr<  	  s*    @@Z@@@@@@5r8   c           	         t          j        |          }i }t          |          }|s|r2|                    dd          st	          t          d                    |rQt	          t          d          d                    t          |                                                    z            t          | ||          }	d|d<   |t          j        | |	d|||	          fS d
|d<   i }
|D ]m}|                    d          rVt                              |t          d          d                   }|
                    t#          j        |                     nt#          j        | j        |
          }||d<   ||d<   t*          D ]0}t,          |         } ||| |f||
|dt          j        |           1|j        |d<   ||                                fS )a  Return chunks constituting a bundle's raw data.

    Could be a bundle HG10 or a bundle HG20 depending on bundlecaps
    passed.

    Returns a 2-tuple of a dict with metadata about the generated bundle
    and an iterator over raw chunks (of varying sizes).
    r  Ts-   request for bundle10 must include changegroups#   unsupported getbundle arguments: %sr   r   s   bundleversionrO   r  r#   r2  Nr  r  )r  r}  r  s   prefercompressed)r   byteskwargsr<  r   
ValueErrorr   r)   r;   keysrt   r
   r  r'   r=   rY   r   r  r   
decodecapsr  r.   r7  r6  r   prefercompressedr  )rq   rV  ro   rr   r  r  r  info
usebundle2rp   r}  bcapsblobrn  namer   s                   r6   getbundlechunksrH  	  s4   " !&))FD!*--J 
 	fjj55 	BCC    	899**VFKKMM22334   $D%88!""% /  

 
	
 D	F 4 4K(( 	4>>%K(8(8(:(:";<<DMM',T22333tw//GF8F9$ 

 

%d+	
 "+	
 	
  ((	
 	
 	
 	
 !( 8D	""$$$$r8   rR   c                 (    t          j        | |fi |S r   )r   addpartbundlestream2)rn  rq   r  r  s       r6   _getbundlestream2rK  f	  s    '@@@@@r8   c           	      F   |                     dd          r|sdS d}	|                     d          }
|
r@fd|
D             }
|
s!t          j        t          d                    t	          |
          }	t          ||          }|j        sdS |                     dd	          rt          t          t          |                     d
g                               }t          t          t          |                     dg                               }t          j        j        ||          }nd}t          j        ||	||||          }|                     d|          }|
r|                    d|	           |                    ddt#          |j                  z  d	           t%          j                  r|                    dd           t(          j        j        v r@|                    dd           t/          j                  }|                    d|           |                     dd	          rc|                     dd	          rO|s|rM|                     d          }dd                    |          d                    |          fz  |_        dS dS dS dS )z.add a changegroup part to the requested bundler%  TNrO   rM   c                 @    g | ]}|t          j                  v |S rh   )r
   r  )ri   r  rq   s     r6   rl   z-_getbundlechangegrouppart.<locals>.<listcomp>~	  s9     
 
 
K9$???? ???r8   r  r  FrH  rI  )includeexclude)r  matcherr  ri  rN   s	   nbchangesr  r  r  r  r  s   exp-wanted-sidedatar  s   Narrow:responsespecs   %s %s   
)r   r   r*   r   r  rt   r   r;   filterrx  r   r  rootr
   r  rl  r  r   r   r  r   r  r  r   format_remote_wanted_sidedatar)   rj  )rn  rq   rV  r  r}  ro   rr   r  r  r5   r  rp   rN  rO  rP  r  r`   sidedatanarrowspecparts    `                 r6   _getbundlechangegrouppartrW  k	  s    ::dD!!  GN++J "
 
 
 

 
 


  	C+a @AABBBj//eV44H zz(E"" fjj&C&CDDEEfjj&C&CDDEE"49gwOOO%'  H ??>?99D +j'***MM,H,<(=(= =MOOOd## -ot,,,(DM99ot,,,8>>,h777 	

8U##

JJ|U++

 

  

 !)?@@'JJwJJw+
 


 

 

 

 

 

r8   c                    |                     dd          sdS |rd|vr!t          j        t          d                    t	          j        |          }t	          j        ||          }|r|                     d|           dS dS )z+add a bookmark part to the requested bundler   FNr0  s#   no common bookmarks exchange methodri  )r   r   r*   r   r   listbinbookmarksr|  rl  )rn  rq   rV  r  r}  r  r  rj  s           r6   _getbundlebookmarkpartrZ  	  s    
 ::k5))  E\//k!BCCDDD$T**Ee,,D 14000001 1r8   rb  c                    |                     dd          }|D ]m}|                     d          }|                    d|           |                    |                                          }	t          j        |	          |_        ndS )z@add parts containing listkeys namespaces to the requested bundler~   rh   rb  r  N)r   rl  r  r~   r<   r   
encodekeysrj  )
rn  rq   rV  r  r}  r  r~   rc  r`   r@  s
             r6   _getbundlelistkeyspartsr]  	  s    
 zz*b))H - -	{++lI...}}Y''--//&t,,			- -r8   c                 (   |                     dd          r{||                                }d |                    d|          D             }|j                            |          }t          j        |          }t          j        | |           dS dS )z8add an obsolescence markers part to the requested bundle
obsmarkersFNc                 6    g | ]}|                                 S rh   r   r   s     r6   rl   z+_getbundleobsmarkerpart.<locals>.<listcomp>	  s     >>>q!&&((>>>r8   r)  )	r   ro   r   r,  r-  r   r  r   r  )	rn  rq   rV  r  r}  ro   r  subsetr  s	            r6   _getbundleobsmarkerpartrb  	  s    
 zz,&& 6=JJLLE>>DHHXu$=$=>>>-//77'00#GW555556 6r8   rz   c                 Z   |                     dd          r|rd|                     d          vr!t          j        t          d                    ||                                }t          j        t                    |                                r|t          j
        <   n?|j        j        }|j        j        }|j        j        }	|D ]0}
 || |	|
                                                 |
           1t#                                                    }|rt'          |          t          j        k    sJ                      t          j        t                                }|rx                     t          j
        t                                }d}|                    |||          }|D ]0}t          j
                                      ||                     1fdt          j        D             }t          j        |          }|                     d	|
           dS dS )z,add phase heads part to the requested bundler   Fr  rz   s    no common phases exchange methodNs"   heads(only(%ln, %ln) and public())c                 <    i | ]}|t          |                   S rh   )r;   )ri   r  headsbyphases     r6   r  z(_getbundlephasespart.<locals>.<dictcomp>	
  s5     
 
 
38E6,u-..
 
 
r8   r  ri  )r   r   r*   r   ro   r  r  r   r  r   r  r  r  rm   r   r   r  r  r@  r  r  r   r  r|  rl  )rn  rq   rV  r  r}  ro   r  r  r   r   r  
seenphases
draftheadsr  r   
extraheadsr.  phasemappingr  re  s                      @r6   _getbundlephasespartrj  	  s%   
 zz(E"" )8 	FI)>)>>>+a CDDEEE=JJLLE".s33?? 	=*/L'' $*E>&D.$C 9 9UU4Q00155a8888l//1122J  7:&,6666 &))&,>>J =*..v}ceeDD>!YYvz;GG
# = =A /33DDGG<<<<
 
 
 
<B<L
 
 

 '55	Y77777S)8 )8r8      hgtagsfnodesc                     |r|                     dd          rd|v sdS t          |||          }t          j        || |           dS )zTransfer the .hgtags filenodes mapping.

    Only values for heads in this bundle will be transferred.

    The part data consists of pairs of 20 byte changeset node and .hgtags
    filenodes raw values.
    r%  Trk  N)r   rt   r   addparttagsfnodescache	rn  rq   rV  r  r}  ro   rr   r  rp   s	            r6   _getbundletagsfnodesro  
  s\    *  &**T400 _5N5NeV44H"4(;;;;;r8   s   cache:rev-branch-cachec                     |                     dd          r;|r9d|vs5|                     dd          s|j                            t                    rdS t	          |||          }t          j        || |           dS )zTransfer the rev-branch-cache mapping

    The payload is a series of data related to each branch

    1) branch name length
    2) number of open heads
    3) number of closed heads
    4) open heads nodes
    5) closed heads nodes
    r%  Ts   rev-branch-cacher  FN)r   r.   has_sectionr  rt   r   addpartrevbranchcachern  s	            r6   _getbundlerevbranchcachers  .
  s    4 JJtT"" f,,::h&& -7122 - 	eV44H!$:::::r8   c                    |                                  }t          j        d                    t	          |                                                              }|dgk    s%||k    s!|d|gk    st          j        d|z            dS dS dS )zVcheck if the heads of a repo have been modified

    Used by peer for unbundling.
    r8   r  s   hasheds.   repository changed while %s - please try againN)ro   r   sha1r)   r;   digestr   	PushRaced)rq   their_headscontextro   
heads_hashs        r6   check_headsr{  T
  s    
 JJLLEsxxu6677>>@@Jz!!%9j111 o=G
 
 	
 	"!11r8   c           	          dg dd} j                             dd          }                    d          s                    d          rd}	 t           |d	           t	          |t
          j                  sd
                    t          j	                  g          } 
                                5                       |          5 }t          j         ||          }	t          j        |	          ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   nd	  fd}
 j                             dd          s
 |
             t          j         |
|d          }		 t          j         ||	          }	|	j        |r#! j                             dd           fd}n1# |	j        |r#! j                             dd           fd}w xY wd         d                                          n># t&          $ r1}d|_        |r"                                 x|_        fd} d}~ww xY wt/          j        d         d         d                    |" | j                                                    nR# t/          j        d         d         d                    |# | j                                                    w w xY wS )a  Apply a bundle to a repo.

    this function makes sure the repo is locked during the application and have
    mechanism to check that no push race occurred between the creation of the
    bundle and its application.

    If the push was raced as PushRaced exception is raised.r   NNNNrv   s   bundle2-output-captures   remote:http:s   remote:https:Ts   uploading changesrQ  c                  8    d         st          j                  s                                 d<                                    d<                                  d<    d         j        d<    d         j        d<   d d         j        d<    d         S )Nr#   r   r   rY  r  r  r   )r   r   r   r   r  r[  )	lockandtrrq   rV  r   s   r6   rS  z unbundle.<locals>.gettransaction
  s    $Q< A&7== 8+/::<<IaL'+yy{{	!'+'7'7'?'?	!;A	!-i88;	!-f5<@	!-j9$Q<'r8   s   bundle2lazylockingr  )captureoutputrV  r  )r   subprocc                 8                         d| d           d S Ns   outputF)rj  r\   )rl  )outputr.  s    r6   	recordoutzunbundle.<locals>.recordout
  s!    IIifINNNNNr8   r#   c                 `    t          j        d| d          }                    |           d S r  )r   
bundlepartr?   )r  r`   rA   s     r6   r  zunbundle.<locals>.recordout
  s;    &1%Fe      T*****r8   r   )r.   r   r'   r{  rT   r   rV   r)   r   rZ  r   r  r  r  r  r  r  
pushbufferr^  BaseExceptionduringunbundle2salvageoutput_bundle2salvagedoutputlockmodr`  	popbuffer)rq   r%  ro   rV  r   r  r  r~  r  r   rS  r  r  rA   r.  s   `  ``       @@@r6   r$  r$  g
  s4    	
A #""IIG&&2 M ~~o&& #..9I*J*J B+ 	D%!5666"g011 9	jj&'*>s*C*C!DEEG : :d..w77 :2(r2vsCC5b99: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : A1	( 	( 	( 	( 	( 	( 	( 	( w))#%:  % #N$$$,""/"	  O .tRB???BA$ O**t*DDDO O O O O	 A$ O**t*DDDO O O O O O O O O Q<+aL&&(((    &*#  +Q]9:9J9JJEC6+ + + + +  		!ilIaLAAA Idg''))*** 		!ilIaLAAA Idg''))**** !Hs   A(J ?D%-DD%D	D%D	D%J %D))J ,D)-J 5AH ;F? -H ?.G--%H J 
I,I		IJ AK-c                    | j         }| j        }|j                            dd          sdS t	          |          rdS | j        rdS |                    d          sdS |                                5 }|                    di           	                                }ddd           n# 1 swxY w Y   d| _
        t          j        ||          }|s)|j                            t          d                     dS t          j        ||| j                  }|sP|j                            t          d                     |j                            t          d                     dS t          j        |j        |          }|d	         d
         }|j                            t          d          |z             t)          |j        ||          r)|j                            t          d                     dS |j                            dd          r)|j                            t          d                     dS t+          j        t          d          t          d                    )z0Apply a clone bundle from a remote, if possible.r  r  NTsD   no clone bundles available on remote; falling back to regular clone
)rC  sO   no compatible clone bundles available on server; falling back to regular clone
s5   (you may want to report this to the server operator)
r   s   URLs   applying clone bundle from %s
s   finished applying clone bundle
s   clonebundlefallbacks   falling back to normal clone
s   error applying bundles}   if this error persists, consider contacting the server operator or disable clone bundles via "--config ui.clonebundles=false"rP   )rq   r   r.   r   r   ro   r   r  r  r  rG  r	   parseclonebundlesmanifestnoter   filterclonebundleentriesrC  r   sortclonebundleentriesr  trypullbundlefromurlr   r*   )rw  rq   r   r  rm  entriesr   s          r6   r  r  
  s    ;D]F7e_55  4yy | >>/** 				!	! :QmmOR007799: : : : : : : : : : : : : : :
 #'F4T3??G 3 	
 	
 	
 	3gF,G  G   	3 	
 	
 	
 	GHH	
 	
 	
 	1$'7CCG
!*V
CGNN17883>???DGT3// 
q<==>>>>> 
		E#9	:	: 
Q899:::::k&''4 
 
 
 	
s   1)B&&B*-B*c           	      0   |                                 5  |                    d          5 }	 t          j        | |          }t	          | |d          }t          |t          j                  r|                    |           nt          j
        |||d|           	 ddd           ddd           dS # t          j        $ rA}|                     t          d          t          j        |          z             Y d}~n[d}~wt          j        $ rF}|                     t          d          t          j        |j                  z             Y d}~nd}~ww xY w	 ddd           ddd           dS # 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	z%Attempt to apply a bundle from a URL.s	   bundleurlr!   r  NTs   HTTP error fetching bundle: %s
s   error fetching bundle: %s
F)r   r  urlmodopenr7   rT   r   r-   applyr   r  urlerr	httperrorr   r   r   r   urlerrorreason)r.   rq   r   r  r/   r%  r  s          r6   r  r    s   	  d&&|44 	R%%BBI..B"k<== H#D"b/3GGG               	 	 	GG566)!,,-         	 	 	GG011)!(334       	 +                                       sp   FE3A.B4F4E7C?:E3?E<EE3EE3F3E7	7F:E7	;FFFr   r   )
NNFrh   NNNNNN)NNNN)NNNNN)NNr}  )}r  r  i18nr   r   r   r    r   r   r   r	   r
   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r  r   r   utilsr   r   r   
interfacesr   r  r=   r  r7   rD   re   rt   r   r   r   r  r   r   r   r   r   r   r  r%  r/  rB  r>  r]  ra  r`  rf  rv  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r*  r   r   r>  transactionalr   r~   r{  r  r  r  r  r  r  r  r  rt  r  r  r  r  r  r  r  r0  r  r7  r6  r8  r<  rH  rK  rW  rZ  r]  rb  rj  ro  rs  r{  r$  r  r  rh   r8   r6   <module>r     s
                                                               ,         
 # " " " " "		! 
 
 
 
>  N= N= N=b3 3 3(#. #. #.L= = = A& A& A& A& A& A& A& A&N 	

#$$	
*++
 	

$%%	
+,,
 	

*++	
122 
& 	m m m mb  
    &  ( ( (& |  4 x;- ;- ;-| |G G G" |O O O(3 3 3l# # #N 
     ,C C C6   $%%8 8 &%8 /""= = #"=$ ,3 3  3l (5 5 5"8 8 8" " "J -  	6 	6 ! 	6 ,8 8  8  
 
 
  .- - -` +1%%%7 7 &%7*8 8 8v-Q -Q -Q`? ? ?D *0    ,  * $  $  $F\, \, \, \, \, \, \, \,~    +   @N N N
'; '; ';T0 0 0, 



| | | |@  
    &   ? ?  ? ~  @J J JZI I I8B 8B 8Bv+ + +!? !? !?H  *  :5 5 5pB5 B5 B5 B5J    
     ,   H% H% H% H%V *%%A A &%A .))
 
H
 H
 H
 *)H
V ,''371 1 1 ('1 +&&37	- 	- 	- '&	- -((?C
6 
6 
6 )(
6 )$$?C-8 -8 -8 %$-8` /**
 
< < < +*<6 344
 
"; "; "; 54";J
 
 
&V V VrO
 O
 O
d    r8   