HEX
Server: Apache
System: Linux p102.lithium.hosting 4.18.0-553.141.1.el8_10.x86_64 #1 SMP Fri Jul 10 17:48:02 UTC 2026 x86_64
User: bvzmoamr (9955)
PHP: 8.1.34
Disabled: syslog
Upload Files
File: //usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pyc
�
1�3\c@@s�dZddlmZddlZddlZddlmZddlmZm	Z	ddl
mZmZdd�Z
d	�Zd
�Zd�Zdd
edd�ZdS(s;
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).
i(tabsolute_importNi(t_(tnullidtnullrev(terrortutilcC@si}tj|�}t�}d}x�|r|j�}	|	|krKq'n|j|	d�}
|
|krv|d9}n|
|kr�|j|	�|r�t|�|kr�dSn|j|	�xW||	�D]I}|tkr�|s�||kr�|j||
d�|j|�q�q�Wq'WdS(s[update an existing sample to match the expected size

    The sample is updated with revs exponentially distant from each head of the
    <revs> 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 <revs> 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 sampleiiN(	tcollectionstdequetsettpopleftt
setdefaulttaddtlenRtappend(trevstheadstsampletparentfntquicksamplesizetdisttvisittseentfactortcurrtdtp((s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pyt
_updatesample:s(		


cC@sZt|jd|��}t|�|kr7t||�Std|||jjd|�|S(s,takes a quick sample of size <size>

    It is meant for initial sampling and focuses on querying heads and close
    ancestors of heads.

    :dag: a dag object
    :headrevs: set of head revisions in local DAG to consider
    :revs: set of revs to discover
    :size: the maximum size of the samples
heads(%ld)RN(RRRt_limitsampleRtNonet	changelogt
parentrevs(trepotheadrevsRtsizeR((s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pyt_takequicksample_s

cC@sht|jd|��}t|jd|��}t||||jj�t|jd|��}i}|jj}xu|jjdt|��D]X}	|j|	g�x?||	�D]1}
|
tkr�q�n|j|
g�j|	�q�Wq�Wt||||j	�|s
t
�t||�}t|�|krd|t|�}|j
tjt||�|��n|S(Ns
heads(%ld)s
roots(%ld)tstart(RRRRRtminR
RR
t__getitem__tAssertionErrorRRtupdatetrandomRtlist(RR RR!Rt	revsheadst	revsrootstchildrenRtrevtprevtmore((s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pyt_takefullsamplers&
"!&cC@s1t|�|kr-ttj||��}n|S(s;return a random subset of sample of at most desiredlen item(RRR(R(Rt
desiredlen((s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pyR�sidi�c%@s$tj�}d}|j}	|	j�|	j}
|dk	r[g|D]}|
|�^q@}n+g|	j�D]}
|
tkrh|
^qh}|jd�|d7}t	||�}t
|�}|j��K}|jdi�}|jdig|D]}�|�^q�d6�}WdQX|j
�|j
�}�|	j�tkrk|tgkr[tgt|fStgtgfS|jtd��g}xQ|D]I}|tkr�q�ny|j|
|��Wq�tjk
r�q�q�Xq�Wt|�t|�kr
|jd	�|t|fSt|�t|�krmt��rm|jtd
��g|D]}�|�^qH}|t|fS|	j|�}t�fd�t|�D��}|j|�t|j|��}t�}t}|jtd�d
td��}x|r|r|gt|�D]\}}�|s|^q}|rS|j |j!d||��n|j |j!d|��|j"|�n|s�Pn|s�|j#�r�|r�|jtd��n
|jd�t$}|} n|jd�t%}|} t|�| kr
t
|�}n||||| �}|d7}|j |�|jd|t|�t|�f�t
|�}|j��?}|jdig|D]}�|�^q�d6�j
��WdQXt}|r�t�fd�t|�D��}|j|�|j&|�q�q�Wt|j!d|j'th��}!tj�|}"|j(�|jd||"f�d}#t|!�t|�}|j)d|#t|!�t|�||"�|!r�|tgkr�|r�tj*td���n|j+td��tht|fS|tgk}$�fd�|!D�}!|!|$|fS(slReturn a tuple (common, anyincoming, remoteheads) used to identify
    missing nodes from or in remote.
    isquery 1; heads
iRtknowntnodesNssearching for changes
sall remote heads known locally
sall local heads known remotely
c3@s%|]\}}�|r|VqdS(N((t.0titn(tyesno(s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pys	<genexpr>�st	searchingtunittqueriess#descendants(%ld) - descendants(%ld)sdescendants(%ld)ssampling from both directions
staking initial sample
staking quick initial sample
s2query %i; still undecided: %i, sample size is: %i
c3@s%|]\}}�|r|VqdS(N((R4R5R6(R7(s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pys	<genexpr>ss
heads(%ld)s%d total queries in %.4fs
sDfound %d common and %d unknown server heads, %d roundtrips in %.4fs
t	discoverysrepository is unrelateds!warning: repository is unrelated
c@sh|]}�|��qS(((R4tr(tclnode(s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pys	<setcomp>8s	(,RttimerRtnodeR-RR RtdebugRR)tcommandexecutortcallcommandtresultttipRtTruetFalsetstatusRR
RtLookupErrorRtalltnotetincrementalmissingrevsRt	enumeratetaddbasestmissingancestorstmakeprogressR'Rtdifference_updatethasbasesR0R"tremoveancestorsfromtbasestcompletetlogtAborttwarn(%tuitlocaltremotetinitialsamplesizetfullsamplesizetabortwhenunrelatedtancestorsofR#t
roundtripstcltclrevR6townheadsR-RtetfheadsR<tfknownt
srvheadhashestsrvheadsR?t
ownheadhashestcommontcommoninsamplet	undecidedtmissingtfulltprogressR5tmissinginsamplet
samplefunct
targetsizeRCtelapsedtmsgtanyincoming((R=R7s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pytfindcommonheads�s�			"+

,


$
"
	!	/
	


	2"
"
!(t__doc__t
__future__RRR(ti18nRR?RRtRRRR"R0RRERRu(((s</usr/lib64/python2.7/site-packages/mercurial/setdiscovery.pyt<module>)s%		(