^ciddlZddlZddlmZddlmZddlmZddlm Z m Z m Z m Z mZmZmZmZmZmZmZmZmZddlmZmZejZejZedZed Zd eefzZd Z d Z!d Z"dZ#dZ$ej%Z&dJdZ'e'ddddZ(e'ddddZ)e'dddZ*e'ddddZ+e'dd dd!Z,gd"Z-d#Z.e'd$dd%Z/e'd&d'dd(Z e'd)d*dd+Z0e'd,d-dd.Z1d/Z2e'd0d1dd2Z3e'd3dd4Z4e'd5dd6Z5e'd7d8dd9Z6e'd:d;dd<Z7e'd=d>dd?Z8e'd@dAddBZ9e'dCdDddEZe'dFddGZ:e'dHd3ddIZ;dS)KN)_)hex)getattr) bundle2 bundlecaches changegroup discoveryencodingerrorexchangepushkeypycompat requirements streamcloneutilwireprototypes)procutil stringutils/incompatible Mercurial client; bundle2 requireds9see https://www.mercurial-scm.org/wiki/IncompatibleClients%s (%s) c|D]6}|dr|dddcS7ddgS)aReturns a list of compression methods supported by the client. Returns a list of the compression methods supported by the client according to the protocol capabilities. If no such capability has been announced, fallback to the default of zlib and uncompressed. scomp=N,szlibsnone) getprotocaps startswithsplit)protocaps =/usr/lib/python3/dist-packages/mercurial/wireprotov1server.pyclientcompressionsupportr/sc!!##'' >>( # # 'qrr7==&& & & & ' W cb|jdd}||S)zObtain the repo used for processing wire protocol commands. The intent of this function is to serve as a monkeypatch point for extensions that need commands to operate on different repo views under specialized circumstances. serversview)uiconfigfiltered)reporcommand viewconfigs rgetdispatchrepor)?s+ 733J == $ $$r ct|||}t|\}}||}|||g|RSN)r)commandsgetargs)r&rr'funcspecargss rdispatchr1JsL 4 0 0D'"JD$ ==  D 4e #d # # ##r ci}|D]}||vr||||<||=|r7tjd|d|fz|S)Ns,warning: %s ignored unexpected arguments %s r)rstderrwritejoin)cmdkeysothersoptsks roptionsr;Ssy D  ;;QiDGq    <DIIf%%& '    Kr c|j}tj|jv}|r|dd|z}||S|dd|z}||S|r|dd}||S|ddS)zWhether a bundle1 operation is allowed from the server. Priority is: 1. server.bundle1gd. (if generaldelta active) 2. server.bundle1. 3. server.bundle1gd (if generaldelta active) 4. server.bundle1 r"s bundle1gd.%sNs bundle1.%ss bundle1gdsbundle1)r#requirementsmodGENERALDELTA_REQUIREMENTr configbool)r&actionr#gdvs rbundle1allowedrCas B  1T5F FB  MM)_v%= > > =H i!788A}  MM)\ 2 2 =H ==J / //r pushcdtjDdvrtjdzdt t stjdfd}|S)aDecorator to declare a wire protocol command. ``name`` is the name of the wire protocol command being provided. ``args`` defines the named arguments accepted by the command. It is a space-delimited list of argument names. ``*`` denotes a special value that says to accept all named arguments. ``permission`` defines the permission type needed to run this command. Can be ``push`` or ``pull``. These roughly map to read-write and read-only, respectively. Default is to assume command requires ``push`` permissions because otherwise commands not declaring their permissions could modify a repository that is supposed to be read-only. c0h|]\}}|ddk|S)sversionr).0r:rBs r z#wireprotocommand..s1a1Z=A;M;M;M;M;Mr rDpullsCinvalid wire protocol permission; got %s; expected "push" or "pull"Nr s:arguments for version 1 commands must be declared as bytesctvrtjdztj|t<|S)Ns+%s command already registered for version 1)r0 transports permission)r,r ProgrammingErrorr commandentry)r.r0namerNrMs rregisterz"wireprotocommand..registersX 8  (>E (4 t z    r )r TRANSPORTSitemsr rO isinstancebytes)rQr0rNrRrMs``` @rwireprotocommandrWs$/5577J+++$ 13= >    | dE " " $ I            Or sbatchscmds *rK)rNctj}g}|dD]}|dd\}}i} |dD]3} | r/| d\} } || | || <4t|\} }t|j}|dvsJ|||rq|}i|D]A}|dkr.i}| D]}||vr | |||<|d<6| ||<B| ||gfd|DR}n | ||}t|tjr|cSt|tj tfsJt|tj r|j }| tj |tj d|S) N; rr=rJ*c g|] }| SrGrG)rHr:datas r zbatch..s(?(?(?Qa(?(?(?r )runescapebatchargrr,rN checkpermr7rUooberror bytesresponserVr^appendescapebatchargr5)r&rcmdsr8 unescapeargrespairopr0valsanrBr.r/permr7r:starkeyresultr^s @rbatchrrs, 1K C 4  %:%:::dA&&DD!! 6 6A 6wwt}}1'2{1~~[[^^$b\ d|&)))))   '::<#?"GHHHHH fn: ; ; ! >0889999  ' # 7 77r sbetweenspairscd|dD}g}||D],}|tj|dz-tjd|S)Nc8g|]}tj|dS)-)r decodelist)rHps rr_zbetween..s% K K KA^ &q$ / / K K Kr rZ r )rbetweenrdr encodelistrcr5)r&rpairsrbs rryrys K KT9J9J K K KE A \\% 77 *1--56666  ' 4 44r branchmapcd|}g}|D]_\}}tt j|}t j|}|d||fz`t j d |S)Ns%s %srx) branchmaprTurlreqquoter fromlocalrrzrdrcr5)r&rrheadsbranchnodes branchname branchnodess rrrs  I E"**;; \\("4V"<"<== $/66  X[ 99::::  ' 5(9(9 : ::r sbranchesnodesctj|}g}||D],}|tj|dz-tjd|S)Nrxr )rrvbranchesrdrzrcr5)r&rrr|r}s rrrsr  %e , ,E A ]]5 ! !77 *1--56666  ' 4 44r s clonebundlesr cntj|jtjS)aZServer command for returning info for available bundles to seed clones. Clients will parse this response and determine what bundle to fetch. Extensions may wrap this command to filter or dynamically emit data depending on the request. e.g. you could advertise URLs for the closest data center given the client's IP address. )rrcvfstryreadrCB_MANIFEST_FILEr&rs r clonebundlesrs/  ' 677  r )lookupr~pushkeyknown getbundles unbundlehashcZtt}td|r|dt j|r|jddr|dt j |}|tj hz s|dn8|dd t|z|jdd rXtjtj|d }|d t"|z|d d tjz|jdd rY|t(j|jddr|t(j|||S)a)return a list of capabilities for a repo This function exists to allow extensions to easily wrap capabilities computation - returns a lists: easy to alter - change done here will be propagated to both `capabilities` and `hello` command without any other action needed. changegroupsubsetr"spreferuncompressedsstream-preferredsstreams streamreqs=%srs experimentalsbundle2-advertise)rolesbundle2=s unbundle=%ssnarrowsnarrowservebrokenellipses)list wireprotocapsr,commandavailablerdrallowservergenerationr#r?streamed_requirementsr=REVLOGV1_REQUIREMENTr5sortedr encodecaps getrepocapsrrbundlepriorityr NARROWCAP ELLIPSESCAPaddcapabilities)r&rcapsrequiredformatscapsblobs r _capabilitiesrs   D  !5u==* ()))(.. O 7  i)> ? ? - KK+ , , ,%;DAA/"F!GG O KK " " " " KK(499VO5L5L+M+MM N N N w/+?@@:%g&9$Y&O&O&OPP K&,,x"8"88999KK7+A!B!BBCCC w/9554 N,--- 7  o/K L L 4 KK2 3 3 3  t , ,,r s capabilitiesct||}tjdt |S)NrZ)rrrcr5rr&rrs r capabilitiesrDs4 u % %D  ' &,,(?(? @ @@r s changegroupsrootsctj|}tj|||}t j||ddtfdd}tj|S)N missingroots ancestorsof01servec.dSNireadcgsrzchangegroup..Qrwwu~~r r gen) rrvr outgoingrchangegroupmodmakechangegroupiter streamres)r&rrootsrrrrs @rr r Js~  %e , ,E! 5djjllH  'hx H HB %%%%s + +C  # , , ,,r rs bases headsctj|}tj|}tj|||}t j||ddt fdd}tj|S)Nrrrc.dSrrrsrrz#changegroupsubset..[rr r r)rrvr rrrrr)r&rbasesrrrrs @rchangegroupsubsetrUs}  %e , ,E  %e , ,E!$UNNNH  'hx H HB %%%%s + +C  # , , ,,r debugwireargss one two *c tdddg|}tj|j||fit j|S)Nrsthreesfour)r;rrc debugwireargsr strkwargs)r&ronetwor8r9s rrr_sU #h%8& A AD  '3@@x'9$'?'?@@  r crd}|jd}|sdStj||}tj||}|sdS|jfd|Ddfd|Ddt|} |D]r} | d} tj j | } | r | | vr| | vrGd | vrt || d } n#t$rYjwxYw| |rtfd | Drt!fd | Drd | vrA || d }n#t$rYwxYwtfd |Ds| d}|jd|z |j|cS#t($r!|jd|zYpwxYwdS)aReturn a file object for the first matching pullbundle. Pullbundles are specified in .hg/pullbundles.manifest similar to clonebundles. For each entry, the bundle specification is checked for compatibility: - Client features vs the BUNDLESPEC. - Revisions shared with the clients vs base revisions of the bundle. A bundle can be applied only if all its base revisions are known by the client. - At least one leaf of the bundle's DAG is missing on the client. - Every leaf of the bundle's DAG is part of node set the client wants. E.g. do not send a bundle of all changes if the client wants only one specific branch of many. c@d|dDS)Nc6h|]}tj|SrG)binascii unhexlify)rHhs rrIz;find_pullbundle..decodehexstring..ys#===!"1%%===r rY)r)ss rdecodehexstringz(find_pullbundle..decodehexstringxs ==qwwt}}====r spullbundles.manifestNc:g|]}|SrGrevrHrcls rr_z#find_pullbundle..s#;;;cbffSkk;;;r T) inclusivec:g|]}|SrGrrs rr_z#find_pullbundle..s#===srvvc{{===r s COMPRESSIONheadsc3FK|]}|vVdSr+rrHrr common_ancs r z"find_pullbundle..s2EE266#;;*,EEEEEEr c3tK|]2}|vo|vV3dSr+r)rHrrr heads_ancs rrz"find_pullbundle..sZs 9,NJ1Nr sbasesc3FK|]}|vVdSr+rrs rrz"find_pullbundle..s2IISrvvc{{j0IIIIIIr sURLssending pullbundle "%s" spullbundle "%s" not accessible )rrrparseclonebundlesmanifestfilterclonebundleentries unfiltered changelog ancestorsrgetr compengines _bundlenames TypeErrorissubsetallanyr#debugopenIOError)r&rr9clheadsrcommonrmanifestrh compformatsentrycompaltcomp bundle_heads bundle_basespathrrrs @@@rfind_pullbundlerhs >>>x 788H t  0x @ @C  /c : :C t    $B ;;;;U;;;t LLI====f===NNJ*511K$$yy(("/33D99  D ++{0J0J  u   .uX??     $$V,, EEEEE EEEEE '  u   .uX??     IIIIILIIIII V}  2T9::: 8==&& & & &    GMM=D E E E H  4s6D!! D.-D.F F&%F&-H  'H43H4rr\ctdtj|}|D]\}}tj|}|dkrtj|||<5|dkr&t |d||<a|dkr&t|d||<|dkr|dkrd||<t|||<|d krtd |zt|d sktj |d sD|jd krtjt"St%jt(t* t|j}t|dt}t|dt} | |j|jddrTd|vr>t;|||||| } | r(tjt?j | dS|jddrP|dd} | r8| s6||kr0t%jtCdtCdtj"|dfitGj$|\} } | dd}n#t$j$r}tj |d s-|jd kr!tj|j%dzcYd}~StMj'|j}d|j%fg}g}|j(|)d|j(f|*tMj+d|||,} d}Yd}~nd}~wwxYwtj| | S) Nrrscsvrsscsvsboolean0Fsplains unknown getbundle option type %srKs bundlecapshttp-v1hintrscommonr"s pullbundles partial-pullT)rprefer_uncompressedsdisablefullbundlescgs%server has pull-based clones disableds/remove --pull if specified or upgrade Mercurialrsprefercompressedrxmessagehint error:abort)-r;rGETBUNDLE_ARGUMENTSr7rTrvrrsetboolKeyErrorrCr bundle2requestedrrQrbbundle2requiredr Abortbundle2requiredmainbundle2requiredhintrrdiscardnullidr#r?rrrr filechunkiterrgetbundlechunksrrmessagerbundle20rrdaddpart bundlepart getchunks)r&rr8r9r:rBkeytyperrrbundler infochunksprefercompressedexcbundlermanargsadvargss r getbundler"se n8==??  D JJ1 4Q7 h  $/22DGG   1774==))DGG   !''$--((DGG  " "DyyQq''Q  >HII I! $ ( (M(-)@)@AA MzZ''%.???+18KLLL L+!dn**,,--DHHXsuu--..TXXi//00t{### G  y- 8 8 5#5#5#7#777%T5$OOF %/*622 7  i)= > > ((5$//K 6 g.>.>k>??MNN  / (  &066  f 88$7>> ;!!!(-)@)@AA zZ''%.s{U/BCCCCCCCC "47++ ,- 8  NNGSX. / / /*>7GLLMMM""$$ !  # ,<(<   s. D MB)MP4A P/P4"BP//P4rc||}tjtj|dzS)Nrx)rrrcrz)r&rrs rrrs0 A  '(A!(D(Du(L M MMr shellocZt||j}tjd|zS)afCalled as part of SSH handshake to obtain server info. Returns a list of lines describing interesting things about the server, in an RFC822-like format. Currently, the only one defined is ``capabilities``, which consists of a line of space separated tokens describing server abilities: capabilities: scapabilities: %s )rr^rrcrs rhellor%s- e $ $ )D  '(=(D E EEr slistkeys namespacect|tj|}t jtj|Sr+) rlistkeysr tolocalrTrrc pushkeymod encodekeys)r&r namespaceds rr(r(sNt}}X-i8899??AABBA  ' (=a(@(@ A AAr rkeyc tj|}||}t|}d}n-#t$r }t j|}d}Yd}~nd}~wwxYwtjd||fzS)Nrrs%d %s ) r r)lookupr Exceptionr forcebytestrrrc)r&rrpr:rmr|successinsts rr0r0s  S ! ! KKNN FF   #D ) )  ' gq\(A B BBs:= A'A""A'rsnodes *cdd|tj|D}tj|S)Nr c3"K|] }|rdpdV dS)1rNrG)rHr}s rrzknown..(s<  ddr )r5knownrrvrc)r&rrr8rBs rr8r8&s[ $(JJ~/H/O/O$P$P  A  ' * **r s protocapsscapsc|jtjkr't|d|_tjdS)NrZsOK)rQrSSHV1rr _protocapsrcrs r protocapsr<.s? z^)))tzz$//00  ' . ..r rsnamespace key old newcjt|dkrStj||kr; |dt j|}n$#t $rYnwxYwt j|}|5}|t j|t j|t j||pd}dddn #1swxYwY|r| nd}tj dt||fzS)Nzutf-8Fr s%d %s) lenr escapestrdecoder r)UnicodeDecodeErrormayberedirectstdiorgetvaluerrcint)r&rr,rpoldnewoutputr|s rrr5sp 3xx2~~*.s33s::  JJw   "3''CC!    D s##  ! ! # #  v LL ++ %% %%                      #) 1V__   cF  ' SVVV4D(D E EEs$)A A$#A$AC,,C03C0s stream_outcNtjtj|S)zIf the server supports streaming clone, it advertises the "stream" capability with a value representing the version and flags of the repo it is serving. Client checks to see if it understands the format. )rstreamreslegacyrgeneratev1wireprotors rstreamrLRs  )+*I$*O*O P PPr sunbundlec  tj|}|5} tj||dd} ||jddrfd}tj nd\fd}tj d \}|j d ztj|tjd D]}|d tj|jd}t'|t(jrjt-|d sZ|jdkr/tjt2|cdddSt5jt8t:tj|||d|} tj | dr=tj!| "|cdddStj#| |r|$nd|cdddS#|wxYw#t4j%t4jt4j&f$r} tO| dds #t4j$r} tPj)| *tPj)+tj#d |r|$ndcYd} ~ cYd} ~ cdddSd} ~ wt4j&$rQtj,tj-| |r|$ndcYcYd} ~ cdddSwxYwt]j/|j} tO| ddD]} | 0|  #t4j1$r} tO| dd} | d| 2ddvr| 3d}|4d| j5| j6|4d| j6d| j7|4d| j7d| j8|4d | j8d| j9|4d!| j9d| j:|4d"| j:dYd} ~ nd} ~ wwxYwn9#t4j%$rv} | 3d#}| j;|4d$| j;| j<r.|4d%d&=| j<Yd} ~ nd} ~ wt4j$rb} d'| j>fg}g}| j?|@d(| j?f| 0t]jAd)||Yd} ~ nJd} ~ wt4j&$r5} | 3d*d'tjC| fgYd} ~ nd} ~ wwxYwtj!| "cYd} ~ cdddSd} ~ wwxYw#1swxYwYdS)+Nspreparing changescdSr+rGrGr rrzunbundle..bsdr r"sstreamunbundlecD]}dSr+rG)rwpayloads rcleanupzunbundle..cleanupgs!")!!A !!r )NNcdrrtjdSdSr+)closeosunlink)fptempnamesrrQzunbundle..cleanuprs@'HHJJJ#0Ih/////00r s hg-unbundle-)prefixs"redirecting incoming bundle to %s swb+rrDrrrsaddpartrr duringunbundle2F_bundle2salvagedoutputrG _replycapsrserrors error:pushkeys in-reply-tor&) mandatoryr.snewsoldsretserror:unsupportedcontentsparttypesparamsrrrserror:pushraced)DrrvrCr check_heads getpayloadr#r?r chunkbufferrmkstemprrTfdopensysstrr4seek readbundlerUr cg1unpackerrCrQrbr r r rrunbundleclient safehasattrrJrpushresrDBundleValueError PushRacedrrr3formatflushpusherrbytestrrrr PushkeyFailedrnewpartaddparampartidr,rprGrFretparttypeparamsr5rrrdrrr2)r&rr their_headsrHrQfdrwrr|rrout remotecapsparterrpartr r!rVrPrWs @@@rrgrg[s +E22K  ! ! # #CKvB K  {4H I I I"lG8 **,,7%%i1BCC!!!!! )'22BB$.LB000000 $,#3?#K#K#KLBGMM>I2xv'>'>??B$$$ GGAJJJ)$'2t<<3 (w77 zZ// .6GG" yCKCKCKCKCKCKCKCKX ++2E%#{Hellnn#Az22M*9akkmmLLL  yCKCKCKCKCKCKCKCKn&-F;v(((  yCKCKCKCKCKCKCKCKx & U_EE KE KE K3 1599 {    O))#**,,777O))+++)1?6??,,,CUCKCKCKCKCKCKCKCKZ)1 (---3<)))]CKCKCKCKCKCKCKCKZ &tw//Gs$">?@  "1g6G6G6I6IJJJ J J J J JGCKCKCKCKCKCKCKCK|E K}CKCKCKCKCKCKCKCKCKCKs,Z?JEJ J&BJ+ J*J, J JJ'Z<9Z7 K  OA9M,OZ7Z<Z?,AO;Z7<Z<=Z?OAZ7PU'DT<7U<UUZ7Y<A,WZ7Y<AX50Z75Y<+Y72Z77Y<<)Z7%Z<&Z?7Z<<Z??[[)NrD)rs    aJKKa@ #68K"LL    %%%$$$   000< &> % ' ',,,,`(I':::*8*8;:*8Z*h7;;;55<;5,7333;;43;+xG<<<55=<5/37;;;  <;  &-&-&-V/g666AA76A .(w???--@?-&7KKK--LK-"LWEEEFECCCL,999KK:9K\(w///NN0/N (w/// F F0/ F+|@@@BBA@B )V888 C C98 C(J7;;;++<;+,G<<<//=</ *67KKKFFLKF8-G444QQ54Q+xG<<<FKFK=<FKFKFKr