Ë *ï CK—Ñãó¤—dZddlZddlZddlmZddlmZddlmZm Z m Z dd„Z dd„Z Gd „d «Z e Ze jd d e ¬ «Z dd„Zy)a; Algorithm works in the following way. You have two repository: local and remote. They both contains a DAG of changelists. The goal of the discovery protocol is to find one set of node *common*, the set of nodes shared by local and remote. One of the issue with the original protocol was latency, it could potentially require lots of roundtrips to discover that the local repo was a subset of remote (which is a very common case, you usually have few changes compared to upstream, while upstream probably had lots of development). The new protocol only requires one interface for the remote repo: `known()`, which given a set of changelists tells you if they are present in the DAG. The algorithm then works as follow: - We will be using three sets, `common`, `missing`, `unknown`. Originally all nodes are in `unknown`. - Take a sample from `unknown`, call `remote.known(sample)` - For each node that remote knows, move it and all its ancestors to `common` - For each node that remote doesn't know, move it and all its descendants to `missing` - Iterate until `unknown` is empty There are a couple optimizations, first is instead of starting with a random sample of missing, start by sending all heads, in the case where the local repo is a subset, you computed the answer in one round trip. Then you can do something similar to the bisecting strategy used when finding faulty changesets. Instead of random samples, you can try picking nodes that will maximize the number of nodes that will be classified with it (since all ancestors or descendants will be marked as well). éNé)Ú_)Únullrev)ÚerrorÚpolicyÚutilcó°—i}tj|«}t«}d}|r±|j«} | |vrŒ|j | d«} | |kDr|dz}| |k(r"|j | «|rt |«|k\ry|j | «|| «D]9} | tk7sŒ |r| |vsŒ|j | | dz«|j| «Œ;|rŒ°yy)a[update an existing sample to match the expected size The sample is updated with revs exponentially distant from each head of the set. (H~1, H~2, H~4, H~8, etc). If a target size is specified, the sampling will stop once this size is reached. Otherwise sampling will happen until roots of the set are reached. :revs: set of revs we want to discover (if None, assume the whole dag) :heads: set of DAG head revs :sample: a sample to update :parentfn: a callable to resolve parents for a revision :quicksamplesize: optional target size of the sampleréN) Ú collectionsÚdequeÚsetÚpopleftÚ setdefaultÚaddÚlenrÚappend) ÚrevsÚheadsÚsampleÚparentfnÚquicksamplesizeÚdistÚvisitÚseenÚfactorÚcurrÚdÚps ú:usr/lib/python3.12/site-packages/mercurial/setdiscovery.pyÚ _updatesampler 8sË€ð €DÜ × Ñ ˜eÓ $€EÜ ‹5€DØ €FÙ Ø�}‰}‹ˆØ �4‰<Ø Ø �O‰O˜D !Ó $ˆØ ˆvŠ:Ø �a‰KˆFØ �Š;Ø �J‰J�tÔ Ù¤C¨£K°?Ò$BØØ �‰�Œá˜$–ˆAØ”G‹|¡T¨Q°$ªYØ—‘  1 q¡5Ô)Ø— ‘ ˜Q•ð ô ócó¶—t|«|kr|St|«}|rttj||««S|j «t|d|«S)z²return a random subset of sample of at most desiredlen item. If randomize is False, though, a deterministic subset is returned. This is meant for integration tests. N)rÚlistr ÚrandomrÚsort)rÚ desiredlenÚ randomizes rÚ _limitsampler(^sR€ô  ˆ6ƒ{�jÒ Øˆ Ü �&‹\€FÙÜ”6—=‘= ¨Ó4Ó5Ð5Ø ‡K�K„MÜ ˆv�k�zÐ"Ó #Ð#r!cój—eZdZdZdd„Zd„Zd„Zd„Zd„Zd„Z e d„«Z d „Z d „Z d „Zd „Zd „Zd„Zy)Úpartialdiscoveryaban object representing ongoing discovery Feed with data from the remote repository, this object keep track of the current set of changeset in various states: - common: revs also known remotely - undecided: revs we don't have information on yet - missing: revs missing remotely (all tracked revisions are known locally) có´—||_||_|jj«|_d|_t «|_d|_||_ ||_ y©N) Ú_repoÚ _targetheadsÚ changelogÚincrementalmissingrevsÚ_commonÚ _undecidedr ÚmissingÚ _childrenmapÚ _respectsizer')ÚselfÚrepoÚ targetheadsÚ respectsizer's rÚ__init__zpartialdiscovery.__init__ysL€ØˆŒ Ø'ˆÔØ—~‘~×<Ñ<Ó>ˆŒ ؈ŒÜ“uˆŒ Ø ˆÔØ'ˆÔØ"ˆ�r!cóž—|jj|«|j�&|jj|j«yy)zregister nodes known as commonN)r1Úaddbasesr2Úremoveancestorsfrom)r6Úcommonss rÚ addcommonszpartialdiscovery.addcommonsƒs9€à � ‰ ×јgÔ&Ø �?‰?Ð &Ø �L‰L× ,Ñ ,¨T¯_©_Õ =ð 'r!cóÄ—|jjd||j«}|r7|jj |«|jj |«yy)zregister some nodes as missings%ld::%ldN)r-rÚ undecidedr3ÚupdateÚdifference_update)r6ÚmissingsÚ newmissings rÚ addmissingszpartialdiscovery.addmissings‰sH€à—Z‘Z—_‘_ [°(¸D¿N¹NÓKˆ Ù Ø �L‰L× Ñ   Ô +Ø �N‰N× ,Ñ ,¨ZÕ 8ð r!cóØ—t«}t«}|D]*\}}|r|j|«Œ|j|«Œ,|r|j|«|r|j|«yy)z*consume an iterable of (rev, known) tuplesN)r rr?rF)r6rÚcommonr3ÚrevÚknowns rÚaddinfozpartialdiscovery.addinfo�s_€ä“ˆÜ“%ˆÛ ‰JˆC�ÙØ— ‘ ˜3•à— ‘ ˜CÕ ð !ñ Ø �O‰O˜FÔ #Ù Ø × Ñ ˜WÕ %ð r!có6—|jj«S)z6return True is we have any clue about the remote state)r1Úhasbases©r6s rÚhasinfozpartialdiscovery.hasinfožs€à�|‰|×$Ñ$Ó&Ð&r!có<—|jduxr |j S)z1True if all the necessary data have been gatheredN)r2rNs rÚ iscompletezpartialdiscovery.iscomplete¢s€à�‰ dÐ*ÒB°4·?±?Ð/BÐBr!có°—|j� |jSt|jj|j««|_|jSr,)r2r r1Úmissingancestorsr.rNs rrAzpartialdiscovery.undecided¦sA€à �?‰?Ð &Ø—?‘?Ð "ܘdŸl™l×;Ñ;¸D×.getparents»sø€Ù˜!“9˜Q˜q�>Ð !r!)r-r/ÚindexÚ __getitem__)r6r`r_s @rÚ_parentsgetterzpartialdiscovery._parentsgetter¸s+ø€Ø—‘×%Ñ%×+Ñ+×7Ñ7ˆô "ðÐr!cóJ—|j�|jjSix|_}|j«}|j}t |«D]C}g||<||«D]1}|t k(rŒ |j |«}|€Œ!|j|«Œ3ŒE|jSr,)r4rbrcrAÚsortedrÚgetr)r6ÚchildrenÚ parentrevsrrIÚprevÚcs rÚ_childrengetterz partialdiscovery._childrengetterÀs¥€à × Ñ Ð (ð ×$Ñ$×0Ñ0Ð 0ð (*Ð)ˆÔ˜Hà×(Ñ(Ó*ˆ Ø�~‰~ˆä˜$–<ˆCðˆH�S‰MÙ" 3ž�Øœ7’?ØØ—L‘L Ó&�Ø‘=Ø—H‘H˜S•Mñ (ð  ð×#Ñ#Ð#r!có"—|j}t|«|kr t|«St|jj d|««}t|«|k\rt |||j¬«Std|||j«|¬«|S)atakes a quick sample of size It is meant for initial sampling and focuses on querying heads and close ancestors of heads. :headrevs: set of head revisions in local DAG to consider :size: the maximum size of the sampleó heads(%ld)©r'N)r) rArr#r r-rr(r'r rc)r6ÚheadrevsÚsizerrs rÚtakequicksamplez partialdiscovery.takequicksampleÞs~€ð�~‰~ˆÜ ˆt‹9˜Ò ܘ“:Ð Ü�T—Z‘Z—_‘_ ]°DÓ9Ó:ˆä ˆv‹;˜$Ò Ü ¨¸¿¹ÔGÐ GäØ �(˜F D×$7Ñ$7Ó$9È4õ ðˆ r!c ó—|j}t|«|kr t|«S|j}t |j d|««}|j «}|j«}t||||«t |j d|««}|j«} t|||| «|sJ‚|js(t|tt|«t|«««}t|||j¬«}t|«|krs|t|«z } t||z «} |jr'|jt!j"| | ««|S| j%«|j| d| «|S)Nrms roots(%ld)rn)rArr#r-r rrcÚcopyr rkr5ÚmaxÚminr(r'rBr$rr%) r6rorprr7rrhÚ revsheadsÚ revsrootsÚ childrenrevsÚmoreÚtakefroms rÚtakefullsamplezpartialdiscovery.takefullsampleósG€Ø�~‰~ˆÜ ˆt‹9˜Ò ܘ“:Ð Ø�z‰zˆÜ�T—Y‘Y˜}¨dÓ3Ó4ˆØ×(Ñ(Ó*ˆ ð—K‘K“Mˆ Ü�d˜I v¨zÔ:ô˜Ÿ ™  -°Ó6Ó7ˆ Ø×+Ñ+Ó-ˆ Ü�d˜I v¨|Ô<Ùˆ ˆvà× Ò Ü�tœS¤ Y£´°Y³Ó@ÓAˆDä˜f d°d·n±nÔEˆÜ ˆv‹;˜Ò Øœ#˜f›+Ñ%ˆDܘD 6™MÓ*ˆHØ�~Š~Ø— ‘ œfŸm™m¨H°dÓ;Ô<ðˆ ð— ‘ ”Ø— ‘ ˜h u¨˜oÔ.؈ r!N©T)Ú__name__Ú __module__Ú __qualname__Ú__doc__r:r?rFrKrOrQÚpropertyrArUrXrcrkrqr{r]r!rr*r*msX„ñ ó#ò>ò 9ò &ò'òCðñóðò  ò )ò ò$ò<ó*r!r*Ú discoveryÚPartialDiscovery)ÚmemberÚdefaultc ó¤ —t|jdd««}|�d|d<tj«}d}|j} | j } | j } |�|D� cgc] } | | «‘Œ } } n'| j«D�cgc]}|tk7sŒ |‘Œ} }|jdd«}|jdd«}|jdd«}|�r|jrt| |«}t|«}n| }|jd «|d z }|j«5}|j!d i«}|�|dxxt#|«z cc<|j!d d |D�cgc] }| |«‘Œ c}i«}ddd«j%«j%«}}|�d |d<| j'«tk(rk|| j(gk7r| j(gd|fS| j(gdgfS|j«5}|j!d i«}ddd«j%«}|j+t-d««g}|D]*}|| j(k(rŒ |j/| |««Œ,|rƒt#|«t#|«k(r|jd«|d|fSt#«t#| «k(r?t5«r4|j7t-d««| D�cgc] }| |«‘Œ }}|d|fS|j8j}|dd«}|xr |j }|dd«}|xs |j }|jdd«} | j:j<rt>}!nt@}!|!|| || ¬«}"|r,|"jC|«|"jEtG««| }#|jIt-d«t-d«¬«}$|"jK«�sq|#s|"jM«rM|#r|j7t-d««n|jd«|"jN}%|}&|r.tQ||z«}n|jd«|"jR}%|}&|%| |&«}|d z }|$jU|«|"jW«}'|jd||'dt#|«fz«t|«}|j«5}|�|dxxt#|«z cc<|j!d d |D�cgc] }| |«‘Œ c}i«j%«}ddd«d}#|"jEtG|««|"jK«s�Œq|"jY«}(tj«|z })|$j[«|jd ||)fz«d!}*t]|(«t]|«z }+|j_d"|*t#|(«t#|+«||)«|�||d<|(sZ|| j(gk7rJ|rt1j`t-d#««‚|jct-d$««| j(hd|fS|| j(gk7},|(D�chc] }| |«’Œ }(}|(|,|fScc} wcc}wcc}w#1swY�ŒxYw#1swY�Œ„xYw#t0j2$rY�ŒowxYwcc}wcc}w#1swY�Œ¡xYwcc}w)%aReturn a tuple (common, anyincoming, remoteheads) used to identify missing nodes from or in remote. The audit argument is an optional dictionnary that a caller can pass. it will be updated with extra data about the discovery, this is useful for debug. sdevelsdiscovery.grow-sample.rateNrs total-queriessdiscovery.exchange-headssdiscovery.sample-size.initialsdiscovery.sample-sizesquery 1; heads rsheadssknownsnodesstotal-roundtripsTFssearching for changes sall remote heads known locally s$all local changesets known remotely sdiscovery.grow-samplesdiscovery.grow-sample.dynamicsdiscovery.randomizerns searchingsqueries)Úunitssampling from both directions staking initial sample staking quick initial sample s2query %i; still undecided: %i, sample size is: %i rAs%d total queries in %.4fs sDfound %d common and %d unknown server heads, %d roundtrips in %.4fs s discoverysrepository is unrelateds!warning: repository is unrelated )2ÚfloatÚconfigrÚtimerr/ÚnoderIrorÚ configboolÚ configintÚlimitedargumentsr(r#ÚdebugÚcommandexecutorÚ callcommandrÚresultÚtiprevÚnullidÚstatusrrrÚ LookupErrorÚallÚnoteÚuiraÚrust_ext_compatr*Úpure_partialdiscoveryr?rKÚzipÚ makeprogressrQrOr{ÚintrqrBrUrXÚcompleter ÚlogÚAbortÚwarn)-r™ÚlocalÚremoteÚabortwhenunrelatedÚ ancestorsofÚauditÚ samplegrowthÚstartÚ roundtripsÚclÚclnodeÚclrevÚnÚownheadsrIÚinitial_head_exchangeÚinitialsamplesizeÚfullsamplesizerÚeÚfheadsr^ÚfknownÚ srvheadhashesÚyesnoÚ knownsrvheadsr‹Ú ownheadhashesrŒÚ grow_sampleÚdynamic_sampleÚhard_limit_sampler'ÚpdÚdiscoÚfullÚprogressÚ samplefuncÚ targetsizerUr’ÚelapsedÚmsgr3Ú anyincomings- rÚfindcommonheadsrÆs€€ô ˜Ÿ™ 8Ð-JÓKÓL€Là ÐØ"#ˆÐÑä �J‰J‹L€Eà€JØ �‰€BØ �W‰W€FØ �F‰F€EàÐÙ&1Ó2¡k ‘E˜!•H kˆÑ2à#%§;¡;¤=ÓC¡=˜C°C¼7³N’C =ˆÐCàŸM™M¨(Ð4OÓPÐØŸ ™  XÐ/OÓPÐØ—\‘\ (Ð,DÓE€NòhØ × "Ò "Ü! (Ð,=Ó>ˆFä˜&“\‰FàˆFà �‰Ð$Ô%Ø�a‰ˆ Ø × #Ñ #Ô %¨Ø—]‘] 8¨RÓ0ˆFØÐ ØÐ&Ó'¬3¨v«;Ñ6Ó'Ø—]‘]Øà±&Ó9±&¨Q™v a�y°&Ñ9ðóˆF÷ &ð &Ÿ}™}›°· ± ³�uˆ à Ð Ø)*ˆEÐ%Ñ &à �9‰9‹;œ'Ò !Ø §¡  Ò+ØŸ ™ �{ D¨-Ð7Ð7Ø—I‘I�;  rÐ)Ð )ð× #Ñ #Ô %¨Ø—]‘] 8¨RÓ0ˆF÷&àŸ ™ ›ˆ ð‡I�IŒaÐ*Ó+Ô,à€MÛˆØ �2—9‘9Ò Ø ð Ø × Ñ ¡ t£Õ -ð ñä ˆ}Ó ¤ ]Ó!3Ò 3Ø �H‰HÐ8Ô 9Ø  %¨Ð6Ð 6ä ˆv‹;œ#˜h›-Ò '¬C°¬JØ �G‰G”AÐ>Ó?Ô @Ù08Ó9±¨1™V A�Y°ˆMÐ9Ø  $¨ Ð5Ð 5ð —‘×$Ñ$€JÙ˜XÐ'?Ó@€KØÒ= f×&=Ñ&=Ð"=€Ká Ð*JÓK€NØ+ÒF¨v×/FÑ/FÐGÐà— ‘ ˜hÐ(>Ó?€IØ ‡x�x×ÒÜ ‰ä "ˆÙ ˆu�hÐ 1¸YÔ G€EÙð ×јÔ'Ø � ‰ ”c˜& %Ó(Ô)à$Ð $€DØ�‰œq ›´Q°z³]ˆÓC€HØ×ÑÕ á �5—=‘=”?ÙØ—‘œÐ<Ó=Õ>à—‘Ð3Ô4Ø×-Ñ-ˆJØ'ˆJÙÜ!$ ^°lÑ%BÓ!C‘ð �H‰HÐ5Ô 6Ø×.Ñ.ˆJØ*ˆJÙ˜H jÓ1ˆà�a‰ˆ Ø�‰˜ Ô#Ø— ‘ “ ˆØ �‰Ø Bؘ5 Ñ-¬s°6«{Ð;ñ <ô ô �f“ˆà × #Ñ #Ô %¨ØÐ ØÐ&Ó'¬3¨v«;Ñ6Ó'Ø—M‘MØà±&Ó9±&¨Q™v a�y°&Ñ9ðó÷ ‰f‹hð ÷&ðˆà � ‰ ”c˜& %Ó(Ô)ðS×ÑÖ ðV× Ñ Ó €FÜ�j‰j‹l˜UÑ"€GØ ×ÑÔØ‡H�HÐ +¨z¸7Ð.CÑ CÔDð %ðô�&‹kœC  Ó.Ñ.€G؇F�Fˆ<˜œc &›k¬3¨w«<¸ÀWÔMà ÐØ%/ˆÐ!Ñ"á �m¨¯ ©  {Ò2Ù Ü—+‘+œaÐ :Ó;Ó<Ð <à �G‰G”AÐ;Ó<Ô =à �Y‰YˆKØ Ø ð ð ð   B§I¡I ;Ñ.€KÙ!'Ó (¡˜A‰f�Q�i €FÐ (Ø �;  Ð -Ð-ùòm3ùâCùòR:÷&Ñ %ú÷,&Ñ %ûô × Ñ ò Ú ð üò:ùò|:÷ &Ñ %üòP)sxÁ#Y3ÂY8ÂY8Ä!rÊspðñ!óHÛ åÝ÷ñó# óL $÷dñdðN)Ðà$�6×$Ñ$ØÐ*Ð4DôÐðØØ ô s.r!