File: //usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyc
ó
ÛXc @@ s§ d Z d d l m Z d d l Z d d l Z d d l m Z d d l m Z m Z d d l
m Z m Z d d „ Z
d „ Z d
„ Z d „ Z d d
e d „ Z d S( 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 ( t absolute_importNi ( t _( t nullidt nullrev( t dagutilt errorc C@ s8 | r | j | ƒ } n | j ƒ } i } t j | ƒ } t ƒ } d } xé | r3| j ƒ } | | k ro qK n | j | d ƒ }
|
| k rš | d 9} n |
| k rÒ | j | ƒ | rÒ t | ƒ | k rÒ d Sn | j | ƒ xN | j | ƒ D]= } | s| | k rï | j | |
d ƒ | j
| ƒ qï qï WqK Wd S( s' update an existing sample to match the expected size
The sample is updated with nodes exponentially distant from each head of the
<nodes> 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 <nodes> set are
reached.
:dag: a dag object from dagutil
:nodes: set of nodes we want to discover (if None, assume the whole dag)
:sample: a sample to update
:quicksamplesize: optional target size of the samplei i N( t headsetofconnectedst headst collectionst dequet sett popleftt
setdefaultt addt lent parentst append( t dagt nodest samplet quicksamplesizeR t distt visitt seent factort currt dt p( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt
_updatesample: s.
c C@ sH | j | ƒ } | t | ƒ k r. t | | ƒ St | d | d | ƒ| 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
:nodes: set of nodes to discover
:size: the maximum size of the sampleR N( R R t _limitsampleR t None( R R t sizeR ( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt _takequicksampleb s
c C@ sœ | j | ƒ } t | | | ƒ t | j ƒ | | ƒ | sA t ‚ t | | ƒ } t | ƒ | k r˜ | t | ƒ } | j t j t | | ƒ | ƒ ƒ n | S( N(
R R t inverset AssertionErrorR R t updatet randomR t list( R R R R t more( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt _takefullsampleq s &c C@ s1 t | ƒ | k r- t t j | | ƒ ƒ } n | S( s; return a random subset of sample of at most desiredlen item( R R
R$ R ( R t
desiredlen( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyR ~ s id iÈ c @ s— d } | j } t j | ƒ } | j d ƒ | d 7} | j ƒ } t | | ƒ }
t |
ƒ }
| j ƒ } | j ƒ | j | j |
ƒ ƒ | j
ƒ | j ƒ \ } ‰ | j ƒ t
k rå | t
g k rÕ t
g t | f St
g t g f S| j t d ƒ ƒ | j | d t ƒ}
t |
ƒ t | ƒ k r?| j d ƒ | t | f S|
r’t | ƒ | k r’t ˆ ƒ r’| j t d ƒ ƒ | j | ƒ } | t | f S| j |
ƒ } t ‡ f d † t |
ƒ Dƒ ƒ } | j | ƒ t | j | ƒ ƒ } t ƒ } t } xØ| rÎ|
r[g t |
ƒ D] \ } } ˆ | s| ^ q} | j | j | | ƒ ƒ | j | ƒ n | sePn | sw| j ƒ r¯| r“| j t d ƒ ƒ n
| j d
ƒ t } | } n | j d ƒ t } | } t | ƒ | k rét | ƒ }
n! | | | | ƒ }
t |
| ƒ }
| d 7} | j! t d ƒ | d
t d ƒ ƒ| j d | t | ƒ t |
ƒ f ƒ t |
ƒ }
| j | j |
ƒ ƒ ‰ t } |
r÷t ‡ f d † t |
ƒ Dƒ ƒ } | j | ƒ | j"