o ]Lbz@sddlmZddlZddlZddlmZddlmZmZddl m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$ddl%m&Z&ej'Z'ej(Z(d Z)dd d Z*d d Z+ddZ,ddZ-ddZ.Gddde/Z0ededfededfededfdZ1      ddd Z2gZ3iZ4d!d"Z5d#d$Z6d%d&Z7e5d'd(d)Z8e5d*d+d,Z9e5d-d.d/Z:e5d0d1d2Z;d3d4ZiZ?dd7d8Z@d9d:ZAd;d<ZBe@d=d>d?ZCe@d@dAdBZDe@d'dCdDZEe@d*dEdFZFdGdHZGdIdJZHe@dKdLdMZIe@d0dNdOZJdPdQZKdRdSZLdTdUZMdVdWZNe@dXddYdZd[ZOd\d]ZPd^d_ZQd`daZRejSfdbdcZTdddeZUdfdgZVGdhdidie/ZWGdjdkdkejXZYdldmZZdndoZ[dpdqZ\          ddrdsZ]gZ^iZ_dtduZ`dvdwZae`dxdydzZbe`d{d|d}Zcd~dZdddZeddZfddZgddZhddZiddZjddZkdddZlddZmgZniZodddZpddZq    dddZrepdddZsepd{     dddZtepd0 dddZuepd dddZvepdK dddZwepd dddZxepd    dddZyepd    dddZzddZ{ddZ|ddZ}ddZ~dS))absolute_importN)_)hexnullrev) bookmarksbundle2 bundlecaches changegroup discoveryerrorlock logexchange narrowspecobsoleteobsutilphasespushkeypycompat requirementsscmutil streamcloneurlutilwireprototypes)hashutil stringutilurlutil) repositorys narrowaclcCst|d}d}|s!d}|ds |dr t||}d}d}n|r(||}|dd|dd}}|dkrBttd ||d krV|durPt|d}t||S|d ret j ||||d S|d krnt |Sttd||f)NstreamsHGsHG10sUNrs%s: not a Mercurial bundles102) magicstringsS1s%s: unknown bundle version %s) r readexactly startswithheaderlessfixupjoinr Abortr cg1unpackerr getunbundlerrstreamcloneapplier)uifhfnamevfsheaderalgmagicversionr54/usr/lib/python3/dist-packages/mercurial/exchange.py readbundle5s2       r7c Csdd}t||d}t|tjr,|j}|dkrd}||}|s(ttd|d|St|tj rd|j vrJ||j d}|sIttd|nd }d}| D]@}|j d krr|j d }|d vred }qRtjtd|tdd|j dkr|durt |j d}|} t| } d| SqR|sttdd||fSt|tjrt|d}t|} d| Sttd|)zInfer the bundlespec from a bundle file handle. The input file handle is seeked and the original seek position is not restored. cSs,z tj|dWStyYdSwNr)r compengines forbundletype bundletypeKeyError)r2r5r5r6speccompression[s  z&getbundlespec..speccompressionNs _truncatedBZsBZs!unknown compression algorithm: %ss%s-v1s Compressionsnone changegroupversion)01s02sv2s7changegroup version %s does not have a known bundlespecs#try upgrading your Mercurial clienthintstream2s requirementssnone-v2;stream=v2;%ss0could not identify changegroup version in bundles%s-%sr"snone-packed1;%ssunknown bundle type: %s)r7 isinstancer r*_typer r)rr unbundle20params iterpartstypeurlrequnquotesplit_formatrequirementsparamsrr,readbundle1header) r-r.r=br2compr4partrsplittedrG formattedr5r5r6 getbundlespecTsb             rTcsF|j}|r|jfdd|D}n|jg}|s|}t|||S)zComputes which revs are outgoing given a set of common and a set of heads. This is a separate function so extensions can have access to the logic. Returns a discovery.outgoing object. csg|]}|r|qSr5r5.0nhasnoder5r6 z$_computeoutgoing..) changelogrYnullidheadsr outgoing)repor^commonclr5rXr6_computeoutgoings rccCs |j}|j}|dd}|js|dvrdSt|jd}|dds#dS|jdur1|dd}n|d |j}||dM}|r|d krR| t d t |dS|d krj| t d t |rht t ddS|dkrt dt |}t d}t j||ddSdS)N experimentals auto-publish)warnconfirmabortphases publishingFsserveds not public()s::%ln - public()res$%i changesets about to be published rfs2push and publish %i changesets (yn)?$$ &Yes $$ &Nos user quitrgs push would publish %i changesetss:use --publish or adjust 'experimental.auto-publish' configrA)r`r-configpublishlistkeysremotegetrevsfilteredwarnrlen promptchoicer CanceledErrorr))pushopr`r-behavior remotephases publishedmsgrBr5r5r6 _checkpublishsB     rzcCs6|jj}|dd}d|vod|v}|p|jd S)zsreturn true if a pull/push must use bundle1 This function is used to allow testing of the older bundle versiondevellegacy.exchangebundle2sbundle1)r`r- configlistrmcapable)opr-exchange forcebundle1r5r5r6 _forcebundle1s rc@sNeZdZdZ      d ddZejddZejd d Ze d d Z dS) pushoperationzA object that represent a single push operation Its purpose is to carry push related state and very common operations. A new pushoperation should be created at the beginning of each push and discarded afterward. FNr5c Cs||_|j|_||_||_||_||_||_t|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_t|_g|_d|_i|_||_||_dSN)r`r-rmforceror newbranchset stepsdonecgresultbkresultr_ remoteheads pushbranchmapincomingrwoutdatedphasesfallbackoutdatedphases outobsmarkers outbookmarks trmanagerpkfailcbpushvarsrk) selfr`rmrrorrrkrr5r5r6__init__s.   zpushoperation.__init__cCs|jjS)z2future remote heads if the changeset push succeeds)r_ ancestorsofrr5r5r6 futureheads6szpushoperation.futureheadscst|jdur |jjS|j}|jj|jjjjfdd|jD}| d|jj|jj }| dd|D|S)z/future remote heads if the changeset push failsNcsg|] }|vr|qSr5r5)rVnoderarevr5r6rZRz/pushoperation.fallbackheads..s%ln and parents(roots(%ln))cs|]}|VqdSrrrVcr5r5r6 Zz.pushoperation.fallbackheads..) ror_ commonheadsr` unfilteredrar\indexrrmissingextend)runficheadsrevsetr5rr6 fallbackheads;s   zpushoperation.fallbackheadscCs|jr|jS|jS)z3set of all common heads after changeset bundle push)rrrrr5r5r6r]szpushoperation.commonheadsFNFr5FN) __name__ __module__ __qualname____doc__rr propertycacherrpropertyrr5r5r5r6rs  K  !rsupdating bookmark %s supdating bookmark %s failed sexporting bookmark %s sexporting bookmark %s failed sdeleting remote bookmark %s s#deleting remote bookmark %s failed )updateexportdeleteFr5c Cs|duri}t|||||||fit|}|jr:t|jj|jj} | r:t dd t | } t | |jsFt t d|jdsSt t dt t|jD]} |jD] \} } | | rmn qbt t dt| q[d}}z)|jdd }t|s|rt|s|j}|j}t|jd |j|_Wn t j y}zd t!"|} |j#| WYd}~nd}~ww|pt$%d|pt$%M|jpt$%5|j&|t'|t(||j)st*|t|st+|t,|t-|t.|t/|Wdn 1swYWdn 1s'wYWdn 1s7wY|jdd rJt01|||S) aWPush 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 pushunbundlesLcannot push: destination does not support the unbundle wire protocol commandsJcannot push: required sidedata category not supported by this client: '%s'rdbundle2.pushbacks push-responses"cannot lock source repository: %s remotenames)2rr strkwargsrmlocalrr`r supportedrr(sortedr r)canpushrrread_remote_wanted_sidedata_sidedata_computersitemsrnbytestrr- configboolrbookmodbookmarksinstorewlockr transactionmanagerrrLockUnavailabler forcebytestrdebugrnullcontextmanager checkpushrz_pushdiscoveryr_checksubrepostate _pushbundle2_pushchangeset_pushsyncphase _pushobsolete _pushbookmarkrpullremotenames)r`rmrrorrrkopargsrurrycategorykind computersrr maypushbackerrr5r5r6pushws              rcfdd}|S)a|decorator for function performing discovery before push The function is added to the step -> function mapping and appended to the list of steps. Beware that decorated function will be added in order (this may matter). You can only use this decorator for a new step, if you want to wrap a step from an extension, change the pushdiscovery dictionary directly.c"tvsJ|t<t|Sr)pushdiscoverymappingpushdiscoveryorderappendfuncstepnamer5r6dec  zpushdiscovery..decr5rrr5rr6 pushdiscovery rcCtD] }t|}||qdSzRun all discovery stepsN)rr)rurstepr5r5r6r rcCs~|j}t|drt|dsdS|jjD]%}||}d|vr.)r_r`rrlrmr-rrrnrrrremotephasessummaryrrw draftroots publishinglistrrkr) rur_rrwdroots extracondrfallbackfuturefdrootsr5r5r6_pushdiscoveryphase8sL      rs obsmarkercCsft|jtjs dS|jjsdSdt|jdvrdS|j}dd|d|jD}|jj ||_ dS)Nobsoletes namespacescsrrrrr5r5r6rrz+_pushdiscoveryobsmarkers..::%ln) r isenabledr` exchangeoptobsstorerlrmrrrelevantmarkersr)rur`nodesr5r5r6_pushdiscoveryobsmarkerswsr bookmarkscs|j}|j|j}|dd}|jr&tjj |j}jj |dd}t t |d}fdd|jD}t j|}t|||||S)Nschecking for updated bookmarks r5T) inclusivercsh|]}j|qSr5 _bookmarks expandnamerVbookmarkr`r5r6  z*_pushdiscoverybookmarks..)r-r`rrmrrormaplistr\r ancestorsrunhexlifybookmarksrlrcomparebookmarksr_processcompared)rur-rmr%revnumsremotebookmarkexplicitrPr5r!r6_pushdiscoverybookmarkss   r,cCs|\}}}}} } } } |j} |D]!\}}}||vr|||r'| ||vr0|j|||fq|D]*\}}}||vr]||t|rT|jt d|d|_ q3|j|d|fq3t |t | t | D]\}}}||vr|||j|||fqj|D]\}}}||vr|||j||dfq| D]\}}}||vr||q|rt |}|jt d|dd|_ |j dS)zntake decision on bookmarks to push to the remote repo Exists to help extensions alter this behavior. s#cannot push divergent bookmark %s! r"rs>bookmark %s does not exist on the local or remote repository! rN)r`removerrrr isdivergentr-rqrrr rsort)rupushedr+ remotebmsrPaddsrcadddstadvsrcadvdstdivergedifferinvalidsamer`rOsciddcidr5r5r6r(sR   "   r(c Cs|j}|j}|jst|j||jdS|js[|j rVt d}t d}t d}t d||d}|j D]"}||}| rDt |||rUt ||d|q3t|dS) 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!)sorphansphase-divergentscontent-divergentrT)r_r`rrrnochangesfoundr-excludedrrrrrr r) isunstable instabilitiesr checkheads) rur_rmsomspdmscdmstrrr5r5r6_pushcheckoutgoings.   rEcfdd}|S)awdecorator 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:tvsJ|t<durt|St|Sr)b2partsgenmappingb2partsgenorderrinsertridxrr5r6r    zb2partsgenerator..decr5rrLrr5rKr6b2partsgenerator  rOc Cs|jsb|jjrdd|jddv}|jdu}|r|r%|jdt|jddSt }t |jD]"\}}|\}}} } |durPt |} |t | | @O}|| t |O}q.|rftt |} |jd| ddSdSdSdS)zdGenerate race condition checking parts Exists as an independent function to aid extensions srelateds checkheadsr5Ns check:headsdatascheck:updated-heads) rr_r capabilitiesrnrnewpartiterrrr iteritemsr) rubundlerallowunrelated emptyremoteaffectedbranchr^rnewheads unsyncedheadsdiscardedheadsrmrRr5r5r6_pushb2ctxcheckheadss(   r_cCst|jjp |jp |jp |jS)z&return True if we are pushing anything)boolr_rrrrrur5r5r6_pushing4srbscheck-bookmarksc Csxt|r|jr dSt|j}d|v}|jr|sdSg}|jD] \}}}|||fqt|j |}|j d|ddS)zinsert bookmark move checkingNrscheck:bookmarksrQ) rbrr bundle2capsrmrrr binaryencoder`rT) rurWb2capshasbookmarkcheckrRbookoldnew checkdatar5r5r6_pushb2checkbookmarks>s  rks check-phasescCst|r|jr dSt|j}d|ddv}|jdurZ|r\ddtjD}|tj  |jj |tj  |jj tt|r^|D]}||qCt|}|jd|ddSdSdSdS) zinsert phase move checkingNheadsrhr5cSi|]}|gqSr5r5rVpr5r5r6 Wz&_pushb2checkphases..s check:phasesrQ)rbrrrcrmrnrwr allphasespublicr publicheadsdraftr anyr itervaluesr/rdrT)rurWre hasphaseheadschecksphaserjr5r5r6_pushb2checkphasesNs  r{csdjvrdSjdtsdSjt|tj}d}| d}|rCfdd|D}|s?t t dt |}tj}tjjj|d||d }|jd|d |red |tjrqd d tjjjvr~dd fdd}|S)zwhandle changegroup push through bundle2 addchangegroup result is stored in the ``pushop.cgresult`` attribute. changesetsNr@r>cs g|] }|tjvr|qSr5)r supportedoutgoingversionsr`rVvrar5r6rZus z_pushb2ctx..no common changegroup versionpush bundlecapsremote_sidedatarQr? treemanifest1 exp-sidedatacs8|jj}t|ddksJ|ddd_dS)z0extract addchangegroup returns from server replyr>rrreturnN)records getrepliesidrrr)r cgrepliescgpartrur5r6 handlereplysz_pushb2ctx..handlereply)raddrEr`prepushoutgoinghooksr_rrcrmrnr r)rmaxrr makestreamr_rTaddparamristreemanifestrREPO_FEATURE_SIDE_DATAfeatures)rurWrer4 cgversionsrcgstreamrr5rr6 _pushb2ctxasF            rcCsnd|jvrdSt|j}|jj}d|ddv}d|v}d|ddv}|r.|s.t||S|r5t ||SdS)z!handle phase push through bundle2rhNr{r|pushkeyrlr5) rrrcrmr`r-r~rn_pushb2phaseheads_pushb2phasespushkey)rurWrer- legacyphase haspushkeyrxr5r5r6 _pushb2phasess    rcCs\|jd|jr,ddtjD}|ddd|jDt|}|jd|dd Sd S) z6push phase information through a bundle2 - binary partrhcSrmr5r5rnr5r5r6rprqz%_pushb2phaseheads..rcsrrrrVhr5r5r6rrz$_pushb2phaseheads.. phase-headsrQN)rrrrrrrrdrT)rurWupdates phasedatar5r5r6rs  rcsjdgfdd}tj}jD]=}|d}|d|d|d|||d|dtj |d |dtj  |j |f|j |j <qfd d }|S) z7push phase information through a bundle2 - pushkey partrhcs6t|j}D]\}}||krttd|qdS)Nsupdating %s to public failed)intpartidr r)r)ruexctargetidrr) part2noder5r6 handlefailures  z+_pushb2phasespushkey..handlefailurer namespacekeyold%dnewcs|D]9\}}|j|}|d}t|dksJd}|s#td|}nt|dds1td|}|dur;j|qdS)Nrrs'server ignored update of %s to public! rrupdating %s to public failed! )rrrrrrr-rq)rrrpartrepresultsryrrur5r6rs    z)_pushb2phasespushkey..handlereply)rrrencoderrTrrrrursrrr)rurWrenc newremoteheadrQrr5rr6rs     r obsmarkerscCs^d|jvrdSt|j}t|durdS|jd|jr-t |j}t ||dSdS)Nr) rrobsmarkersversionrSr commonversionrrr sortedmarkersbuildobsmarkerspart)rurWremoteversionsmarkersr5r5r6_pushb2obsmarkerss    rcCs^d|jvrdSt|j}|jjdd}d|v}|s$d|vr$t||Sd|vr-t||SdS)z$handle bookmark push through bundle2rNr{r|r) rrrcrmr`r-r~_pushb2bookmarkspart_pushb2bookmarkspushkey)rurWrelegacy legacybooksr5r5r6_pushb2bookmarkss     rcCs|sdS|sdSdS)z"small utility for bookmark pushingrrrr5)rhrir5r5r6 _bmactions rcCs2|r|j|tjkrttd|dSdS)z6abort if a given bookmark points to a secret changesets:cannot push bookmark %s as it points to a secret changesetN)r`rzrsecretr r)r)rurrOr5r5r6_abortonsecretctxs  rcsjdjs dSgg}jD]\}}}t|||||f|t||fqtj|}|j d|dfdd}|S)NrrQcs.j}D]\}}|t|d|qdSr8)r-status bookmsgmap)rr-rgaction allactionsrur5r6rs z)_pushb2bookmarkspart..handlereply) rrrrrrrrdr`rT)rurWrRrgrhrirjrr5rr6rs  rc sjdgtj}fdd}jD]N\}}}t|||d}|d|d|d|||d|t||d|t|d }|sOd }n|sSd } |j ||f|j |j <qfd d } | S)Nrcs@t|j}D]\}}}||krtt|d|qJ)Nr)rrr r)rrstrip)rurrrrgr) part2bookr5r6r#s z._pushb2bookmarkspushkey..handlefailurerrrrrrrrcsj}D]M\}}}|j|}|d}t|dksJ|s)jtd|qt|dd}|r?|t|d|q|t|d|j durRd_ qdS)Nrrs"server ignored bookmark %s update rr) r-rrrrrqrrrrr)rr-rrgrrrretrrur5r6r:s  z,_pushb2bookmarkspushkey..handlereply) rrrrrrrTrrrrr) rurWrrrgrhrirQrrr5rr6rs(    rpushvars)rLc Cs|j}|r.rrrrrrr)rrlrmr-rrrn_localphasemoveranalyzeremotephasesr`rurrrrrrrrsrrqr) rurrwanar outdatedrrrr5rr6rsX             rcs`jrtjj|dSfdd|D}tj}|r.jtd|dSdS)z0move to in the local source repocs"g|] }j|kr|qSr5)r`rzrUrzrur5r6rZ"z#_localphasemove..s8cannot lock source repo, skipping local %s phase update N) rradvanceboundaryr`r phasenamesr-rr)rurrz actualmovesphasestrr5r r6rs rc Csd|jvrdS|j}|j}|jd|jrT|jdg}t|j}t |}t |ddD]}||}| | d|d|q/dd |DrVtd }|j|dSdSdS) z5utility function to push obsolete markers to a remoterNs'try to push obsolete markers to remote TreverserrcSsg|]}|s|qSr5r5)rVrr5r5r6rZ7rz!_pushobsolete..s&failed to push some obsolete markers! )rr`rmrrr-rrrr_pushkeyescaperrrrrq) rur`rmrsltsr remotedatarrRryr5r5r6r's$      rc Cs|jdks d|jvr dS|jd|j}|j}|jD]V\}}}d}|s'd}n|s+d}|}|dd|t|t|d }Wdn1sKwY|r^| t |d|q| t |d ||j durqd |_ qdS) z"Update bookmark position on remoterrNrrrrrr)rrrr-rmrrrrrrrrqr) rur-rmrOrhrirrrr5r5r6r<s<    rc@s^eZdZdZ         dddZejddZejd d Zejd d Z d dZ dS) pulloperationzA object that represent a single pull operation It purpose is to carry pull related state and very common operation. A new should be created at the beginning of each pull and discarded afterward. NFr5c s|_||_| |_||_fdd|D|_||_||_d|_d|_d|_ d|_ ||_ d|_ t |_d|_||_| |_| |_dS)Ncsg|]}j|qSr5rrr!r5r6rZr#z*pulloperation.__init__..F)r`rm remote_pathr^explicitbookmarksrstreamclonerequestedrrarheadsfetchremotebookmarksrrrclonebundleattempted includepats excludepatsdepth) rr`rmr^rrrrrrrpathr5r!r6rhs(  zpulloperation.__init__cCsF|jdur t|j}t|j}|jD] }||vr||q|S|jS)z0heads of the set of changeset target by the pullN)r^rrar rr)rrrrWr5r5r6 pulledsubsets     zpulloperation.pulledsubsetcCs t| Sr)rrr5r5r6 canusebundle2 zpulloperation.canusebundle2cCs t|jSr)rrcrmrr5r5r6remotebundle2capss zpulloperation.remotebundle2capscCs |jSr)rrrr5r5r6gettransactionr"zpulloperation.gettransaction) NFr5NNNNNN) rrrrrrrr r!r#r$r5r5r5r6r_s&  7    rc@s0eZdZdZddZddZddZdd Zd S) rzAn object to manage the life cycle of a transaction It creates the transaction on demand and calls the appropriate hooks when closing the transaction.cCs||_||_||_d|_dSr)r`sourcer_tr)rr`r%rr5r5r6rs ztransactionmanager.__init__cCsL|js#d|jt|jf}|j||_|j|jjd<|j|jjd<|jS)zdS||}|||j |_ t |j|j |_q)Ncd||}dd|DS)zReturns heads(h1 % h2)sheads(%ln %% %ln)cSh|]}|qSr5rrVrr5r5r6r"rz8_fullpullbundle2..headsofdiff..rh1h2resrr5r6 headsofdiffz%_fullpullbundle2..headsofdiffcr1)zReturns heads((h1 + h2) - null)sheads((%ln + %ln - null))cSr2r5rr3r5r5r6r"rz9_fullpullbundle2..headsofunion..r4r5r9r5r6 headsofunionr;z&_fullpullbundle2..headsofunionTc3s|]}|VqdSrrXrU)unficlr5r6rz#_fullpullbundle2..) rr\r^rr _pullbundle2rNARROW_REQUIREMENTallrrar)r`pullopr:r< old_headsclstart new_headsr5)rr=r6_fullpullbundle2s$     rFcsF|j}tj||dddt|fdd}|d|dS)zadds a finalize callback to transaction which can be used to show stats to user and confirm the pull before committing transactionpullT)txnname as_validatorcs(}td}|j|rtddS)Ns+accept incoming changes (yn)?$$ &Yes $$ &Nos user aborted)rr-rsr r))trr`cmreporefr5r6prompts   z$add_confirm_callback..prompts900-pull-promptN)rrrregistersummarycallbackweakrefrefr addvalidator)r`rBrJrNr5rLr6add_confirm_callback s  rSc  Cs,|duri}|s | r|pt}| pt} n|j\}} t|t| t||f||||||| | dt|} | j} | r[t| j | j j }|r[t dd t|}t||jD]}|jD] \}}||rpn qett dt|q^t|d|| _t}t|s|}|g|S| j@| s|j !ddr|j "st#|| t$| t%&| t'| | j(rt)|| t*| t+| t,| t-| Wdn1swYWdn1swYWdn 1swY|j !dd rt./||| S) aFetch 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)rr^rrrrrrrrsDsidedata category requested by local side without localsupport: '%s'rGrfrdr)0r narrowpatsrvalidatepatternsrrrrmrrr`rrr(rr r)_wanted_sidedatarrrnProgrammingErrorrrrrrrrrrr r-rplainrS_maybeapplyclonebundlermaybeperformlegacystreamclone_pulldiscoveryr!rF_pullchangeset _pullphase_pullbookmarks _pullobsoleterr)r`rmrr^rrrrrrrconfirmrB peerlocalrryrrrrr5r5r6pull s*                   rbcr)a|decorator for function performing discovery before pull The function is added to the step -> function mapping and appended to the list of steps. Beware that decorated function will be added in order (this may matter). You can only use this decorator for a new step, if you want to wrap a step from an extension, change the pulldiscovery dictionary directly.crr)pulldiscoverymappingpulldiscoveryorderrrrr5r6rrzpulldiscovery..decr5rr5rr6 pulldiscoveryrrecCrr)rdrc)rBrrr5r5r6r[rr[s b1:bookmarkscCs>|jdurdS|jrd|jvrdSt|jd}t||_dS)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/r)rr!r#rlrmrr&)rBbooksr5r5r6_pullbookmarkbundle1s  rgr>cCstj|j|j|j|jd}|\}}}|jjjj }|r?|r?t |}|D]}||r3||vr3| |q$t | t |r?g}||_ ||_||_dS)z~discovery phase for the pull Current handle changeset discovery only, will change handle all discovery at some point.)r^rN)r rr`rmr^rrr\rhas_noderrissubsetrarr)rBtmprarrrhscommonrWr5r5r6_pulldiscoverychangegroups"    rlc Cs`dt|jddi}|jj}tj|ddd}|j|d<|jp |j|d<|j t j }|r4|j r4|j |d <|r>|j r>|j |d <|rUd |d <d|d <|jd|jdn9|jd|j|d <d|ddv}d|jddv}|s|rd|d<|jdd|jvrd|jvrdg|d<d }d|ddv}d|jv} |jdur|jdd|jvr|jdur|s| rd|d<d}d|jvrd|jvr|jd|dgd|j dr|jdurt|j|jjgkr|j|d<|r|jjtdn+|js |jjtdd|_n|jdur&t|j|jjgkr&|jjtdt|jtjrGt !|j} t"| durGd|d<|jdt#||t $|j} | rY| |d<|j%l} t&|} d| d<| 'd | (}zt j)|j|j*dd!}d"|j+d<t j,|j||d#Wn9t j-y}z|jj.td$|t.j/td%|j0d&d}~wt.j1y}z t./td'|d}~wwWdn 1swY|jrt 2||_|j3dD]\}}|dkrt4||q|r i}|j3dD] }|d(||d)<q||_n|j3dD]\}}|dkr t56||_q|jdur.t7|dSdS)*zNpull data using bundle2 For now, the only supported data are changegroup.s bundlecapsrrT)rrcommonrls includepatss excludepatsFcgr r>rhr{r|r5r/rNsrequest-bookmarks clonebundless cbattemptedsstreaming all changes no changes found requesting all changes rsremote_sidedatarGr' getbundle)r%srecordsrsremote: abort: %s spull failed on remoterArsnodesbookmark)8 caps20to10r`r-rcanperformstreamclonerar^rrmrr NARROWCAPrrrrrr~r#rnr setdefaultrr r]rrrrrrrrrr_pullbundle2extrapreparerrdictrrbundleoperationr$modesrrr rrBrcombinechangegroupresultsr_pullapplyphasesrr&r^)rBkwargsr- streaming servernarrowrhasbinaryphasebookmarksrequestedlegacybookmark hasbinarybookrrrargsbundlerrr0rrfrecordr5r5r6r?s                       "              r?cCsdS)z>hook function so that extensions can extend the getbundle callNr5)rBrr5r5r6rysrycCsd|jvrdS|jd|js|jjtdd|_dS|}|j dur;t |j |jj gkr;|jjtdn|j durJ|j drJ|j|_ |j dr_|j jd|j |j p[|jd }nW|j dur|j }|d|jdd }Wdn1swYn0|j dsttd |j }|d|j|j dd }Wdn1swYt|j||d|j }t||_dS) z0pull changeset from unbundle into the local repor>NrqrrrschangegroupsubsetrsrGrar^)snodesr'sWpartial pull cannot be done because other repository doesn't support changegroupsubset.)sbasesrlr')rrrr`r-rrrr$r^r rar]rmrr getbundlerrrr r)r applybundlerr})rBrJrrbundleopr5r5r6r\sb        r\cCs(d|jvrdSt|jd}t||dS)Nrh)rrlrmr~)rBrwr5r5r6r]s  r]csd|jvrdS|jdt|dd}|r(|s(t|j|j|\}}|j}n|j}g}|jj j j j j tjtjfdd|D}|r\|}t|j||fdd|D}|ry|}t|j||dSdS)z/apply phase movement from observed remote staterhNriFcs"g|] }|kr|qSr5r5rVpn)rzrsrrr5r6rZr z$_pullapplyphases..cs"g|] }|kr|qSr5r5r)rurzrrr5r6rZr )rrr`rnrrr`r r _phasecacherzr\rget_revrsrur$r )rBrwr r_drdheadsrJr5)rurzrsrrr6r~s2     r~c Csdd|jvrdS|jd|j}|j}d}|jdur|jj}tj|j|||j |j |j |ddS)z?process the remote bookmark information to update the local onerN)r+mode) rrr`rrbookmarks_moderupdatefromremoter-rmrr$r)rBr`rrr5r5r6r^s"    r^cCsd|jvrdS|jdd}t|jtjr]|jjdt|j d}d|vr]| }g}t |ddD]}| drMt ||}t|\}}||7}q4|rX|jj|||j|S) aVutility 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 purposerNs!fetching remote obsolete markers rsdump0Trsdump)rrrrr`rr-rrlrmr$rr&r b85decode _readmarkersrinvalidatevolatilesets)rBrJ remoteobsrrrRr4newmarksr5r5r6r_s(     r_c Cs|j}||jdp|}|t|d|td}|t|d|td}|s7tt dt|fdd|D}d d|D}t |d g}t |d g}t ||||\}}}|rptt d |t |fi} | |d | d<d | d<|| d <|r|| d <| S)zApply narrow fetch access control. This massages the named arguments for getbundle wire protocol commands so requested data is filtered through access control rules. s REMOTE_USERs .includessdefault.includess .excludessdefault.excludess%%s configuration for user %s is emptycS g|] }|dkr dnd|qS*spath:.spath:r5rnr5r5r6rZ6z"applynarrowacl..cSrrr5rnr5r5r6rZ9rrrs4The following includes are not accessible for %s: %sTnarrow narrow_acl)r- shortuserenvironrnusernamer~_NARROWACL_SECTIONr r)rrrrestrictpatternsrpprintupdate) r`rr-r user_includes user_excludes req_includes req_excludesinvalid_includesnew_argsr5r5r6applynarrowaclsV     rc sjj}jfdd|DthB}fdd|D}|r'dd|D} tt} ttfdd} fdd fd d tj||d } t | } t}fd d| D}t||B}| D]} |dd |D}|dur| |}|D]}t |d| ||d| |<qd}|dup| ||k}|r|j}|r| |dj}t|||}|st|dkr| |dj}t|||}nt||}|r| |D]}| ||q|D]}||q||qg|s tg}||vr+| |D]}| ||q|D] }| ||qqg|D] }| || |O<q-qg|D]}| |D]}| ||qDq>||fS)aCompute 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. ch|]}|qSr5r5rUclrevr5r6r"qrz#_computeellipsis..crr5r5rUrr5r6r"rrcSsi|]}|dqS)rr5rr5r5r6rpurqz$_computeellipsis..csR||t|dkr'|\}}||||}t|dksdSdS)z=Add a root to an ellipsis head, splitting heads with 3 roots.r"N)rrr)head curchangechildroots) ellipsisroots splithead splitrootsr5r6addrootzs   z!_computeellipsis..addrootcs<||||||||dSr)difference_updaterrdiscard)rrr)rr5r6rsz$_computeellipsis..splitrootscst|\}}}||f||f||ffD]6\}}d||||}|D]&}||kr3|||ffS|vs?t|dkrI|||ffSq#qttd||||f)Ns%sort(merge() & %d::%d & %d::%d, -rev)r"s;Failed to split up ellipsis node! head: %d, roots: %d %d %d)rrorrr r)r)rr1r2r3nr1nr2midj)rr`r5r6rs&  z#_computeellipsis..splitheadrcsg|]}|qSr5r)rVm)rbr5r6rZsz$_computeellipsis..cSsg|]}|tkr|qSr5)r)rVprevr5r5r6rZr[NrFr)r\ manifestlogrr collections defaultdictrr findmissingrevsreversedchangelogrevision parentrevsminrnrreadr`diffrrrvwalkrr)r`rar^knownmatchrmfl commonrevs headsrevsrevdepth ellipsisheadsrrvisitrelevant_nodes visitnodesrequiredrpscurdepthroneededshallow_enoughcurmfp1mfp2mfrrr5)rbrrr`rrr6_computeellipsisUst             rcCs2dh}ttj||d}|dt||S)zFreturn a set with appropriate options to use bundle20 during getbundlesHG20rmbundle2=)rrrrrJquote)r`rcapsrr5r5r6rusrucrF)adecorator 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.crGr)getbundle2partsmappinggetbundle2partsorderrrJrrKr5r6rrMz%getbundle2partsgenerator..decr5rNr5rKr6getbundle2partsgeneratorrPrcCs|dur tdd|DSdS)Ncss|]}|dVqdS)sHG2N)r&)rVcapr5r5r6r r>z#bundle2requested..F)rvrr5r5r6bundle2requested src Ks4t|}i}t|}|sC|r|ddsttd|r,ttddt|t |||} d|d<|t j || d|||d fSd |d<i} |D]} | d ret | td d } | t| qKt|j| } ||d <||d<tD]}t|}|| ||f|| |dt|qw| j|d<|| fS)aReturn 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). roTs-request for bundle10 must include changegroups#unsupported getbundle arguments: %srrs bundleversionr@rr"rNrlrn)rrersprefercompressed)r byteskwargsrrn ValueErrorrr(rkeysrcr rr&rJrKrrrr decodecapsrr-rrrprefercompressedr)r`r%r^rarrrinfo usebundle2r_rebcapsblobrWnamerr5r5r6getbundlechunks sf     rrCcOstj||fi|Sr)raddpartbundlestream2)rWr`rrr5r5r6_getbundlestream2R src s|ddr|s dSd} |d} | r)fdd| D} | s%ttdt| } t||} | js4dS|d d rZttt |d g} ttt |d g} t j j | | d }nd}t j| | ||||d}|jd|d}| rw|d| |jddt| jd dtr|ddtjjvr|ddt}|d||d d r|dd r| s| r|d}dd| d| f|_dSdSdSdS)z.add a changegroup part to the requested bundlerTNr@r>csg|] }|tvr|qSr5)r r}r~r!r5r6rZj s z-_getbundlechangegrouppart..rrFrr)includeexclude)rmatcherrrQr?s nbchangesrrrrrsexp-wanted-sidedatarsNarrow:responsespecs%s%s )rnr r)rrrcrrfilterr`rrrootr rrTrrrrrrrrrformat_remote_wanted_sidedatar(rR)rWr`r%rrer^rarrr4rr_rrrrrQsidedatanarrowspecpartr5r!r6_getbundlechangegrouppartW sh                 rcKsZ|ddsdS|rd|vrttdt|}t||}|r+|jd|ddSdS)z+add a bookmark part to the requested bundlerFNrs#no common bookmarks exchange methodrQ)rnr r)rrlistbinbookmarksrdrT)rWr`r%rrerrfrRr5r5r6_getbundlebookmarkpart s    rr/c KsJ|dd}|D]}|d}|d|||} t| |_qdS)z@add parts containing listkeys namespaces to the requested bundlerlr5r/rN)rnrTrrlrr encodekeysrR) rWr`r%rrerrlr0rQrr5r5r6_getbundlelistkeysparts s   rc Ks\|ddr,|dur|}dd|d|D}|j|}t|}t||dSdS)z8add an obsolescence markers part to the requested bundle obsmarkersFNcSrr5rrr5r5r6rZ rz+_getbundleobsmarkerpart..r) rnr^rrrrrrr) rWr`r%rrer^rsubsetrr5r5r6_getbundleobsmarkerpart s   rrhc s>|ddr|rd|dvrttd|dur|}tt|r-|t j <nX|j j }|j j}|j j} |D]} ||| | | q;t} | r[t| t jks[Jt jt} | rt j t} d}||| | }|D] }t j ||qxfdd t jD}t |}|jd |d dSdS) z,add phase heads part to the requested bundlerFrlrhs no common phases exchange methodNs"heads(only(%ln, %ln) and public())csi|] }|t|qSr5)r)rVrz headsbyphaser5r6rp sz(_getbundlephasespart..rrQ)rnr r)rr^rrrr rrsrrzr\rrrr rrrurorrrdrT)rWr`r%rrer^rrzrrr seenphases draftheadsrtr extraheadsr phasemappingrr5r r6_getbundlephasespart s:      r hgtagsfnodesc Ks:|r |ddr d|vsdSt|||}t|||dS)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. rTrN)rnrcraddparttagsfnodescache rWr`r%rrer^rarr_r5r5r6_getbundletagsfnodes s rscache:rev-branch-cachec KsR|ddr|rd|vs|dds|jtrdSt|||}t|||dS)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 rTsrev-branch-cacherFN)rnr- has_sectionrrcraddpartrevbranchcacherr5r5r6_getbundlerevbranchcache s    rcCsX|}tdt|}|dgks&||ks(|d|gks*td|dSdSdS)zVcheck if the heads of a repo have been modified Used by peer for unbundling. rrshasheds.repository changed while %s - please try againN)r^rsha1r(rdigestr PushRaced)r` their_headscontextr^ heads_hashr5r5r6 check_heads@ s  rc sVdgdd}jdd}dsdrd}zt|d t|tjsjd t g} + |}t ||} t | Wdn1sUwYWdn1sdwYndzdfd d } jdd s| tj| |dd} z!tj|| d} W| j|rdurjjdddfdd}n| j|rˆdurˆjjdddfdd}wddurψdWn#ty} zd| _|rdur| _fdd}d} ~ wwWtddd|dur|jStddd|dur*|jww)aApply 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.rNNNNrdsbundle2-output-captures remote:http:s remote:https:Tsuploading changesrcsjds1tsd<d<d<djd<djd<ddjd<dS)Nr"rrr'rrr})rrrr rr)r5) lockandtrr`r%rr5r6r$u s   z unbundle..gettransactionsbundle2lazylockingr) captureoutputr%rt)r subproccsjd|dddSNsoutputF)rRr)rT)output)rr5r6 recordout szunbundle..recordoutr"cstjd|dd}|dSr")r bundlepartr)r#rQ)partsr5r6r$ sr)r-rr&rrDrrFr(rr(r rrr}r{rr pushbufferr, BaseExceptionduringunbundle2 salvageoutput_bundle2salvagedoutputlockmodr. popbuffer) r`rr^r%rr$r rHrJrr$rr5)rr&rr`r%rr6rS s~             rcCsf|j}|j}|jddsdSt|rdS|jrdS|ds!dS|}|di }Wdn1s8wYd|_ t ||}|sR|j tddSt j|||jd}|so|jtd|jtddSt |j|}|d d }|jtd |t|j||r|jtd dS|jdd r|jtddStjtdtdd)z0Apply a clone bundle from a remote, if possible.rrpNTsDno clone bundles available on remote; falling back to regular clone )rsOno compatible clone bundles available on server; falling back to regular clone s5(you may want to report this to the server operator) rsURLsapplying clone bundle from %s sfinished applying clone bundle sclonebundlefallbacksfalling back to normal clone serror applying bundles}if this error persists, consider contacting the server operator or disable clone bundles via "--config ui.clonebundles=false"rA)r`rmr-rrrr^rrrrrr parseclonebundlesmanifestnoterfilterclonebundleentriesrrqsortclonebundleentriesrtrypullbundlefromurlr r))rBr`rmrr8entriesrr5r5r6rY s`    rYc CsF||d}z0t||}t||d}t|tjr$||n t |||d|WWdWddSt j yZ}z| tdt|WYd}~n$d}~wt jyy}z| tdt|jWYd}~nd}~ww WdWddS1swYWddS1swYdS) z%Attempt to apply a bundle from a URL.s bundleurlr rpNTsHTTP error fetching bundle: %s serror fetching bundle: %s F)r rurlmodopenr7rDrr,applyrrurlerr httperrorrqrrrurlerrorreason)r-r`rrJr.rrr5r5r6r2 s4      Pr2rr) NNFr5NNNNNN)NNNN)NNNNN)NNr) __future__rrrPi18nrrrrrrrr r r r r r,rrrrrrrrrrrr4rrutilsrrr interfacesrr7rJrr7rTrcrzrobjectrrrrrrrrrrrr,r(rErIrHrOr_rbrkr{rrrrrrrrrrrrrrrsrrrr transactionalrrlrFrSrbrdrcrer[rgrlr?ryr\r]r~r^r_rrrurrrrrrrrrrrrrrrrYr2r5r5r5r6sH  X  D& q  >  6'    6  %    0 ;0B#_ *    ;$ 8    K  K      0  %Y R