
    6h                      S SK Jr  S SKrS SKrSSKJr  SSKJrJr  SSK	J
rJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r   SSK!J"r"J#r#J$r$  SSK%J&r&  \RN                  r'\RP                  r(S	r)SoS
 jr*S r+S r,S r-S r.S r/ " S S5      r0\" S5      \" S5      4\" S5      \" S5      4\" S5      \" S5      4S.r1      SpS jr2/ r30 r4S r5S r6S r7\5" S5      S 5       r8\5" S5      S  5       r9\5" S!5      S" 5       r:\5" S#5      S$ 5       r;S% r<S& r=/ r>0 r?SoS' jr@S( rAS) rB\@" S*5      S+ 5       rC\@" S,5      S- 5       rD\@" S5      S. 5       rE\@" S5      S/ 5       rFS0 rGS1 rH\@" S25      S3 5       rI\@" S#5      S4 5       rJS5 rKS6 rLS7 rMS8 rN\@" S9S S:9S; 5       rOS< rPS= rQS> rR\R                  4S? jrTS@ rUSA rV " SB SC5      rW " SD SE\R                  5      rYSF rZSG r[SH r\          SqSI jr]/ r^0 r_SJ r`SK ra\`" SL5      SM 5       rb\`" SN5      SO 5       rcSP rdSQ reSR rfSS rgST rhSU riSV rjSW rkSoSX jrlSY rm/ rn0 roSoSZ jrpS[ rq    SrS\ jrr\p" S]5      S^ 5       rs\p" SN5           SsS_ j5       rt\p" S#5       StS` j5       ru\p" Sa5       StSb j5       rv\p" S25       SuSc j5       rw\p" Sd5       SuSe j5       rx\p" Sf5          SrSg j5       ry\p" Sh5          SrSi j5       rzSj r{Sk r|Sl r}Sm r~Sn rg)v    )annotationsN   )_)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                   [         R                  " US5      nS nU(       dI  SnUR                  S5      (       d0  UR                  S5      (       a  [         R                  " X5      nSnSnOU(       a  UR	                  U5      nUSS USS pvUS:w  a"  [
        R                  " [        S	5      U-  5      eUS
