-=[ Mr. Bumblebee ]=-
_Indonesia_
ó
Ì\,Tc @ s‡ d Z d d l m Z d d l m Z d d l Z d d l Z d d l 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 nullid( t _Ni c
C sG | r | j | ƒ } n | j ƒ } i } t j | ƒ } t ƒ } d } xø | rB| j ƒ }
|
| k ro qK n | j |
d ƒ } | | k rš | d 9} n | | k rá |
| k rá | j |
ƒ | rÞ t | ƒ | k rÞ d Sqá n | j |
ƒ xN | j |
ƒ D]= } | s| | k rþ | j | | d ƒ | j
| ƒ qþ qþ WqK Wd S( Ni i ( t headsetofconnectedst headst utilt dequet sett popleftt
setdefaultt addt lent parentst append(
t dagt nodest samplet alwayst quicksamplesizeR t distt visitt seent factort currt dt p( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt
_updatesample0 s0
c C sm t | ƒ | k r% t | ƒ d d f S| j | ƒ } | t | ƒ } | d k r] | d | f S| t ƒ | f S( Ni ( R
R t NoneR ( R
R t sizeR t
desiredlen( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt _setupsampleL s
c C sj t | | | ƒ \ } } } | d k r+ | S| r: d } n | } t | | | | d | ƒ| j | ƒ | S( NR ( R R R t update( R
R R t initialR R R t fromset( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt _takequicksampleW s
c C sí t | | | ƒ \ } } } | d k r+ | St | | | | ƒ t | j ƒ | | | ƒ | sc t ‚ t | ƒ | k r t t j | | ƒ ƒ } nL t | ƒ | k rÜ | t | ƒ } | j t j t
| | | ƒ | ƒ ƒ n | j | ƒ | S( N( R R R t inverset AssertionErrorR
R t randomR R t list( R
R R R R R t more( ( s: /usr/lib/python2.7/dist-packages/mercurial/setdiscovery.pyt _takefullsamplec s *
id iÈ c s… d } | j } t j | ƒ } | j d ƒ | d 7} | j ƒ } | }
| j ƒ rz | j ƒ } | j | j |
ƒ ƒ ‰ np | j d ƒ rØ | j ƒ } | j ƒ }
| j | j |
ƒ ƒ } | j
ƒ |
j } | j ‰ n | j ƒ } g }
| j ƒ t
k r+| t
g k rt
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 j ˆ ƒ rÉ| j t d ƒ ƒ | j | ƒ } | t | f S| j ƒ } t ƒ } t ƒ } | j | j | ƒ ƒ | j | ƒ t } xº| rÌ|
r¿t ‡ f d † t |
ƒ Dƒ ƒ } | j | j | | ƒ ƒ g t |
ƒ D] \ } } ˆ | sg| ^ qg} | j | j | | ƒ ƒ | j | ƒ | j | ƒ n | sÉPn | rú| j t d
ƒ ƒ t | | d | ƒ}
nS | r%| j d ƒ t | | d | ƒ}
n( | j d
ƒ t | | d | d t ƒ}
| d 7} | j t d ƒ | d t d ƒ ƒ| j d | t | ƒ t |
ƒ f ƒ t! |
ƒ }
| j | j |
ƒ ƒ ‰ t } qW| j"