:X  a0  Uc  [         R                  " US5      n[         R                  " X5      $ UR                  S5      (       a  [        R                  " XXg-   S9$ US:X  a  [        R                  " U5      $ [
        R                  " [        S5      X'4-  5      e)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
readbundler8   5   s2   $$R+F
C  ''F,=,=e,D,D,,R8BFC	Aa[&1+7~kk!9:UBCC%;))"a0C&&r//			D	!	!##BHH	E	--b11kk./52BB
 	
    c                    / n[        U R                  5       5       H/  u  p#[        R                  U5      nUR	                  SX#4-  5        M1     SR                  U5      $ )Ns   %s=%s   ;)sorteditemsurlreqquoteappendr*   )paramspartskeyvalues       r7   _format_paramsrE   T   sP    EV\\^,
U#X,- - 99Ur9   c                   S n0 n[        XS5      n[        U[        R                  5      (       aJ  UR                  nUS:X  a  SnU" U5      nU(       d"  [
        R                  " [        S5      U-  5      eSU-  $ [        U[        R                  5      (       Ga  SUR                  ;   a?  U" UR                  S   5      nU(       d"  [
        R                  " [        S5      U-  5      eOSnSnUR                  5        GH\  nUR                  S	:X  aQ  UR                  S
   n	U	S;   a  SnM-  U	S;   a  SnXS'   M;  [
        R                  " [        S5      U-  [        S5      S9eUR                  S:X  aS  UcP  [        R                  UR                  S   5      n
U
R                  " 5       n[        R                   " U5      nSU-  s  $ UR                  S:X  aS  UcP  [        R                  UR                  S   5      n
U
R                  " 5       n[        R                   " U5      nSU-  s  $ UR                  S:X  d  GM>  SUS'   UR"                  (       a  GMW  SUS'   GM_     U(       d  SUS	'   SnSXg4-  nU(       a  US-  nU[%        U5      -  nU$ [        U[&        R(                  5      (       a4  [&        R*                  " U5      S   n
[        R                   " U
5      nSU-  $ [
        R                  " [        S 5      U-  5      e)!zInfer the bundlespec from a bundle file handle.

The input file handle is seeked and the original seek position is not
restored.
c                     [         R                  R                  U 5      R                  5       S   $ ! [         a     g f = fNr   )r   compenginesforbundletype
bundletypeKeyError)r4   s    r7   speccompression&getbundlespec.<locals>.speccompressionc   s>    	##11#6AACAFF 		s   /2 
??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hints   stream2s   requirementss   none-v2;stream=v2;%ss   stream3-exps   none-v2;stream=v3-exp;%s
   obsmarkerss   yess   obsolescences   nos   obsolescence-mandatorys   %s-%sr;   r$   s   none-packed1;%ss   unknown bundle type: %s)r8   
isinstancer   r,   _typer   r+   r   r	   
unbundle20rA   	iterpartstyper>   unquotesplit_formatrequirementsparams	mandatoryrE   r   r.   readbundle1header)r/   r0   rM   rA   br4   compr6   part	cgversionr   splittedspec	formatteds                 r7   getbundlespecrf   \   s    F24 A![,,--gg/!Cs#++a DEKLL$	Aw))	*	*QXX%"188N#;<Dkk:;dB  
 DKKMDyyN* KK
3	.#G(*#G,5=)++2 "	"
 EF  j(W_%~~dkk/.JK'--/ ::8D.77n,%~~dkk/.JK'--/ ::8D2V;;m+*0'~~~8=F45A "D %*F>"G4/)DLDN6**D	A{55	6	6"44R8;55lC	!I--kk!67!;<<r9   c                   U R                   nU(       a-  UR                  nU Vs/ s H  oT" U5      (       d  M  UPM     nnOU R                  /nU(       d  UR                  5       n[        R
                  " XU5      $ s  snf )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.
)	changeloghasnodenullidheadsr   outgoing)repork   commonclri   ns         r7   _computeoutgoingrq      sf     
B**#2Vwqz!V2++
dE22 3s
   A<A<c                "   U R                   nUR                  nUR                  SS5      nU R                  (       d  US;  a  g [	        U R
                  S5      nUR                  SS5      (       d  g U R                  c!  UR                  S5      R                  S5      nO/UR                  S	U R                  5      nXQR                  S5      -  nU(       a  US
:X  a'  UR                  [        S5      [        U5      -  5        g US:X  aK  UR                  [        S5      [        U5      -  5      (       a  [        R                  " [        S5      5      eg US:X  a6  [        S5      [        U5      -  n[        S5      n[        R                  " XgS9eg g )N   experimentals   auto-publish)   warn   confirm   abort   phases
   publishingFs   serveds   not public()s   ::%ln - public()rt   s$   %i changesets about to be published
ru   s2   push and publish %i changesets (yn)?$$ &Yes $$ &Nos	   user quitrv   s    push would publish %i changesetss:   use --publish or adjust 'experimental.auto-publish' configrR   )rm   r/   configpublishlistkeysremotegetrevsfilteredwarnr   lenpromptchoicer   CanceledErrorr+   )pushoprm   r/   behaviorremotephases	publishedmsgrS   s           r7   _checkpublishr      sd   ;;D	Byy/:H~~)HHFMM95LM511{{MM),11/B	II16;;?	 	]]9--	wGG:;c)nL #GHi.!  ))!L/::	
 !783y>ICD ++c-- " r9   c                    U R                   R                  nUR                  SS5      nSU;  =(       a    SU;   nU=(       d     U R                  R	                  S5      (       + $ )zoreturn 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)rm   r/   
configlistr|   capable)opr/   exchangeforcebundle1s       r7   _forcebundle1r      sU     
B }}X'9:HX-H*2HL<ryy00<<<r9   c                      \ rS rSrSr      S	S jr\R                  S 5       r\R                  S 5       r	\
S 5       rSrg)
pushoperation   zA 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.
Nc	                j   Xl         UR                  U l        X l        X0l        X@l        X`l        XPl        [        5       U l        S U l	        S U l
        S U l        S U l        S U l        S U l        S U l        S U l        S U l        [        5       U l        / U l        S U l        0 U l        Xl        Xpl        g N)rm   r/   r|   forcer~   r   	newbranchset	stepsdonecgresultbkresultrl   remoteheadspushbranchmapincomingr   outdatedphasesfallbackoutdatedphasesoutobsmarkersoutbookmarks	trmanagerpkfailcbpushvarsrz   )	selfrm   r|   r   r~   r   r   rz   r   s	            r7   __init__pushoperation.__init__  s     	''
	""   " "&*# U  r9   c                .    U R                   R                  $ )z2future remote heads if the changeset push succeeds)rl   ancestorsofr   s    r7   futureheadspushoperation.futureheadsP  s     }}(((r9   c                   U R                   c  U R                  R                  $ U R                  R	                  5       nU R                  R
                  nU R                  R	                  5       nUR                  nUR                  R                  nUR                  nUR                  n/ n[        5       nU R                    H4  n	U" U	5      n
X;   a  UR                  U
5        M#  UR                  U
5        M6     UR                  USS9nU(       a  U R                  R                   V	s1 s H
  o" U	5      iM     nn	UR                  [         5        [        5       nU HG  n
U" U
5      u  pX;  a  X;  a  UR                  U5        X;  d  M/  X;  d  M6  UR                  U5        MI     U(       a#  UR                  SX5      nUR#                  U5        [%        U5       V
s/ s H
  o" U
5      PM     sn
$ s  sn	f s  sn
f )z/future remote heads if the changeset push failsT	inclusivezheads(%ld::%ld))r~   rl   commonheadsrm   
unfilteredrn   rh   indexrevnode
parentrevsr   addr@   	ancestorsmissingr   updater<   )r   unfirn   ro   to_revto_nodeparent_revs
unselectedcheadsrp   rknown_non_headsmissing_revsroot_pointsp1p2rk   s                    r7   fallbackheadspushoperation.fallbackheadsU  s    99==,,,yy##%( %%yy##%^^''mm
Aq	A{

1!!!$  ,,v,>/3}}/D/DE/D!F1I/DLEW%%K!$Q)b.GOOB')b.GOOB' " 		"3[Ne$$*6N3Nq
N33 F 4s   'G1G6c                T    U R                   (       a  U R                  $ U R                  $ )z3set of all common heads after changeset bundle push)r   r   r   r   s    r7   r   pushoperation.commonheads  s#     ==###%%%r9   )r   r   r   r   r   r   r   r   r   rl   r   r   rz   r   r   r|   r   r   rm   r~   r   r   r/   FNF FN)__name__
__module____qualname____firstlineno____doc__r   r   propertycacher   r   propertyr   __static_attributes__r   r9   r7   r   r      sk     IV 
) ) 
74 74r & &r9   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   deletec           	     z   Uc  0 n[        U UUUUUU40 [        R                  " U5      D6nUR                  R	                  5       (       a  [        UR                  R                  5      UR                  R	                  5       R                  -
  n	U	(       a<  [        S5      SR                  [        U	5      5      -  n
[        R                  " U
5      eUR                  R                  5       (       d  [        R                  " [        S5      5      eUR                  R                  S5      (       d  [        R                  " [        S5      5      e[        [         R"                  " UR                  5      5       Hs  nU R$                  R'                  5        H  u  pUR)                  U5      (       d  M    M=     [        R                  " [        S5      [        R*                  " U5      -  5      e   S=p  UR,                  R/                  SS	5      n[1        U5      (       d<  U(       a5  [2        R4                  " U 5      (       d  UR                  R7                  5       nUR                  R9                  5       n[;        UR                  S
UR                  R=                  5       5      Ul        UR                  RI                  U5        [K        U5        [M        U5        URN                  (       d  [Q        U5        [1        U5      (       d  [S        U5        [U        U5        [W        U5        [Y        U5        [[        U5        UR>                  b  UR>                  R]                  5         [^        R`                  " UR>                  X5        U R,                  R/                  SS5      (       a  [b        Rd                  " X5        U$ ! [        R@                   aA  nSn
U
[B        RD                  " U5      -  n
UR,                  RG                  U
5         SnAGNeSnAff = f! [^        R`                  " UR>                  X5        f = f)a;  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'rs      bundle2.pushbacks   push-responses"   cannot lock source repository: %s
   remotenames)3r   r   	strkwargsr|   localr   rm   r   	supportedr   r*   r<   r   r+   canpushr   r	   read_remote_wanted_sidedata_sidedata_computersr=   r}   bytestrr/   
configboolr   bookmodbookmarksinstorewlockr   transactionmanagerr   r   LockUnavailabler   forcebytestrdebug	checkpushr   _pushdiscoveryr   _checksubrepostate_pushbundle2_pushchangeset_pushsyncphase_pushobsolete_pushbookmarkcloselockmodreleaser   pullremotenames)rm   r|   r   r~   r   r   rz   opargsr   r   r   categorykind	computersr   r   maypushbackerrs                     r7   pushr    s^   $ ~	 

V
$	F }}(()FMM,?,?,A,K,KK 	  F7O,	.C
 ++c""==  ""kk!@ABB==  --kk2
 	
 7>>v}}MN  $77==?OD}}X&&  @ ++- ""8,	-  O E(7	! !))..#K
 #6**0066))+;;##%D1-v}}/@/@/B F 	f%fv||v&V$$ vvff'""$(($6ww/>::##D1M7 $$ 	! 9C:**3//CIIOOC  	!, 	(($6s2   4B6N? *B;P ?P6P	P PP #P:c                   ^  U 4S jnU$ )ah  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                \   > T[         ;  d   eU [         T'   [        R                  T5        U $ r   )pushdiscoverymappingpushdiscoveryorderr@   funcstepnames    r7   decpushdiscovery.<locals>.dec0  0    3333)-X&!!(+r9   r   r	  r
  s   ` r7   pushdiscoveryr  &       Jr9   c                @    [          H  n[        U   nU" U 5        M     gzRun all discovery stepsN)r  r  )r   r	  steps      r7   r   r   9      &#H-V 'r9   c                   U R                   n[        UR                  S5      5      (       a  [        UR                  S5      5      (       d  gU R                  R                   Ho  nX   nSUR                  5       ;   d  M  SUR                  5       ;   d  M3  [        UR                  5       H#  nUR                  U5      nUR                  SS9  M%     Mq     g)zDEnsure all outgoing referenced subrepo revisions are present locallys   .hgsubs   .hgsubstateNT)onpush)rm   r   filerl   r   manifestfilesr<   substatesubverify)r   rm   rp   ctxsubpathr  s         r7   r   r   @  s     ;;D tyy#$$C		.0I,J,J__$$g&>SYY[+H!#,,/ggg&

$
' 0	 %r9   s	   changesetc                   [         R                  nU R                  (       a2  U" U R                  U R                  U R
                  U R                  S9nO&U" U R                  U R                  U R
                  S9nUu  p4n[         R                  nU" U R                  U R                  U R                  UU R
                  S9nXpl        XPl        X@l	        g)z-discover the changeset that need to be pushed)r   r   )r   )	onlyheads	commonincr   N)
r   findcommonincomingr~   rm   r|   r   findcommonoutgoingrl   r   r   )r   fcir   rn   incr   fcorl   s           r7   _pushdiscoverychangesetr&  S  s     
&
&C{{KKMM,,	
	 V]]&,,G	(F

&
&C++llH O$Or9   s   phasec                J   U R                   nU R                  nUR                  5       nUR                  nUR                  R
                  n[        U R                  S5      nU R                  R                  SS5      (       aH  U(       aA  U R                   R                  (       d&  UR                  SS5      (       a  / U l        / U l        gU R                   Vs1 s H
  ou" U5      iM     nn[        R                   " U R                  UU5      U l        [%        U R"                  R&                  5      n	U R"                  R(                  n
U R"                  R(                  =(       d    U R*                  nUR                   Vs1 s H
  ou" U5      iM     nnUR,                  R/                  U[        R0                  5      nU
(       a  X-
  nSnO
X-
  nX-  nSnU(       d  / =nnO'UR3                  XU5      nU Vs/ s H  nUU   PM
     nnU(       a  UR5                  5       nOX-
  nU R*                  (       a  UR7                  X-  5        OU(       a  UR7                  U5        UR9                  U5       Vs/ s H  nUU   PM
     snU l        UU l        gs  snf s  snf s  snf s  snf )	zldiscover the phase that needs to be pushed

(computed for both success and failure case for changesets push)rw      ui   _usedassubreporx   FNs   heads(%ld::%ld)s   heads((%ld::%ld) and public()))rl   rm   r   rh   r   r   r{   r|   r/   r   r   r}   r   r   r   r   RemotePhasesSummaryr   r   draft_roots
publishingrz   _phasecacheget_raw_setdraftr~   copyr   headrevs)r   rl   rm   r   ro   r   r   rp   fallbackheads_revdrootsfallback_publishingpush_publishingr   draftsfallback_rootsrevsetfallbackfallback_revr   r   s                       r7   _pushdiscoveryphaser;  n  s=   
 H;;D??D	BXX\\FFMM95L 			U$566'']E22 !#(*%,2,@,@A,@q,@A 44F
 $$001F --88))44FO'/'7'78'7!F1I'7L8))$=F.#&2"$$<yy9JK%12\DG\2 %%'	 )	~~*34	&.0kk).DE.DT!W.DEF$,F!K B 9 3 Fs   J>J5J2J s	   obsmarkerc                |   [         R                  " U R                  [         R                  5      (       d  g U R                  R                  (       d  g S[        U R                  S5      ;  a  g U R                  nUR                  SU R                  5      nU R                  R                  R                  US9U l
        g )N   obsoletes
   namespacess   ::%lnr~   )r   	isenabledrm   exchangeoptobsstorer{   r|   r~   r   relevantmarkersr   )r   rm   r~   s      r7   _pushdiscoveryobsmarkersrC    s    fkk8+?+?@@;;(6==-@@;;D 99Xv112D!;;//??T?JFr9   	   bookmarksc                Z   U R                   nU R                  R                  5       nU R                  nUR	                  S5        SnU R
                  (       aO  [        R                  " UR                  R                  U R
                  5      nUR                  R                  USS9n[        R                  " [        US5      5      nU R                   Vs1 s H  orR                  R!                  U5      iM     nn[        R"                  " X"R                  U5      n	[%        XXU	5      $ s  snf )Ns   checking for updated bookmarks
r   Tr   rD  )r/   rm   r   r|   r   r~   r   maplistrh   r   r   r   unhexlifybookmarksr{   r   
_bookmarks
expandnamecomparebookmarks_processcompared)
r   r/   rm   r|   r   revnumsremotebookmarkbookmarkexplicitr`   s
             r7   _pushdiscoverybookmarksrP    s    	B;;!!#D]]FHH01I{{""4>>#5#5v{{CNN,,W,E	//0NON >D=M=M=M""8,=M   ##D//>JDFxNNs   $D(c                *   Uu  pVpxppU R                   nU HY  u  pnX;   a  UR                  U5        U(       a  X   R                  5       U;   d  M;  U R                  R	                  UUU45        M[     U H  u  pnX;   d  M  UR                  U5        [
        R                  " U5      (       a0  U R                  R                  [        S5      U-  5        SU l
        Mi  U(       aH  X   R                  5       U;  a2  [        S5      nU R                  R                  UU-  5        SU l
        M  U R                  R	                  USU45        M     [        U5      [        U	5      -   [        U
5      -    H[  u  pnX;   d  M  UR                  U5        U(       a  X   R                  5       U;   d  M=  U R                  R	                  UUU45        M]     U H<  u  pnX;   d  M  UR                  U5        U R                  R	                  UUS45        M>     U H  u  pnX;   d  M  UR                  U5        M      U(       a<  [        U5      nU R                  R                  [        S5      US   -  5        SU l
        U R                  R                  5         g)zftake decision on bookmarks to push to the remote repo

Exists to help extensions alter this behavior.
s#   cannot push divergent bookmark %s!
r$   s1   cannot push bookmark X without its revision: %s!
r9   s>   bookmark %s does not exist on the local or remote repository!
r   N)rm   remover   r   r@   r   isdivergentr/   r   r   r   listr<   sort)r   pushedrO  	remotebmsr`   addsrcadddstadvsrcadvdstdivergedifferinvalidsamerm   r_   sciddcidr   s                     r7   rK  rK    s&   
 FJBFFGW;;D=OOA)V3&&47	    =OOA""1%%		q!HIAMN"#DJNN,F:MN		sQw'"###**AsD>:   fW5VD=OOATZ^^-7##**AtT?;	 E  =OOA&&4~6	   =OOA  (#		+ qk		
 
r9   c                   U R                   nU R                  R                  5       nUR                  (       d,  [        R
                  " UR                  X!R                  5        gU R                  (       d  UR                  (       a  [        S5      n[        S5      n[        S5      n[        S5      UUS.nUR                   Hu  nX'   nUR                  5       (       a  [        R                  " X8-  5      eUR                  5       (       d  MK  [        R                  " XhR!                  5       S      U-  5      e   ["        R$                  " U 5        g)	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)rl   rm   r   r   r   nochangesfoundr/   excludedr   rA  r   r   r   r   r+   
isunstableinstabilitiesr   
checkheads)	r   rl   r   msomspdmscdmstr   r  s	            r7   _pushcheckoutgoingrl    s   H;;!!#Dtww.?.?@<< ==<=CDEDFGDCD$(&*C !,,j<<>>++ci00^^%%  ++c*;*;*=a*@&AC&GHH - 	V$r9   c                   ^ ^ UU 4S jnU$ )ac  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[         ;  d   eU [         T'   Tc  [        R                  T5        U $ [        R                  TT5        U $ r   )b2partsgenmappingb2partsgenorderr@   insertr  idxr	  s    r7   r
  b2partsgenerator.<locals>.decQ  sN    0000&*(#;""8,  ""31r9   r   r	  rs  r
  s   `` r7   b2partsgeneratorrv  G       Jr9   c                >   U R                   (       Gd  U R                  R                  (       a  SUR                  R	                  SS5      ;   nU R
                  SL nU(       a  U(       a$  UR                  S[        U R                  5      S9  g[        5       nU R
                  R                  5        H;  u  pVUu  pxpUc  M  [        U5      nU[        U
5      U-  -  nXK[        U5      -
  -  nM=     U(       a%  [        [        U5      5      nUR                  SUS9  gggg)z\Generate race condition checking parts

Exists as an independent function to aid extensions
s   relateds
   checkheadsr   Ns   check:headsdatas   check:updated-heads)r   rl   r   capabilitiesr}   r   newpartiterr   r   r=   r<   )r   bundlerallowunrelatedemptyremoteaffectedbranchrk   r   newheadsunsyncedheadsdiscardedheadsr|   rz  s                r7   _pushb2ctxcheckheadsr  ]  s     <<<FOO77#w';';'?'?2(
 
 **d2OONf6H6H1IOJuH!'!5!5!;!;!=GLD}* -FN 3f <<HX 66H "> F8,- 6TB  8<r9   c                    [        U R                  R                  =(       d2    U R                  =(       d    U R                  =(       d    U R
                  5      $ )z&return True if we are pushing anything)boolrl   r   r   r   r   )r   s    r7   _pushingr  x  sH     	  		 	 r9   s   check-bookmarksc                z   [        U 5      (       a  U R                  (       a  g[        R                  " U R                  5      nSU;   nU R
                  (       a  U(       d  g/ nU R
                   H  u  pVnUR                  XV45        M     [        R                  " U R                  U5      nUR                  SUS9  g)zinsert bookmark move checkingNrD  s   check:bookmarksry  )r  r   r	   bundle2capsr|   r   r@   r   binaryencoderm   r|  )	r   r~  b2capshasbookmarkcheckrz  bookoldnew	checkdatas	            r7   _pushb2checkbookmarksr    s     Fv||  /F#v-$4D --3TK  .$$V[[$7IOO&YO7r9   s   check-phasesc                J  ^ [        U 5      (       a  U R                  (       a  g[        R                  " U R                  5      nSUR                  SS5      ;   nU R                  Gb8  U(       Ga/  [        R                   Vs0 s H  oD/ _M     nnU R                  R                  5       R                  R                  mU[        R                     R                  U4S jU R                  R                   5       5        U[        R                      R                  U4S jU R                  R"                   5       5        [%        UR'                  5       5      (       aB  U H  nXV   R)                  5         M     [        R*                  " U5      nUR-                  SUS9  ggggs  snf )	zinsert phase move checkingN   headsrw   r   c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   .0r   r   s     r7   	<genexpr>%_pushb2checkphases.<locals>.<genexpr>  s      %
 @1GAJJ @   c              3  4   >#    U  H  nT" U5      v   M     g 7fr   r   r  s     r7   r  r    s      $
 ?1GAJJ ?r  s   check:phasesry  )r  r   r	   r  r|   r}   r   r   	allphasesrm   r   rh   r   publicextendpublic_headsr/  r+  anyvaluesrU  r  r|  )	r   r~  r  hasphaseheadspchecksphaser  r   s	           @r7   _pushb2checkphasesr    sI    Fv||  /F

9b 99M&=!'!1!12!1AR%!12++((*4499v}}$$ %
 & 3 3 @ @%
 	
 	v||## $
 & 3 3 ? ?$
 	
 v}}""$  ++F3IOOO)O<	   ,9&2s   F c           	       ^ ^	 ST R                   ;   a  gT R                   R                  S5        [        T 5      (       d  gT R                  R	                  T 5        [        T U5        [        R                  " T R                  5      nSnUR                  S5      nU(       ai  U Vs/ s H+  nU[        R                  " T R                  5      ;   d  M)  UPM-     nnU(       d  [        R                  " [        S5      5      e[        U5      n[        R                   " T R                  5      n[        R"                  " T R                  T R$                  USUUS9nUR'                  SUS9m	U(       a  T	R)                  S	U5        [*        R,                  " T R                  5      (       a  T	R)                  S
S5        [.        R0                  T R                  R2                  ;   a  T	R)                  SS5        U	U 4S jnU$ s  snf )zohandle changegroup push through bundle2

addchangegroup result is stored in the ``pushop.cgresult`` attribute.

   changesetsNrQ   rO      no common changegroup version   push
bundlecapsremote_sidedatary  rP      treemanifest   1   exp-sidedatac                   > U R                   R                  TR                  5      n[        US   5      S:X  d   eUS   S   S   Tl        g)z0extract addchangegroup returns from server replyrO   r   r      returnN)records
getrepliesidr   r   )r   	cgrepliescgpartr   s     r7   handlereply_pushb2ctx.<locals>.handlereply  sI    JJ))&))4	9^,-222#N3A6yAr9   )r   r   rl  rm   prepushoutgoinghooksr  r	   r  r|   r}   r   supportedoutgoingversionsr   r+   r   maxr   
makestreamrl   r|  addparamr   istreemanifestr   REPO_FEATURE_SIDE_DATAfeatures)
r   r~  r  r6   
cgversionsvr  cgstreamr  r  s
   `        @r7   
_pushb2ctxr    s    (((
'f%%
KK$$V,)  /FGN+J  
K99&++FF  	 

 ++a @ABBj/99&--HO%%'H __^(_;F
G,fkk**.((FKK,@,@@.B A
s   %(G:G:c                F   SU R                   ;   a  g[        R                  " U R                  5      nU R                  R
                  nSUR                  SS5      ;   nSU;   nSUR                  SS5      ;   nU(       a  U(       d  [        X5      $ U(       a  [        X5      $ g)z!handle phase push through bundle2rw   Nr   r      pushkeyr  r   )
r   r	   r  r|   rm   r/   r   r}   _pushb2phaseheads_pushb2phasespushkey)r   r~  r  r/   legacyphase
haspushkeyr  s          r7   _pushb2phasesr    s     F$$$  /F	Br}}X7IJJKv%J

9b 99M[ 11	#F44 
r9   c                >   U R                   R                  S5        U R                  (       al  [        R                   Vs0 s H  o"/ _M     nnUS   R                  S U R                   5       5        [        R                  " U5      nUR                  SUS9  ggs  snf )z6push phase information through a bundle2 - binary partrw   r   c              3  @   #    U  H  oR                  5       v   M     g 7fr   )r   )r  hs     r7   r  $_pushb2phaseheads.<locals>.<genexpr>  s     B,Aq&&((,As      phase-headsry  N)r   r   r   r   r  r  r  r|  )r   r~  r  updates	phasedatas        r7   r  r    s    
#"("2"23"2Qb5"23
BF,A,ABB''0	Y7	 3s   Bc                R  ^ ^ T R                   R                  S5        / mU4S jn[        R                  nT R                   H  nUR                  S5      nUR                  SU" S5      5        UR                  SU" UR                  5       5      5        UR                  SU" S[        R                  -  5      5        UR                  SU" S[        R                  -  5      5        TR                  UR                  U45        UT R                  UR                  '   M     UU 4S	 jnU$ )
z7push phase information through a bundle2 - pushkey partrw   c                   > [        UR                  5      nT H,  u  p4X2:X  d  M  [        R                  " [	        S5      U-  5      e   g )Ns   updating %s to public failed)intpartidr   r+   r   )r   exctargetidr  r   	part2nodes        r7   handlefailure+_pushb2phasespushkey.<locals>.handlefailure  s<    szz?%LF!kk!$C"Dt"KLL &r9   r  	   namespace   key   old   %d   newc                6  > T H  u  pU R                   R                  U5      nUS   n[        U5      S::  d   eS nU(       d  [        S5      U-  nO$[	        US   S   5      (       d  [        S5      U-  nUc  Mw  TR
                  R                  U5        M     g )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         r7   r  )_pushb2phasespushkey.<locals>.handlereply  s    %LFjj++F3Gj)Gw<1$$$CCDtKI.//:;dB		s# &r9   )r   r   r   encoder   r|  r  r   r   r/  r  r@   r  r   )r   r~  r  encnewremoteheadra   r  r  s   `      @r7   r  r    s    
#IM ..C..z*lC	N3fc-"3"3"567fc%&,,"678fc%&--"789$''=12#0  /$ r9   rT   c                \   SU R                   ;   a  g [        R                  " UR                  5      n[        R
                  " U5      c  g U R                   R                  S5        U R                  (       a7  [        R                  " U R                  5      n[        R                  " X5        g g )NrT   )r   r	   obsmarkersversionr{  r   commonversionr   r   r   sortedmarkersbuildobsmarkerspart)r   r~  remoteversionsmarkerss       r7   _pushb2obsmarkersr  "  s    (((..w/C/CDNn-5
'''(<(<=##G5 r9   c                   SU R                   ;   a  g[        R                  " U R                  5      nU R                  R
                  R                  SS5      nSU;   nU(       d  SU;   a  [        X5      $ SU;   a  [        X5      $ g)z$handle bookmark push through bundle2rD  Nr   r   r  )	r   r	   r  r|   rm   r/   r   _pushb2bookmarkspart_pushb2bookmarkspushkey)r   r~  r  legacylegacybookss        r7   _pushb2bookmarksr  /  s{     v'''  /F[[^^&&x1CDF&(K<61#F44	v	&v77 
r9   c                $    U (       d  gU(       d  gg)z"small utility for bookmark pushingr   r   r   r   )r  r  s     r7   	_bmactionr  ?  s    r9   c                    U(       aR  U R                   U   R                  5       [        R                  :X  a"  [        R
                  " [        S5      U-  5      egg)z6abort if a given bookmark points to a secret changesets:   cannot push bookmark %s as it points to a secret changesetN)rm   r  r   secretr   r+   r   )r   r   r_   s      r7   _abortonsecretctxr  H  sH    D!'')V]]:kkKLqP
 	
 ;tr9   c                |  ^ ^ T R                   R                  S5        T R                  (       d  g / m/ nT R                   H@  u  p4n[        T XS5        UR	                  X545        TR	                  U[        XE5      45        MB     [        R                  " T R                  U5      nUR                  SUS9  UU 4S jnU$ )NrD  ry  c                p   > TR                   nT H#  u  p#UR                  [        U   S   U-  5        M%     g rH   )r/   status
bookmsgmap)r   r/   r  action
allactionsr   s       r7   r  )_pushb2bookmarkspart.<locals>.handlereply^  s3    YY&LDIIj(+d23 'r9   )
r   r   r   r  r@   r  r   r  rm   r|  )	r   r~  rz  r  r  r  r  r  r  s	   `       @r7   r  r  P  s    
&JD --3&#,TK 43!456 . $$V[[$7IOOLyO14 r9   c           	     ^  ^ ^
 T R                   R                  S5        / m
[        R                  nU
4S jnT R                   H  u  pEn[        T Xd5        UR                  S5      nUR                  SU" S5      5        UR                  SU" U5      5        UR                  SU" [        U5      5      5        UR                  SU" [        U5      5      5        SnU(       d  S	nO	U(       d  S
nT
R                  UR                  XH45        UT R                  UR                  '   M     U
U 4S jn	U	$ )NrD  c                   > [        UR                  5      nT H<  u  p4nX2:X  d  M  [        R                  " [        U   S   R                  5       U-  5      e    e)Nr   )r  r  r   r+   r  rstrip)r   r  r  r  r  r  	part2books         r7   r  ._pushb2bookmarkspushkey.<locals>.handlefailurel  sS    szz?$- F&!kk*V"4Q"7">">"@4"GHH %. 	ur9   r  r  r  r  r  r   r   r   c                  > T	R                   nT H  u  p#nU R                  R                  U5      nUS   n[        U5      S::  d   eU(       d)  T	R                   R	                  [        S5      U-  5        Mg  [        US   S   5      nU(       a   UR                  [        U   S   U-  5        M  UR	                  [        U   S   U-  5        T	R                  c  M  ST	l	        M     g )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
           r7   r  ,_pushb2bookmarkspushkey.<locals>.handlereply  s    YY$- F&jj++F3Gj)Gw<1$$$		q!GH4OP'!*Y/0IIj03d:;GGJv.q1D892*+ %.r9   )r   r   r   r  r   r  r|  r  r   r@   r  r   )r   r~  r  r  r  r  r  ra   r  r  r  s   `         @r7   r  r  g  s    
&I
..C !--3&#,z*lC$56fc$i(fc#c(m,fc#c(m,FF$''401#0  .," r9      pushvars)rs  c                &   U R                   nU(       a~  0 nU H;  nSU;  a  Sn[        R                  " XT-  5      eUR                  SS5      u  pgXsU'   M=     UR	                  S5      nUR                  5        H  u  pUR                  XSS9  M     gg)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+   r[   r|  r=   r  )r   r~  r   	shellvarsrawr   kr  ra   rC   rD   s              r7   _getbundlesendvarsr    s     H	C34  kk#),,99T1%DAaL  {+#//+JCMM#M6 , r9   c                   [         R                  " U R                  [         R                  " U R                  5      5      nU R
                  =(       a    U R                  R                  SS5      n[         R                  " [         R                  " U R                  USS95      nUR                  SUS9  / n[         H7  n[        U   nU" X5      n[        U5      (       d  M&  UR                  U5        M9     UR                  S::  a  g[         R"                  " UR%                  5       5      n  U R                  R'                  5        n	U	R)                  S	US
/U R                  R+                  5       S.5      R-                  5       n
SSS5         SnU(       a  U R
                  R6                  n[         R8                  " U R                  W
UU R                  S9nU H  nU" W5        M     g! , (       d  f       Nk= f! [.        R0                   a'  n[.        R2                  " [5        S5      U-  5      eSnAff = f! [.        R0                   a'  n[.        R2                  " [5        S5      U-  5      eSnAf[         R:                   a  nU R                  R/                  [5        S5      U-  5        UR<                  b4  U R                  R/                  [5        S5      SUR<                  -  -  5        [.        R2                  " [5        S5      5      eSnAff = f! [.        R>                   aE  n[A        URB                  5      nXRD                  ;  a  e U RD                  U   " X5         SnAGNSnAff = f)zpush data to the remote using bundle2

The only currently supported type of data is changegroup but this will
evolve in the future.rs   r      client)allowpushbackroles	   replycapsry  r   Nr      force)s   bundler     url   missing support for %sr|   s   remote: %s
s   (%s)s   push failed on remote)#r	   bundle20r/   r  r|   r   r   
encodecapsgetrepocapsrm   r|  rp  ro  callabler@   nbpartsr   chunkbuffer	getchunkscommandexecutorcallcommandr   resultr   BundleValueErrorRemoteErrorr   transactionprocessbundleAbortFromPartrS   PushkeyFailedr  r  r   )r   r~  pushbackcapsblobreplyhandlerspartgennamepartgenr  streamereplyr  trgetterr   r  rephands                   r7   r   r     s   
 vyy'*=*=fmm*LMG FII$8$8,%H
 !!FKKxiPH OOLxO0M&#K0f&C==  %	 ' !g//12F"-	H..0A#)#+* & 1 1 3 &(  1	AH!++77&&}}	B$ ! !C 10 %% 	H##A&?$@3$FGG	H %% 	H##A&?$@3$FGG$$ 	AIIOOAo.45xx#		/ 2g6H IJ##A&>$?@@		A
  -SZZ(,,	-s   -G; >G*G; A
H9 *
G84G; 7L 8G; ;H6"H11H66L 9L"I//LBLLL M.):M))M.c           	        SU R                   ;   a  gU R                   R                  S5        [        U 5      (       d  gU R                  R	                  S5      (       d   eU R
                  R                  U 5        U R                  nSnU R                  c9  UR                  (       d(  U R
                  R                  R                  (       d  SnOSn[        R                  " U R
                  USSUUS9nU R                  (       a  S	/nOU R                  nU R                  R!                  XEU R
                  R#                  5       5      U l        g)
z7Make the actual push of changeset bundle to remote repor  Nr   TFrQ   r  )fastpathr  r  )r   r   rl  r|   r   rm   r  rl   r~   rd  rh   filteredrevsr   makechangegroupr   r   unbundler   r   )r   rl   r  r8  cgr   s         r7   r   r     s	   (((
'f%% ==  ----
KK$$V,HJ{{V[[22?? 		$	$
B ||j(( mm,,Rfkkoo>OPFOr9   c           
     ~   U R                   n[        U R                  S5      nU R                  R	                  SS5      (       a/  U(       a(  U R
                  c  UR                  SS5      (       a  SS0nU(       d  [        X5        gU R                  R                  5       nUR                  R                  R                  nUR                  R                  nU Vs/ s H
  od" U5      PM     nn[        R                  " U R                  UU5      u  pU V
s/ s H
  o" U
5      PM     nn
UR                  SS5      (       a  [        X5        O%[        X5        [        X[        R                   5        U R
                  (       a  SU R"                  ;   a  gU R$                  nOU R&                  nU R"                  R)                  S5        U Vs/ s H  oR                  5       U;  d  M  UPM     nnU H  nU R                  R+                  5        nUR-                  SSUR/                  5       S	[        R                   -  S	[        R0                  -  S
.5      R3                  5       n
SSS5        W
(       a  M  U R                  R5                  [7        S5      U-  5        M     gs  snf s  sn
f s  snf ! , (       d  f       NR= f)z2synchronise phase information locally and remotelyrw   r(  r)  Nrx   Fs   Truer  r  r  r  r  r  r  )r   r{   r|   r/   r   r   r}   _localphasemoverm   r   rh   r   r   r   r   analyze_remote_phasesr/  r   r   r   r   r$  r%  r   r  r&  r   r   )r   r   r   r   r   r   rp   cheads_revspheads_revs_drr   pheadsoutdatedcr  r3  s                   r7   r   r     s4   FFMM95L		U$566OO#]E22 &w/' {{%%'%%))..%%*01&Qvay&1!77KK

 '22k'!*k2M511F+F+FFLL9 ??F,,,,,H44HY'  (Bx!6686+AAxB%M..0AMM&/ - 1 1 3 % 4 % 5	 &(  1 1		89MI &9 2 3( C 10s%   JJ$
J)%J)AJ..
J<	c                   U R                   (       a;  [        R                  " U R                  U R                   R	                  5       X!5        gU Vs/ s H'  o2U R                  U   R                  5       :  d  M%  UPM)     nn[        R                  U   nU(       a(  U R                  R                  [        S5      U-  5        ggs  snf )z0move <nodes> to <phase> in the local source repos8   cannot lock source repo, skipping local %s phase update
N)
r   r   advanceboundaryrm   r)  r  
phasenamesr/   r   r   )r   nodesr  rp   actualmovesphasestrs         r7   r?  r?  g  s    KK))557	
 #(J%Q6;;q>3G3G3I+Iq%J$$U+II/ 	  Ks   $C9Cc           	     ^   SU R                   ;   a  gU R                  nU R                  nU R                   R                  S5        U R                  (       a  U R
                  R                  S5        / n[        R                  " U R                  5      n[        R                  " U5      n[        USS9 H*  nXV   nUR                  UR                  SUSU5      5        M,     U Vs/ s H  o(       a  M  UPM     sn(       a'  [        S5      n	UR
                  R                  U	5        gggs  snf )	z5utility function to push obsolete markers to a remoterT   Ns'   try to push obsolete markers to remote
Treverser=  r9   s&   failed to push some obsolete markers!
)r   rm   r|   r   r   r/   r   r   r  r   _pushkeyescaper<   r@   r   r   r   )
r   rm   r|   rsltsr  
remotedatarC   rz  r   r   s
             r7   r   r   }  s    (((;;D]]F
'		CD''(<(<=,,W5
*d3C?DLLS#tDE 4 &u!AAu&>?CGGLL '  's   %
D*3D*c                z   U R                   S:X  d  SU R                  ;   a  gU R                  R                  S5        U R                  nU R                  nU R
                   H  u  p4nSnU(       d  SnO	U(       d  SnUR                  5        nUR                  SSU[        U5      [        U5      S.5      R                  5       nSSS5        W(       a   UR                  [        U   S   U-  5        M  UR                  [        U   S	   U-  5        U R                  c  M  S	U l        M     g! , (       d  f       Nn= f)
z"Update bookmark position on remoter   rD  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  r3  r   s	            r7   r   r     s   !|v/?/??
&	B]]F**FF##%".HH	 fh  & IIj(+a/0GGJv&q)A-.*"#1 + &%s   8D,,
D:	c                      \ rS rSrSr         S
S jr\R                  S 5       r\R                  S 5       r	\R                  S 5       r
S rS	rg)pulloperationi  zA 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.
Nc                X   Xl         X l        Xl        X0l        U Vs/ s H  oR                  R                  U5      PM     snU l        X@l        Xpl        S U l	        S U l
        S U l        S U l        X`l        S U l        [        5       U l        SU l        Xl        Xl        Xl        g s  snf )NF)rm   r|   remote_pathrk   rH  rI  explicitbookmarksr   streamclonerequestedr   rn   rheadsfetchremotebookmarksr   r   r   clonebundleattemptedincludepatsexcludepatsdepth)r   rm   r|   rk   r   r   r\  rY  r^  r_  r`  pathrN  s                r7   r   pulloperation.__init__  s     	  
 BK"
AJXOO&&x0"
 
$8!
.$)!&&
9"
s   $B'c                    U R                   cW  [        U R                  5      n[        U R                  5      nU R                   H  nX1;  d  M
  UR                  U5        M     U$ U R                   $ )z0heads of the set of changeset target by the pull)rk   r   rn   rT  rZ  r@   )r   rF  r  rp   s       r7   pulledsubsetpulloperation.pulledsubset  s]     :: DKK At{{#C[[:JJqM ! J ::r9   c                "    [        U 5      (       + $ r   )r   r   s    r7   canusebundle2pulloperation.canusebundle2  s     &&&r9   c                B    [         R                  " U R                  5      $ r   )r	   r  r|   r   s    r7   remotebundle2capspulloperation.remotebundle2caps  s    ""4;;//r9   c                6    U R                   R                  5       $ r   )r   r)  r   s    r7   gettransactionpulloperation.gettransaction  s    ~~))++r9   )r   r]  rn   r`  r_  rX  r[  r   rk   r^  r|   rW  r\  rm   rZ  r   rY  r   )	NFr   NNNNNN)r   r   r   r   r   r   r   r   rd  rg  rj  rm  r   r   r9   r7   rU  rU    s}     !5n 
 " 
' ' 
0 0,r9   rU  c                  0    \ rS rSrSrS rS rS rS rSr	g)	r   i  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                6    Xl         X l        X0l        S U l        g r   )rm   sourcer   _tr)r   rm   rq  r   s       r7   r   transactionmanager.__init__  s    	r9   c                f   U R                   (       d  SU R                  [        R                  " U R                  5      4-  nU R
                  R                  U5      U l         U R                  U R                   R                  S'   U R                  U R                   R                  S'   U R                   $ )z<Return an open transaction object, constructing if necessarys   %s
%s   sourcer  )rr  rq  r   hidepasswordr   rm   r)  hookargs)r   trnames     r7   r)  transactionmanager.transaction   sz    xx$++w/C/CDHH/M!NNFyy,,V4DH+/;;DHHi((,DHHf%xxr9   c                T    U R                   b  U R                   R                  5         gg)zclose transaction if createdN)rr  r   r   s    r7   r   transactionmanager.close)  s    88HHNN  r9   c                T    U R                   b  U R                   R                  5         gg)zrelease transaction if createdN)rr  r   r   s    r7   r   transactionmanager.release.  s!    88HH  r9   )rr  rm   rq  r   N)
r   r   r   r   r   r   r)  r   r   r   r   r9   r7   r   r     s     

r9   r   c                    U R                  5        nUR                  SSU05      R                  5       sS S S 5        $ ! , (       d  f       g = f)N   listkeysr  )r$  r%  r&  )r|   	namespacer3  s      r7   r{   r{   4  s8    				!Q}}[<*CDKKM 
"	!	!s	   "=
Ac                  ^^ U R                  5       mTR                  mU4S jnU4S jn TR                  5       n[        T5      n[	        U5        [
        R                  U R
                  ;   a  g U[        T5      :X  a  g [        U4S jUR                   5       5      (       a  g U" TR                  5       U5      nU" XaR                  5      Ul	        [        UR                  5      UR                  -
  Ul        M  )Nc                r   > TR                  SX5      nU Vs1 s H  o3R                  5       iM     sn$ s  snf )zReturns heads(h1 % h2)s   heads(%ln %% %ln)r   r   h1h2resr  r   s       r7   headsofdiff%_fullpullbundle2.<locals>.headsofdiffF  s0    hh+R4&)*cs
c***   4c                r   > TR                  SX5      nU Vs1 s H  o3R                  5       iM     sn$ s  snf )zReturns heads((h1 + h2) - null)s   heads((%ln + %ln - null))r  r  s       r7   headsofunion&_fullpullbundle2.<locals>.headsofunionK  s0    hh3R<&)*cs
c***r  c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr   )ri   )r  rp   unficls     r7   r  #_fullpullbundle2.<locals>.<genexpr>\  s     8-Qv~~a  -s   !)r   rh   rk   r   _pullbundle2r   NARROW_REQUIREMENTallrZ  rn   r   )	rm   pullopr  r  	old_headsclstart	new_headsr   r  s	          @@r7   _fullpullbundle2r  9  s     ??D^^F+
+
 LLN	f+V**d.?.??
 c&k!8&--888	:	$Y>FMM*V]]:! r9   c                   ^ UR                   R                  5       n[        R                  " XSSS9  [        R
                  " U R                  5       5      mU4S jnUR                  SU5        g)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" 5       n[        S5      nUR                  R                  U5      (       a  [        R                  " S5      eg )Ns+   accept incoming changes (yn)?$$ &Yes $$ &Nos   user aborted)r   r/   r   r   r+   )trrm   cmreporefs      r7   prompt$add_confirm_callback.<locals>.promptm  s>    y=>77##++o.. $r9   s   900-pull-promptN)r   r)  r   registersummarycallbackweakrefrefr   addvalidator)rm   r  r  r  r  s       @r7   add_confirm_callbackr  c  s[     
			%	%	'B##' kk$//+,G/ OO&/r9   c                   Uc  0 nUc  U	b'  U=(       d
    [        5       nU	=(       d
    [        5       n	OU R                  u  p[        R                  " U5        [        R                  " U	5        [	        U U4UUUUUUU	U
S.[
        R                  " U5      D6nUR                  R                  5       nU(       ao  [        UR                  5      UR                  R                  -
  nU(       a<  [        S5      SR                  [        U5      5      -  n[        R                   " U5      eU R"                   Ht  nU R$                  R'                  5        H  u  nnUR)                  U5      (       d  M    M>     [        R*                  " [        S5      [
        R,                  " U5      -  5      e   [/        U SUR1                  5       5      Ul        [4        R6                  n[8        R:                  " U 5      (       d  U R<                  nU" 5          U R?                  5          UR2                     U(       d@  U R@                  RC                  SS5      (       a*  U R@                  RE                  5       (       d  [G        X5        [I        U5        [J        RL                  " U5        [O        U5        URP                  (       a  [S        X5        [U        U5        [W        U5        [Y        U5        [[        U5        SSS5        SSS5        SSS5        U R@                  RC                  SS	5      (       a  [\        R^                  " X5        U$ ! , (       d  f       NW= f! , (       d  f       N`= f! , (       d  f       Ni= f)
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)ra  rk   r   r   rY  r^  r_  r`  r   r   sD   sidedata category requested by local side without localsupport: '%s'r  ru   rs   r   )0r   
narrowpatsr   validatepatternsrU  r   r   r|   r   r   rm   r   r   r*   r<   r   r+   _wanted_sidedatar   r=   r}   ProgrammingErrorr   r   r   r   r   nullcontextmanagerr   r   r   r   r/   r   plainr  _maybeapplyclonebundler   maybeperformlegacystreamclone_pulldiscoveryrg  r  _pullchangeset
_pullphase_pullbookmarks_pullobsoleter   r   )rm   r|   ra  rk   r   r   r   rY  r^  r_  r`  confirmr  	peerlocalr   r   r   r   r   r   s                       r7   pullr  v  s   T ~ +"9!*SU!*SU#'?? ,, 1 

V
$F ##%Ii,,-0E0EE F7O,	.C
 ++c""))  $77==?OD)}}X&&  @ ((% ""8,	-  *" *$FF##E##D))

	$))+v//GGw
33DGGMMOO . 	v&11&9vT*v6vf!  0+& ww/>::##D1M-  0/++s=   	M!M'CL?.M6M!?
M	M
M	M!!
M/c                   ^  U 4S jnU$ )ah  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                \   > T[         ;  d   eU [         T'   [        R                  T5        U $ r   )pulldiscoverymappingpulldiscoveryorderr@   r  s    r7   r
  pulldiscovery.<locals>.dec  r  r9   r   r  s   ` r7   pulldiscoveryr    r  r9   c                @    [          H  n[        U   nU" U 5        M     gr  )r  r  )r  r	  r  s      r7   r  r    r  r9   s   b1:bookmarksc                    U R                   b  gU R                  (       a  SU R                  ;   a  g[        U R                  S5      n[
        R                  " U5      U l         g)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.Nr  rD  )r\  rg  rj  r{   r|   r   rG  )r  bookss     r7   _pullbookmarkbundle1r    sQ     )v/G/G G 	V]]L1E$77>Fr9   rO   c                   [         R                  " U R                  U R                  U R                  U R
                  S9nUu  p#nU R                  R                  5       R                  R                  R                  nU(       al  U(       ae  [        U5      nU H*  nU" U5      (       d  M  Xv;  d  M  UR                  U5        M,     [        U5      R                  [        U5      5      (       a  / nX l        X0l        X@l        g)zvdiscovery phase for the pull

Current handle changeset discovery only, will change handle all discovery
at some point.)rk   r   N)r   r!  rm   r|   rk   r   r   rh   r   has_noder   r@   issubsetrn   r[  rZ  )r  tmprn   r[  rZ  r  scommonrp   s           r7   _pulldiscoverychangegroupr  (  s     
&
&V]]&,,fllC  F6{{%%'1177@@H f+A{{#MM!$  v;F,,EMLMr9   c                r   S[        U R                  SS90nU R                  R                  n[        R                  " U SS9S   nU R
                  US'   U R                  =(       d    U R                  US'   U R                  R                  [        R                  5      nU(       a   U R                  (       a  U R                  US	'   U(       a   U R                  (       a  U R                  US
'   U(       aA  SUS'   SUS'   U R                  R                  S5        U R                  R                  S5        OU R                  R                  S5        U R                   US'   SUR#                  SS5      ;   nSU R$                  R'                  SS5      ;   nU(       d'  U(       a   SUS'   U R                  R                  S5        SU R$                  ;   a  SU R                  ;  a  S/US'   SnSUR#                  SS5      ;   nSU R$                  ;   n	U R(                  b  U R                  R                  S5        SU R                  ;  a"  U R(                  c  U(       d  U	(       a  SUS'   SnSU R$                  ;   aL  SU R                  ;  a<  U R                  R                  S5        UR+                  S/ 5      R-                  S5        U R                  R                  S5      (       aJ  U R                  c=  [/        U R
                  5      U R                  R0                  /:X  a  U R2                  US'   U(       a/  U R                  R                  R5                  [7        S5      5        OU R                   (       d6  U R                  R                  R5                  [7        S5      5        SU l        OiU R                  c\  [/        U R
                  5      U R                  R0                  /:X  a.  U R                  R                  R5                  [7        S5      5        [:        R<                  " U R                  [:        R>                  5      (       aW  [@        RB                  " U R$                  5      n
[:        RD                  " U
5      b   SUS'   U R                  R                  S5        [G        X5        [@        RH                  " U R                  5      nU(       a  XS'   U R                  RK                  5        n[M        U5      nSUS'   URO                  S U5      RQ                  5       n [@        RR                  " U R                  U RT                  SU R                  S!9nS"URV                  S'   [@        RX                  " U R                  UUU R                  S#9   SSS5        U R                   (       a  [@        Rd                  " W5      U l        WRf                  S    H  u  nnUS:X  d  M  [i        U U5        M     U(       a+  0 nURf                  S    H  nUS(   UUS)   '   M     UU l        O<URf                  S    H)  u  nnUS:X  d  M  [j        Rl                  " U5      U l        M+     U R(                  b  [o        U 5        gg! [@        RZ                   a^  nU R                  R                  R]                  [7        S$5      U-  5        [\        R^                  " [7        S%5      UR`                  S&9eSnAf[\        Rb                   a'  n[\        R^                  " [7        S'5      U-  5      eSnAff = f! , (       d  f       GN= f)*zJpull data using bundle2

For now, the only supported data are changegroup.s
   bundlecapsr  r  T)r	   r      commonr  s   includepatss   excludepatsF   cgr"   rO   rw   r   r   r   r  rD  Ns   request-bookmarks   clonebundless   cbattempteds   streaming all changes
   no changes found
   requesting all changes
rT   s   remote_sidedatar  ru  	   getbundle)rq  r|   s   records)r   r|   s   remote: abort: %s
s   pull failed on remoterR   r  s   nodes   bookmark)8
caps20to10rm   r/   r   canperformstreamclonern   rk   rZ  r|   r   r   	NARROWCAPr^  r_  r   r   r[  r   rj  r}   r\  
setdefaultr@   rT  rj   r]  r   r   r   r   r?  r@  r	   r  r  _pullbundle2extrapreparer   r$  dictr%  r&  bundleoperationrm  modesr*  r+  r   r(  rS   r'  combinechangegroupresultsr  _pullapplyphasesr   rG  r  )r  kwargsr/   	streamingservernarrowr  hasbinaryphasebookmarksrequestedlegacybookmarkhasbinarybookr  r  r3  argsbundler   r  r  rD   r  records                        r7   r  r  I  s    Z)DEF 
B 11&$GJI F9||4v}}F8 ==(()A)ABL**!'!3!3~**!'!3!3~u y^,Y' 	^,u2==;M#NN!V%=%=%A%A)R%PP~ $F9  +&222 0 00'0k{#!R]]8=O%PPN F$<$<<M)12 	F$4$44""*#|!f...v'7'77   !56k2.55lC 	o..LL FKK$6$6#77!'!<!<~a :;<\\a 567<<D$7FKK<N<N;O$OKKNN!!!$?"@A&++x';';<< 2263K3KL!!.1=$(F=!  /V,99&--HO%4!"		&	&	(AF|!Y|T299;	H((%%}}	B &0BHH\"!!}}	 
)2 ||!;;B? JJ{3	5	!VU+ 4
 jj.F)/E&%& /!& "

; 7IuL()0)C)CE)J& !8
 )v *5 $$ 	PKKNN  #9!:S!@A##A&>$?chhOO%% 	H##A&?$@3$FGG	H- 
)	(s8   .1\' A/Y99\$A[&&\$="\\$$\''
\6c                    g)z>hook function so that extensions can extend the getbundle callNr   )r  r  s     r7   r  r    s    r9   c           	        SU R                   ;   a  gU R                   R                  S5        U R                  (       d6  U R                  R                  R                  [        S5      5        SU l        gU R                  5       nU R                  c]  [        U R                  5      U R                  R                  /:X  a/  U R                  R                  R                  [        S5      5        O>U R                  c1  U R                  R                  S5      (       a  U R                  U l	        U R                  R                  S5      (       aC  U R                  R!                  SU R                  U R                  =(       d    U R                  S	9nOU R                  cQ  U R                  R#                  5        nUR%                  SU R                  SS
.5      R'                  5       nSSS5        OU R                  R                  S5      (       d  [(        R*                  " [        S5      5      eU R                  R#                  5        nUR%                  SU R                  U R                  SS.5      R'                  5       nSSS5        [,        R.                  " U R                  WUSU R                  R1                  5       U R                  S9n[,        R2                  " U5      U l        g! , (       d  f       No= f! , (       d  f       N= f)z0pull changeset from unbundle into the local reporO   Nr  r   r  s   changegroupsubsetr  r  rn   rk   )s   nodesru  sW   partial pull cannot be done because other repository doesn't support changegroupsubset.)s   basesr  ru  r  )r   r   r[  rm   r/   r   r   r   rm  rk   rT  rn   rj   r|   r   rZ  	getbundler$  r%  r&  r   r+   r	   applybundler   r  )r  r  r<  r3  bundleops        r7   r  r    sK   
 )))
(<<a 567				 B||V]] 38J8J7K Ka ;<=		&--"7"78L"M"M}}}}\**]]$$FMM1N % 
 
	]]**,$ll& fh  -, ]]""#788kk&
 	
 ]]**,$$ll$ll& fh  - ""

}}H 77AFOI -,$ -,s   6.K(9K9(
K69
Lc                h    SU R                   ;   a  g [        U R                  S5      n[        X5        g )Nrw   )r   r{   r|   r  )r  r   s     r7   r  r  "  s+    F$$$FMM95LV*r9   c           	        SU R                   ;   a  gU R                   R                  S5        [        UR                  SS5      5      nU(       a  U(       d  U R                  R                  5       nUR                  R                  R                  nUR                  R                  nU R                   Vs/ s H
  od" U5      PM     nn[        R                  " U R                  UU5      u  pU V
s/ s H
  o" U
5      PM     nn
U R                  nOU R                  n/ nU R                  R                  5       nUR                  R                  nUR                  R                  R                  n[        R                   n[        R"                  nU Vs/ s H  nU" X>" U5      5      U:  d  M  UPM     nnU(       a2  U R%                  5       n[        R&                  " U R                  UX5        U Vs/ s H  nU" X>" U5      5      U:  d  M  UPM     nnU(       a4  U R%                  5       n[        R&                  " U R                  UUU5        ggs  snf s  sn
f s  snf s  snf )z/apply phase movement from observed remote staterw   Nrx   F)r   r   r  r}   rm   r   rh   r   r   r   rd  r   r@  r-  r  get_revr  r/  rm  rH  )r  r   r,  r   r   r   rp   pulledsubset_revsrB  rC  r   rD  dheadsr  r   r  r/  pnr  s                      r7   r  r  *  s   F$$$
#l&&}e<=JJ{{%%'%%))..%%060C0CD0C1VAY0CD!77KK

 '22k'!*k2$$ $$;;!!#D""E
..


&
&C]]FLLE "C6RU4R%9F%Bb6FC""$v{{B? "B6RU4R%9E%Ab6FB""$v{{Bv> 9 E 3 D Cs$   4I/II+I0I
Ic           
     v   SU R                   ;   a  gU R                   R                  S5        U R                  nU R                  nSnU R                  b  U R                  R
                  n[        R                  " UR                  UUU R                  R                  5       U R                  U R                  US9  g)z?process the remote bookmark information to update the local onerD  N)rO  mode)r   r   rm   r\  rW  bookmarks_moder   updatefromremoter/   r|   r   rm  rX  )r  rm   r\  r  s       r7   r  r  U  s    v'''
&;;D,,ON%++::))r9   c                   SU R                   ;   a  gU R                   R                  S5        Sn[        R                  " U R                  [        R
                  5      (       a  U R                  R                  R                  S5        [        U R                  S5      nSU;   a  U R                  5       n/ n[        USS9 HO  nUR                  S5      (       d  M  [        R                  " X$   5      n[        R                  " U5      u  pgX7-  nMQ     U(       a%  U R                  R                   R                  X5        U R                  R#                  5         U$ )	aF  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 purposerT   Ns!   fetching remote obsolete markers
r=  s   dump0TrN  s   dump)r   r   r   r?  rm   r@  r/   r   r{   r|   rm  r<   r(   r   	b85decode_readmarkersrA  invalidatevolatilesets)r  r  	remoteobsr  rC   rz  r6   newmarkss           r7   r  r  j  s
    (((
'	B&++x';';<<BCV]]K8	y &&(BGi6>>'**>>).9D(0(=(=d(C%G'G	 7
 $$((5KK..0Ir9   c                   U R                   nUR                  UR                  R                  S5      =(       d    UR	                  5       5      nUR                  [        US-   UR                  [        S5      5      nUR                  [        US-   UR                  [        S5      5      nU(       d(  [        R                  " [        S5      [        U4-  5      eU Vs/ s H  ofS:X  a  SOS	U-   PM     nnU Vs/ s H  ofS:X  a  SOS	U-   PM     nn[        UR                  S
/ 5      5      n[        UR                  S/ 5      5      n[        R                  " XxXE5      u  pxn	U	(       a8  [        R                  " [        S5      U[        R                  " U	5      4-  5      e0 n
U
R                  U5        SU
S'   SU
S'   XzS
'   U(       a  XS'   U
$ s  snf s  snf )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 empty   *s   path:.s   path:r^  r_  s4   The following includes are not accessible for %s: %sTnarrow
narrow_acl)r/   	shortuserenvironr}   usernamer   _NARROWACL_SECTIONr   r+   r   r   r   restrictpatternsr   pprintr   )rm   r  r/   r  user_includesuser_excludesr  req_includesreq_excludesinvalid_includesnew_argss              r7   applynarrowaclr    s    
B||BJJNN>:KbkkmLHMM<
(*=>M
 MM<
(*=>M
 kk67!8,-
 	
 ;H:GQ$Y	HqL0-   ;H:GQ$Y	HqL0-   vzz-45Lvzz-45L3=3N3NM40L 0 kkEF**+;<=>
 	

 HOOFHX!H\*]".O9s   G9Gc           
     ,  ^ ^"^#^$ T R                   nT R                  nUR                  nU V	s1 s H
  o" U	5      iM     sn	[        1-  n
U V	s1 s H
  o" U	5      iM     nn	U(       a  U Vs0 s H  oS_M     nn[        R
                  " [        5      n[        R
                  " [        5      m"U"U#U$4S jnU"4S jm$U"U 4S jm#[        UR                  XS95      n[        U5      n[        5       nU Vs/ s H  nUR                  U5      PM     nn[        U5      U-  nU GH5  nUR                  U5      nUR                  U5       Vs/ s H  nU[        :w  d  M  UPM     nnUb3  WU   nU H(  n[        US-   UR                  UUS-   5      5      UU'   M*     SnUSL =(       d    WU   U:*  nU(       a  XxR                     R!                  5       nU(       a  XvR                  US   5      R                     R!                  5       n[#        UR%                  UU5      5      nU(       dX  ['        U5      S:  aI  XvR                  US   5      R                     R!                  5       n[#        UR%                  UU5      5      nO[)        UR+                  U5      5      nU(       aR  UU    H  n U" U U5        M     U H  nUR-                  U5        M     UR-                  UR                  U5      5        GM  U(       d  [        /nUU;   a5  UU    H  n U" U U5        M     U H  nUU   R-                  U5        M     GM  U H  nUU==   UU   -  ss'   M     GM8     U
 H  n!UU!    H  n U" U U!5        M     M     UUT"4$ s  sn	f s  sn	f s  snf s  snf s  snf )	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.
r   c                   > TU    R                  U5        [        TU    5      S:  a*  T" U 5      u  p#T" XU5        Un [        TU    5      S:  a  M)  gg)z=Add a root to an ellipsis head, splitting heads with 3 roots.r$   N)r   r   )head	curchangechildrootsellipsisroots	splithead
splitrootss       r7   addroot!_computeellipsis.<locals>.addroot  sX    d	*
 -%&*$T?LEtE*D -%&*r9   c                   > TU    R                  U5        TU    R                  U5        TU   R                  U5        TU   R                  U5        g r   )difference_updater   r   discard)r  r  r  r  s      r7   r  $_computeellipsis.<locals>.splitroots  sO    d--e4d&e##E*e$$U+r9   c                &  > [        TU    5      u  pnX#4X4X44 HP  u  pET	R                  SX@XP5      nU H2  nXu:X  a	  XTU44s  s  $ UT;  d  [        TU   5      S:  d  M+  XtU44s  s  $    MR     [        R                  " [        S5      XX#4-  5      e)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  rm   s
           r7   r  #_computeellipsis.<locals>.splithead  s    M$/0
B8bX6HC))8#SC 8c
?*M)Sq1A-BQ-FCj=(	 	 7 kk#  	!
 	
r9   r  Nr   F)rh   manifestlogr   r   collectionsdefaultdictr   rT  findmissingrevsreversedr   changelogrevisionr   minr}   r  readr  diffr   r  walkr   )%rm   rn   rk   knownmatchr`  ro   mflclrevrp   
commonrevs	headsrevsr  revdepthellipsisheadsr  r   visitrelevant_nodesm
visitnodesrequiredr   prevpscurdepthr  neededshallow_enoughcurmfp1mfp2mfr  rF  r  r  r  s%   `                                 @@@r7   _computeellipsisrC    sD   . 
B


CFFE$*+Fq%(F+wi7J#()5aq5I)"+,)QqD),++C0M++C0M
,
& 2%%Z%IJGWEUN&-.g"''!*gJ.9~%H$$S)!}}S1E1tTW_d1E}H!(Q,Q	0JK $@(3-5*@',,.E //16??@EEGejju56#b'A+
 33BqE:CCDIIKD!%**T5"9:F UZZ./%c*c" +Q rwws|,Yh)#.DD#& /A!!$((-  A!!$c(::$ Y ` !!$DD! %  ~}44M ,) -Z / Fs#   M=N+N3NNNc                    S1n[         R                  " [         R                  " XS95      nUR                  S[        R                  U5      -   5        U$ )zFreturn a set with appropriate options to use bundle20 during getbundles   HG20r     bundle2=)r	   r  r  r   r>   r?   )rm   r  capsr.  s       r7   r  r  D	  sC    9D!!'"5"5d"FGHHH[6<<112Kr9   c                   ^ ^ UU 4S jnU$ )av  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[         ;  d   eU [         T'   Tc  [        R                  T5        U $ [        R                  TT5        U $ r   )getbundle2partsmappinggetbundle2partsorderr@   rq  rr  s    r7   r
  %getbundle2partsgenerator.<locals>.dec_	  sN    5555+/x(; ''1  !''X6r9   r   ru  s   `` r7   getbundle2partsgeneratorrL  U	  rw  r9   c                .    U b  [        S U  5       5      $ g)Nc              3  B   #    U  H  oR                  S 5      v   M     g7f)s   HG2N)r(   )r  caps     r7   r  #bundle2requested.<locals>.<genexpr>m	  s     @Zc>>&))Zs   F)r  )r  s    r7   bundle2requestedrQ  k	  s    @Z@@@r9   c           
     z   [         R                  " U5      n0 n[        U5      nU(       d  U(       a+  UR                  SS5      (       d  [	        [        S5      5      eU(       a=  [	        [        S5      SR                  [        UR                  5       5      5      -  5      e[        XU5      n	SUS'   U[        R                  " U U	SUUUS	94$ S
US'   0 n
U Ha  nUR                  S5      (       d  M  [        R                  U[        S5      S 5      nU
R!                  ["        R$                  " U5      5        Mc     ["        R&                  " U R(                  U
5      nX&S'   X6S'   [*         H/  n[,        U   nU" UU U4UU
US.[         R.                  " U5      D6  M1     UR0                  US'   X}R3                  5       4$ )zReturn 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   bundleversionrQ   r  r$   rE  Nr  r  )r  r  r  s   prefercompressed)r   byteskwargsrQ  r}   
ValueErrorr   r*   r<   keysrq   r   r  r(   r>   rZ   r   r   r	   
decodecapsr  r/   rJ  rI  r   prefercompressedr#  )rm   rq  rk   rn   r  r  r  info
usebundle2rl   r  bcapsblobr~  namer  s                   r7   getbundlechunksr]  q	  s   " !!&)FD!*-Jfjj55BC  89**VFKKM234  $D8!"""% /

 
	
 D	FK((>>%K(8(:";<DMM',,T23  tww/G89$%d+	
 "+	
   (	
 % !( 8 8D	""$$$r9   r"   c                0    [         R                  " X40 UD6$ r   )r	   addpartbundlestream2)r~  rm   r  r  s       r7   _getbundlestream2r`  	  s    ''@@@r9   c           
     b   UR                  SS5      (       a  U(       d  gSn	UR                  S5      n
U
(       a_  U
 Vs/ s H!  nU[        R                  " U5      ;   d  M  UPM#     n
nU
(       d  [        R                  " [        S5      5      e[        U
5      n	[        XU5      nUR                  (       d  gUR                  SS5      (       ar  [        [        [        UR                  S	/ 5      5      5      n[        [        [        UR                  S
/ 5      5      5      n[        R                  " UR                  XS9nOSn[        R                  " UUU	UUUUS9nU R!                  SUS9nU
(       a  UR#                  SU	5        UR#                  SS[%        UR                  5      -  SS9  [&        R(                  " U5      (       a  UR#                  SS5        [*        R,                  UR.                  ;   a:  UR#                  SS5        [0        R2                  " U5      nUR#                  SU5        UR                  SS5      (       ac  UR                  SS5      (       aK  W(       d  W(       a<  U R!                  S5      nSSR5                  U5      SR5                  W5      4-  Ul        ggggs  snf )z.add a changegroup part to the requested bundler<  TNrQ   rO   r  r  Fr^  r_  )includeexclude)r  matcherr  ry  rP   s	   nbchangesr  r  r  r  r  s   exp-wanted-sidedatar  s   Narrow:responsespecs   %s %s   
)r}   r   r  r   r+   r   r  rq   r   r<   filterr  r   r/  rootr  r|  r  r   r   r  r   r  r  r	   format_remote_wanted_sidedatar*   rz  )r~  rm   rq  r  r  rk   rn   r  r  r6   r  r  rl   rb  rc  rd  r  ra   sidedatanarrowspecparts                       r7   _getbundlechangegrouppartrk  	  sG    ::dD!!GN+J  
K99$??  	 

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

8U##JJ|U++ !)?@'JJwJJw+
 
	   , 	$[
s   J, J,c                   UR                  SS5      (       d  gU(       a  SU;  a  [        R                  " [        S5      5      e[        R
                  " U5      n[        R                  " X5      nU(       a  U R                  SUS9  gg)z+add a bookmark part to the requested bundler   FNrD  s#   no common bookmarks exchange methodry  )r}   r   r+   r   r   listbinbookmarksr  r|  )r~  rm   rq  r  r  r  r  rz  s           r7   _getbundlebookmarkpartrn  
  so    
 ::k5))\/kk!BCDD$$T*E,D40 r9   r  c                    UR                  SS5      nU H`  nU R                  S5      nUR                  SU5        UR                  U5      R	                  5       n	[
        R                  " U	5      Ul        Mb     g)z@add parts containing listkeys namespaces to the requested bundler{   r   r  r  N)r}   r|  r  r{   r=   r   
encodekeysrz  )
r~  rm   rq  r  r  r  r{   r  ra   rU  s
             r7   _getbundlelistkeyspartsrq  
  sc    
 zz*b)H	{+lI.}}Y'--/&&t,		 r9   c                   UR                  SS5      (       a  UR                  5       R                  nUc  UR                  R                  5       nOCUR                  R
                  n	U V
s/ s H
  o" U
5      PM     nn
U Vs/ s H	  oc  M  UPM     nnUR                  USS9nUR                  R                  US9n[        R                  " U5      n[        R                  " X5        ggs  sn
f s  snf )z8add an obsolescence markers part to the requested bundle
obsmarkersFNTr   r>  )r}   r   rh   r1  r   r  r   rA  rB  r   r  r	   r  )r~  rm   rq  r  r  rk   r  unfi_clr1  r  r   r   r~   r  s                 r7   _getbundleobsmarkerpartru  )
  s    
 zz,&&//#--=~~..0Hmm++G278%$%H8'/CxxHC  T :--//T/:''0##G5 ' 9Cs   *C*C/C/rw   c                   UR                  SS5      (       Ga(  U(       a  SUR                  S5      ;  a  [        R                  " [        S5      5      eUc  UR	                  5       n[
        R                  " [        5      nUR                  5       (       a  XW[        R                  '   GOEUR                  R                  nUR                  R                  n	UR                  R                  n
U H"  nXx" X" U5      5         R!                  U5        M$     [#        UR%                  5       5      nU(       a  ['        U5      [        R(                  ::  d   eUR                  [        R(                  [        5       5      nU(       am  UR                  [        R                  [        5       5      nSnUR+                  XU5      nU H+  nU[        R                     R!                  U	" U5      5        M-     [        R,                   Vs0 s H  o[/        Xx   5      _M     nn[        R0                  " U5      nU R3                  SUS	9  ggs  snf )
z,add phase heads part to the requested bundler   Fr  rw   s    no common phases exchange methodNs"   heads(only(%ln, %ln) and public())r  ry  )r}   r   r+   r   rk   r%  r&  r   r,  r   r  r-  r  rh   r   r   r   rT  rU  r  r/  r~   r  r<   r  r|  )r~  rm   rq  r  r  rk   r  headsbyphaser  r   r   r  
seenphases
draftheadspublicheadsr8  
extraheadsr   phasemappingr  s                       r7   _getbundlephasespartr}  <
  s   
 zz(E""I)>>++a CDEE=JJLE"..s3??*/' $$**E>>&&D..$$CU4Q0155a8 l//12J :&,,666 &))&,,>J*..v}}ceD>!YYv;G
#A /33DG< $
 =C<L<L
<L56,-..<L 	 

 ''5	Y7S #F
s   I   hgtagsfnodesc                    U(       a  UR                  SS5      (       a  SU;   d  g[        XU5      n[        R                  " XU5        g)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<  Tr~  N)r}   rq   r	   addparttagsfnodescache	r~  rm   rq  r  r  rk   rn   r  rl   s	            r7   _getbundletagsfnodesr  m
  s=    * &**T400_5NV4H""4(;r9   s   cache:rev-branch-cachec                
   UR                  SS5      (       aH  U(       aA  SU;  d;  UR                  SS5      (       d$  UR                  R                  [        5      (       a  g[	        XU5      n[
        R                  " XU5        g)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  rq   r	   addpartrevbranchcacher  s	            r7   _getbundlerevbranchcacher  
  sf    4 JJtT""f,::h&&77122V4H!!$:r9   c                    U R                  5       n[        R                  " SR                  [	        U5      5      5      R                  5       nUS/:X  d(  X:X  d"  USU/:X  d  [        R                  " SU-  5      eggg)zNcheck if the heads of a repo have been modified

Used by peer for unbundling.
r9   r  s   hasheds.   repository changed while %s - please try againN)rk   r   sha1r*   r<   digestr   	PushRaced)rm   their_headscontextrk   
heads_hashs        r7   check_headsr  
  sz    
 JJLEsxxu67>>@Jz!9j11 oo=G
 	
	 2   	"r9   c           	       ^ ^^^^^ Sm/ SQmSnT R                   R                  SS5      nTR                  S5      (       d  TR                  S5      (       a  Sn [        T US	5        [	        U[
        R                  5      (       d  S
R                  T[        R                  " T5      /5      nT R                  5          T R                  U5       n[
        R                  " T XTT5      n	[
        R                  " U	5      mSSS5        SSS5        OSm UU UU4S jn
T R                   R                  SS5      (       d  U
" 5         [
        R                  " T U
USS9n	 [
        R                  " T XS9n	U	R                   mU(       a#  Tb   T R                   R#                  SSS9  U4S jnTS   b  TS   R%                  5         [.        R0                  " TS   TS   TS   5        Ub   U" T R                   R3                  5       5        T$ ! , (       d  f       GN= f! , (       d  f       Nf= f! U	R                   mU(       a%  Tb!  T R                   R#                  SSS9  U4S jnf f f = f! [&         a4  nSUl        U(       a   Tb  TR+                  5       =mUl        U4S jne SnAff = f! [.        R0                  " TS   TS   TS   5        Ub!  U" T R                   R3                  5       5        f f = f)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   NNNNrs   s   bundle2-output-captures   remote:http:s   remote:https:Ts   uploading changesre  c                 8  > T S   (       d  [         R                  " T5      (       d  TR                  5       T S'   TR                  5       T S'   TR	                  T5      T S'   TT S   R
                  S'   TT S   R
                  S'   ST S   R
                  S'   T S   $ )Nr$   r   r   ru  r  r  r   )r   r   r   r   r)  rw  )	lockandtrrm   rq  r   s   r7   rm   unbundle.<locals>.gettransaction
  s    $Q<&77==+/::<IaL'+yy{	!'+'7'7'?	!;A	!--i88;	!--f5<@	!--j9$Q<'r9   s   bundle2lazylockingr  )captureoutputrq  )r   )r   subprocc                (   > TR                  SU SS9  g Ns   outputF)rz  r]   )r|  )outputr   s    r7   	recordoutunbundle.<locals>.recordout  s    IIifINr9   r$   c                T   > [         R                  " SU SS9nTR                  U5        g r  )r	   
bundlepartr@   )r  ra   rB   s     r7   r  r    s(    &11%Fe  T*r9   r   )r/   r   r(   r  rU   r	   rW   r*   r   rv  r   r)  r  r  r  r*  r4  
pushbufferr   BaseExceptionduringunbundle2salvageoutput_bundle2salvagedoutputr   r   	popbuffer)rm   r<  rk   rq  r   r  r  r  r  r   rm  r  r  rB   r   s   `  ``       @@@r7   r;  r;  
  s    	
A #IIGG&&2M ~~o&&#..9I*J*JB+ 	D%!56"g0011jj&'*>*>s*C!DEGd..w72((rvsC55b9 8 A1	( 	( ww))#%:  #$,,""/"	O ..tR?BA$**t*DO Q<+aL&&( 		!ilIaLA dgg'')*Hw 87D A$**t*DO *7} ! &*# Q]9:9JJEC6+  		!ilIaLA dgg'')* !sv   A#J' =H0H?HJ' AI& H) 1AI& 
H	H
H&"J' ):I##I& &
J$0/JJ$$J' 'AK.c           
     d   U R                   nU R                  nUR                  R                  SS5      (       d  g[	        U5      (       a  gU R
                  (       a  gUR                  S5      (       d  gUR                  5        nUR                  S0 5      R                  5       nSSS5        SU l
        [        R                  " UW5      nU(       d%  UR                  R                  [        S5      5        g[        R                  " XU R                   S9nU(       dI  UR                  R#                  [        S5      5        UR                  R#                  [        S5      5        g[        R$                  " UR                  U5      nUS	   S
   nUS	   R'                  S5      nU(       a  [(        R*                  R,                  R/                  5       n[1        [3        U[5        [	        U5      5      5      5      n	Sn
[	        U	5      nUR7                  S5       H-  nUR7                  S5      u  pX;  a  M  X   U:  d  M'  Un
X   nM/     U
nUR                  R9                  [        S5      U-  5        [;        UR                  XX'5      (       a%  UR                  R9                  [        S5      5        gUR                  R                  SS5      (       a%  UR                  R#                  [        S5      5        g[<        R>                  " [        S5      [        S5      S9e! , (       d  f       GN= f)z0Apply a clone bundle from a remote, if possible.r(  r  NTsD   no clone bundles available on remote; falling back to regular clone
)rY  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   DIGEST   ,   :s   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"rR   ) rm   r|   r/   r   r   rk   r   r$  r%  r&  r]  r
   parseclonebundlesmanifestnoter   filterclonebundleentriesrY  r   sortclonebundleentriesr}   urlmoddigesthandlerdigest_algorithmsrU  r  zipranger[   r   trypullbundlefromurlr   r+   )r  rm   r|   r3  r  entriesr   r  
algorithms
preference
best_entrybest_preferencedigest_entrycur_algo
cur_digests                  r7   r  r    s    ;;D]]F77e_55 4yy||>>/**				!QmmOR0779 
"
 #'F44T3?G3	
 	33F,G,GG  	3	
 	GH	
 	11$''7CG
!*V
CQZ^^I&F));;@@B
#j%J*@AB

j/"LL.L#/#5#5d#; H)#o5)
","6 / GGNN1783>?DGGT??q<=> 
		E#9	:	:Q89:kk&'4
 	
G 
"	!s   !L  
L/c                    U(       d"  [         R                  " [        SU-  5      5      eU[        [        R
                  5      S  nUR                  U5      n[        R                  " U5      $ )Ns$   no remote repository supplied for %s)	r   r+   r   r   r
   CLONEBUNDLESCHEMEget_cached_bundle_inliner   r"  )r/   r   peerclonebundleidpeerclonebundles        r7   inline_clone_bundle_openr  |  sX    kk!CcIJKKL::;=>M33MBOO,,r9   c           	     r   UR                  5          UR                  S5       n UR                  [        R                  5      (       a  [        XU5      nO[        R                  " XUS9n[        XS5      n[        U[        R                  5      (       a  UR                  U5        O[        R                  " XUSU5         SSS5        SSS5        g! [        R                    a;  nU R#                  [%        S5      [&        R(                  " U5      -  5         SnAO_SnAf[        R*                   aE  nU R#                  [%        S5      [&        R(                  " UR,                  5      -  5         SnAOSnAff = f SSS5        SSS5        g	! , (       d  f       O= fSSS5        g! , (       d  f       g= f)
z%Attempt to apply a bundle from a URL.s	   bundleurl)r  r"   r  NTs   HTTP error fetching bundle: %s
s   error fetching bundle: %s
F)r   r)  r(   r
   r  r  r  openr8   rU   r   r.   applyr	   r  urlerr	httperrorr   r   r   r   urlerrorreason)	r/   rm   r   r  r  r  r0   r<  r3  s	            r7   r  r    s;   	d&&|4	~~l<<==-bt<[[8BI.B"k<<==##Db/3G 5  	GG56))!,-   	GG01))!((34 	 1 544s^   F(FBCF(E9'1DFE94;E4/F4E99F=F(
F	F((
F6r   r   )
NNFr   NNNNNN)NNNN)NNNNN)NNr  )
__future__r   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  r8   rE   rf   rq   r   r   r   r  r  r  r  r  r   r   r&  r;  rC  rP  rK  rl  rp  ro  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r  r?  r   r   rU  transactionalr   r{   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rC  r  rJ  rI  rL  rQ  r]  r`  rk  rn  rq  ru  r}  r  r  r  r;  r  r  r  r   r9   r7   <module>r     s   #        , 
 #		! 
>S=l3(#.L= Y& Y&~ 	

#$	
*+
 	

$%	
+,
 	

*+	
12
& 	qj  
  &(& | 4 xC- C-L |K K" |O O(9x#N 
  ,C6 $%8 &8 /"= #=. ,3  3l (5 5"8"J - 	6 !	6 ,8  8
.-` +1%7 &7*=@-Q`GT *0 ,* $F\, \,~++ @N
';T0, 



|@  
  & ?  ? ~ @RjI=B@+(?V*:5pB5J  
  , H%V )$A %A .)
 
H
 *H
V ,'371 (1 +&37	- '	- -(?C6 )6$ )$?C-8 %-8` /*
 
< +<6 34
 
"; 5";J
&Vr^
B-r9   