§
    cÌc� ã                   óŒ  — d dl Z ddlmZmZmZmZmZ dZ G d„ d¦  «        Z G d„ d¦  «        Z	 G d	„ d
¦  «        Z
 G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Zd„ Zd„ Z G d„ d¦  «        Zg d¢Z	 ddlmZ dS # e$ r!Z ej        e¦  «         ddlmZ Y dZ[dS dZ[ww xY w)é    Né   )ÚdebugÚerrorsÚosutilsÚrevisionÚtraceé   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚDictParentsProviderz%A parents provider for Graph objects.c                 ó   — || _         d S ©N©Úancestry)Úselfr   s     ú./usr/lib/python3/dist-packages/breezy/graph.pyÚ__init__zDictParentsProvider.__init__7   s   € Ø ˆŒˆˆó    c                 ó   — d| j         z  S )NzDictParentsProvider(%r)r   ©r   s    r   Ú__repr__zDictParentsProvider.__repr__:   s   € Ø(¨4¬=Ñ8Ð8r   c                 ó.   ‡— | j         Šˆfd„|D ¦   «         S )z)See StackedParentsProvider.get_parent_mapc                 ó*   •— i | ]}|‰v ¯|‰|         “ŒS © r   )Ú.0Úkr   s     €r   ú
<dictcomp>z6DictParentsProvider.get_parent_map.<locals>.<dictcomp>E   s$   ø€ Ð>Ð>Ð> 1°°X°°��8˜A”;°°°r   r   )r   Úkeysr   s     @r   Úget_parent_mapz"DictParentsProvider.get_parent_mapB   s$   ø€ à”=ˆØ>Ð>Ð>Ð>¨Ð>Ñ>Ô>Ð>r   N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   4   sG   € € € € € Ø/Ð/ð!ð !ð !ð9ð 9ð 9ð?ð ?ð ?ð ?ð ?r   r   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚStackedParentsProviderz’A parents provider which stacks (or unions) multiple providers.

    The providers are queries in the order of the provided parent_providers.
    c                 ó   — || _         d S r   )Ú_parent_providers)r   Úparent_providerss     r   r   zStackedParentsProvider.__init__N   s   € Ø!1ˆÔÐÐr   c                 óL   — d                      | j        j        | j        ¦  «        S ©Nz{}({!r}))ÚformatÚ	__class__r    r'   r   s    r   r   zStackedParentsProvider.__repr__Q   s    € Ø× Ò  ¤Ô!8¸$Ô:PÑQÔQÐQr   c                 ó¦  — i }t          |¦  «        }| j        D ]O}t          |dd¦  «        }|€Œ ||¦  «        }|                     |¦  «         |                     |¦  «         |s nŒP|s|S | j        D ]\}	 |                     |¦  «        }n# t          j        $ r Y Œ*w xY w|                     |¦  «         |                     |¦  «         |s nŒ]|S )aå  Get a mapping of keys => parents

        A dictionary is returned with an entry for each key present in this
        source. If this source doesn't have information about a key, it should
        not include an entry.

        [NULL_REVISION] is used as the parent of the first user-committed
        revision.  Its parent list is empty.

        :param keys: An iterable returning keys to check (eg revision_ids)
        :return: A dictionary mapping each key to its parents
        Úget_cached_parent_mapN)Úsetr'   ÚgetattrÚupdateÚdifference_updater   r   ÚUnsupportedOperation)r   r   ÚfoundÚ	remainingÚparents_providerÚ
get_cachedÚ	new_founds          r   r   z%StackedParentsProvider.get_parent_mapT   s+  € ð ˆÝ˜‘I”Iˆ	ð
 !%Ô 6ð 		ð 		ÐÝ Ð!1Ð3JØ!%ñ'ô 'ˆJàÐ!ØØ"˜
 9Ñ-Ô-ˆIØ�LŠL˜Ñ#Ô#Ð#Ø×'Ò'¨	Ñ2Ô2Ð2Øð Ø�ðàð 	ØˆLØ $Ô 6ð 	ð 	ÐðØ,×;Ò;¸IÑFÔF�	�	øÝÔ.ð ð ð Ø�ðøøøà�LŠL˜Ñ#Ô#Ð#Ø×'Ò'¨	Ñ2Ô2Ð2Øð Ø�ðàˆs   Á7BÂBÂBNr   r   r   r   r%   r%   H   sN   € € € € € ðð ð
2ð 2ð 2ðRð Rð Rð(ð (ð (ð (ð (r   r%   c                   óF   — e Zd ZdZdd„Zd„ Zdd„Zd„ Zd„ Zd	„ Z	d
„ Z
d„ ZdS )ÚCachingParentsProvidera–  A parents provider which will cache the revision => parents as a dict.

    This is useful for providers which have an expensive look up.

    Either a ParentsProvider or a get_parent_map-like callback may be
    supplied.  If it provides extra un-asked-for parents, they will be cached,
    but filtered out of get_parent_map.

    The cache is enabled by default, but may be disabled and re-enabled.
    Nc                 ó‚   — || _         |€| j         j        | _        n|| _        d| _        |                      d¦  «         dS )zýConstructor.

        :param parent_provider: The ParentProvider to use.  It or
            get_parent_map must be supplied.
        :param get_parent_map: The get_parent_map callback to use.  It or
            parent_provider must be supplied.
        NT)Ú_real_providerr   Ú_get_parent_mapÚ_cacheÚenable_cache)r   Úparent_providerr   s      r   r   zCachingParentsProvider.__init__‹   sL   € ð .ˆÔØÐ!Ø#'Ô#6Ô#EˆDÔ Ð à#1ˆDÔ ØˆŒØ×Ò˜$ÑÔÐÐÐr   c                 óL   — d                      | j        j        | j        ¦  «        S r*   )r+   r,   r    r<   r   s    r   r   zCachingParentsProvider.__repr__›   s    € Ø× Ò  ¤Ô!8¸$Ô:MÑNÔNÐNr   Tc                 ót   — | j         �t          d¦  «        ‚i | _         || _        t          ¦   «         | _        dS )zEnable cache.Nz#Cache enabled when already enabled.)r>   ÚAssertionErrorÚ_cache_missesr/   Úmissing_keys)r   Úcache_missess     r   r?   z#CachingParentsProvider.enable_cachež   s:   € àŒ;Ð"Ý Ð!FÑGÔGÐGØˆŒØ)ˆÔÝ™EœEˆÔÐÐr   c                 óH   — d| _         d| _        t          ¦   «         | _        dS )zDisable and clear the cache.N)r>   rD   r/   rE   r   s    r   Údisable_cachez$CachingParentsProvider.disable_cache¦   s#   € àˆŒØ!ˆÔÝ™EœEˆÔÐÐr   c                 ó<   — | j         €dS t          | j         ¦  «        S )z(Return any cached get_parent_map values.N)r>   Údictr   s    r   Úget_cached_mapz%CachingParentsProvider.get_cached_map¬   s   € àŒ;ÐØ�4Ý�D”KÑ Ô Ð r   c                 ó6   ‡— | j         Š‰€i S ˆfd„|D ¦   «         S )z¿Return items from the cache.

        This returns the same info as get_parent_map, but explicitly does not
        invoke the supplied ParentsProvider to search for uncached values.
        Nc                 ó*   •— i | ]}|‰v ¯|‰|         “ŒS r   r   ©r   ÚkeyÚcaches     €r   r   z@CachingParentsProvider.get_cached_parent_map.<locals>.<dictcomp>»   s$   ø€ Ð@Ð@Ð@ C°3¸%°<°<��U˜3”Z°<°<°<r   )r>   )r   r   rP   s     @r   r.   z,CachingParentsProvider.get_cached_parent_map²   s0   ø€ ð ”ˆØˆ=ØˆIØ@Ð@Ð@Ð@¨4Ð@Ñ@Ô@Ð@r   c                 ó~  ‡— | j         Š‰€|                      |¦  «        Šnyˆfd„|D ¦   «         }|                     | j        ¦  «         |rO|                      |¦  «        }‰                     |¦  «         | j        r|D ]}||vr|                      |¦  «         Œi }|D ]}‰                     |¦  «        }|�|||<   Œ|S )z*See StackedParentsProvider.get_parent_map.Nc                 ó   •— h | ]}|‰v¯|’Œ	S r   r   rN   s     €r   ú	<setcomp>z8CachingParentsProvider.get_parent_map.<locals>.<setcomp>Ã   s#   ø€ ÐHÐHÐH¨°sÀ%Ð7GÐ7G Ð7GÐ7GÐ7Gr   )r>   r=   r2   rE   r1   rD   Únote_missing_keyÚget)r   r   Úneeded_revisionsÚ
parent_maprO   ÚresultÚvaluerP   s          @r   r   z%CachingParentsProvider.get_parent_map½   sõ   ø€ à”ˆØˆ=Ø×(Ò(¨Ñ.Ô.ˆEˆEàHÐHÐHÐH¨tÐHÑHÔHÐà×.Ò.¨tÔ/@ÑAÔAÐAØð 7Ø!×1Ò1Ð2BÑCÔC�
Ø—’˜ZÑ(Ô(Ð(ØÔ%ð 7Ø/ð 7ð 7˜Ø jÐ0Ð0Ø ×1Ò1°#Ñ6Ô6Ð6øØˆØð 	$ð 	$ˆCØ—I’I˜c‘N”NˆEØÐ Ø#��s‘øØˆr   c                 óL   — | j         r| j                             |¦  «         dS dS )zNote that key is a missing key.N)rD   rE   Úadd)r   rO   s     r   rT   z'CachingParentsProvider.note_missing_keyÔ   s4   € àÔð 	'ØÔ×!Ò! #Ñ&Ô&Ð&Ð&Ð&ð	'ð 	'r   )NN)T)r    r!   r"   r#   r   r   r?   rH   rK   r.   r   rT   r   r   r   r:   r:      s¦   € € € € € ð	ð 	ð ð  ð  ð  ð Oð Oð Oð"ð "ð "ð "ð"ð "ð "ð!ð !ð !ð	Að 	Að 	Aðð ð ð.'ð 'ð 'ð 'ð 'r   r:   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )Ú CallableToParentsProviderAdapterz¼A parents provider that adapts any callable to the parents provider API.

    i.e. it accepts calls to self.get_parent_map and relays them to the
    callable it was constructed with.
    c                 ó   — || _         d S r   ©Úcallable)r   Ú
a_callables     r   r   z)CallableToParentsProviderAdapter.__init__á   s   € Ø"ˆŒˆˆr   c                 óL   — d                      | j        j        | j        ¦  «        S r*   )r+   r,   r    r`   r   s    r   r   z)CallableToParentsProviderAdapter.__repr__ä   s   € Ø× Ò  ¤Ô!8¸$¼-ÑHÔHÐHr   c                 ó,   — |                       |¦  «        S r   r_   )r   r   s     r   r   z/CallableToParentsProviderAdapter.get_parent_mapç   s   € Ø�}Š}˜TÑ"Ô"Ð"r   Nr   r   r   r   r]   r]   Ú   sN   € € € € € ðð ð#ð #ð #ðIð Ið Ið#ð #ð #ð #ð #r   r]   c                   óÌ   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	 d"d„Zd„ Zd#d„Zd„ Zd„ Zd„ Zd „ Z d!„ Z!dS )$ÚGraphz­Provide incremental access to revision graphs.

    This is the generic implementation; it is intended to be subclassed to
    specialize it for other repository types.
    c                 óˆ   — t          |dd¦  «        �|j        | _        t          |dd¦  «        �|j        | _        || _        dS )aŸ  Construct a Graph that uses several graphs as its input

        This should not normally be invoked directly, because there may be
        specialized implementations for particular repository types.  See
        Repository.get_graph().

        :param parents_provider: An object providing a get_parent_map call
            conforming to the behavior of
            StackedParentsProvider.get_parent_map.
        Úget_parentsNr   )r0   rg   r   Ú_parents_provider)r   r6   s     r   r   zGraph.__init__ò   sO   € õ Ð# ]°DÑ9Ô9ÐEØ/Ô;ˆDÔÝÐ#Ð%5°tÑ<Ô<ÐHØ"2Ô"AˆDÔØ!1ˆÔÐÐr   c                 ó   — d| j         z  S )Nz	Graph(%r))rh   r   s    r   r   zGraph.__repr__  s   € Ø˜TÔ3Ñ3Ð3r   c                 ó^   — |                       |¦  «        \  }}}|                      |¦  «        S )aÌ  Determine the lowest common ancestors of the provided revisions

        A lowest common ancestor is a common ancestor none of whose
        descendants are common ancestors.  In graphs, unlike trees, there may
        be multiple lowest common ancestors.

        This algorithm has two phases.  Phase 1 identifies border ancestors,
        and phase 2 filters border ancestors to determine lowest common
        ancestors.

        In phase 1, border ancestors are identified, using a breadth-first
        search starting at the bottom of the graph.  Searches are stopped
        whenever a node or one of its descendants is determined to be common

        In phase 2, the border ancestors are filtered to find the least
        common ancestors.  This is done by searching the ancestries of each
        border ancestor.

        Phase 2 is perfomed on the principle that a border ancestor that is
        not an ancestor of any other border ancestor is a least common
        ancestor.

        Searches are stopped when they find a node that is determined to be a
        common ancestor of all border ancestors, because this shows that it
        cannot be a descendant of any border ancestor.

        The scaling of this operation should be proportional to:

        1. The number of uncommon ancestors
        2. The number of border ancestors
        3. The length of the shortest path between a border ancestor and an
           ancestor of all border ancestors.
        )Ú_find_border_ancestorsÚheads)r   Ú	revisionsÚborder_commonÚcommonÚsidess        r   Úfind_lcazGraph.find_lca  s3   € ðD (,×'BÒ'BÀ9Ñ'MÔ'MÑ$ˆ�v˜uð �zŠz˜-Ñ(Ô(Ð(r   c                 óì   — |                       ||g¦  «        \  }}}|                      ||¦  «         |d         j        }|d         j        }|                     |¦  «        |                     |¦  «        fS )z4Determine the graph difference between two revisionsr   r   )rk   Ú_search_for_extra_commonÚseenÚ
difference)r   Úleft_revisionÚright_revisionÚborderro   Ú	searchersÚleftÚrights           r   Úfind_differencezGraph.find_difference.  sy   € à$(×$?Ò$?Ø˜NÐ+ñ%-ô %-Ñ!ˆ�˜	à×%Ò% f¨iÑ8Ô8Ð8Ø˜Œ|Ô ˆØ˜!”Ô!ˆØ—’ Ñ&Ô&¨×(8Ò(8¸Ñ(>Ô(>Ð?Ð?r   c                 óä   — |                       |                      ||¦  «        ¦  «        }t          t          |¦  «        ¦  «        }|                     |g¦  «        }t          |¦  «         |j        S )z:Find descendants of old_key that are ancestors of new_key.)Úget_child_mapÚ_find_descendant_ancestorsre   r   Ú_make_breadth_first_searcherÚlistrt   )r   Úold_keyÚnew_keyÚ	child_mapÚgraphÚsearchers         r   Úfind_descendantszGraph.find_descendants7  sl   € à×&Ò& t×'FÒ'FØ�Wñ(ô (ñ ô ˆ	åÕ)¨)Ñ4Ô4Ñ5Ô5ˆØ×5Ò5°w°iÑ@Ô@ˆÝˆX‰ŒˆØŒ}Ðr   c                 óx  — |                       |g¦  «        }|                       |g¦  «        }|D ]m}|j                             |¦  «        }|                     |¦  «         |                     |                     ¦   «         ¦  «        }|                     |¦  «         Œn|j                             |j        ¦  «        S )z=Find ancestors of new_key that may be descendants of old_key.)r€   rt   ÚintersectionÚstop_searching_anyÚfind_seen_ancestorsÚstepru   )r   r‚   rƒ   ÚstopÚdescendantsrm   Úold_stopÚ	seen_stops           r   r   z Graph._find_descendant_ancestors@  s¯   € à×0Ò0°'°Ñ;Ô;ˆØ×7Ò7¸¸	ÑBÔBˆØ$ð 	6ð 	6ˆIØ”y×-Ò-¨iÑ8Ô8ˆHØ×*Ò*¨8Ñ4Ô4Ð4Ø#×7Ò7¸¿	º	¹¼ÑDÔDˆIØ×*Ò*¨9Ñ5Ô5Ð5Ð5ØÔ×*Ò*¨4¬9Ñ5Ô5Ð5r   c                 óè   — | j                              |¦  «        }i }t          |                     ¦   «         ¦  «        D ]3\  }}|D ]+}|                     |g ¦  «                             |¦  «         Œ,Œ4|S )zïGet a mapping from parents to children of the specified keys.

        This is simply the inversion of get_parent_map.  Only supplied keys
        will be discovered as children.
        :return: a dict of key:child_list for keys.
        )rh   r   ÚsortedÚitemsÚ
setdefaultÚappend)r   r   rW   Úparent_childÚchildÚparentsÚparents          r   r~   zGraph.get_child_mapK  sŒ   € ð Ô+×:Ò:¸4Ñ@Ô@ˆ
ØˆÝ$ Z×%5Ò%5Ñ%7Ô%7Ñ8Ô8ð 	Bð 	B‰NˆE�7Ø!ð Bð B�Ø×'Ò'¨°Ñ3Ô3×:Ò:¸5ÑAÔAÐAÐAðBàÐr   c                 ó4  — t          |¦  «        }|}d}t          j        }d||<   t          |¦  «        }i }||vrÕ|||<   |dz  }|h}	|	                     |¦  «         |                      |	¦  «        }
|
                     |d¦  «        }|st          j        ||¦  «        ‚|d         }g }|D ]^}|
                     |d¦  «        }|sŒ|d         }||         dz
  }||v r|||         z   c S ||v rŒD|||<   | 	                    |¦  «         Œ_|}||v°Õ||         |z   S )a“  Find the left-hand distance to the NULL_REVISION.

        (This can also be considered the revno of a branch at
        target_revision_id.)

        :param target_revision_id: A revision_id which we would like to know
            the revno for.
        :param known_revision_ids: [(revision_id, revno)] A list of known
            revno, revision_id tuples. We'll use this to seed the search.
        r   r   N)
rJ   r   ÚNULL_REVISIONr�   r1   r   rU   r   ÚGhostRevisionsHaveNoRevnor•   )r   Útarget_revision_idÚknown_revision_idsÚknown_revnosÚcur_tipÚ	num_stepsr›   Úsearching_known_tipsÚunknown_searchedÚ	to_searchrW   r˜   Únext_known_tipsÚrevision_idÚnextÚ
next_revnos                   r   Úfind_distance_to_nullzGraph.find_distance_to_nullY  s”  € õ Ð.Ñ/Ô/ˆØ$ˆØˆ	Ý Ô.ˆØ&'ˆ�]Ñ#å# LÑ1Ô1ÐàÐà˜\Ð)Ð)Ø(1Ð˜WÑ%Ø˜‰NˆIØ ˜	ˆIØ×ÒÐ1Ñ2Ô2Ð2Ø×,Ò,¨YÑ7Ô7ˆJØ —n’n W¨dÑ3Ô3ˆGØð @ÝÔ6Ð7IØ7>ñ@ô @ð @à˜a”jˆGØ ˆOØ3ð -ð -�Ø$Ÿ.š.¨°dÑ;Ô;�Øð ØØ˜q”z�Ø)¨+Ô6¸Ñ:�
ØÐ+Ð+Ð+à%Ð(8¸Ô(>Ñ>Ð>Ð>Ð>Ø˜<Ð'Ð'ØØ%/�˜TÑ"Ø×&Ò& tÑ,Ô,Ð,Ð,Ø#2Ð ð3 ˜\Ð)Ð)ð: ˜GÔ$ yÑ0Ð0r   c                 ó  — g }g }|D ]X}	 |                      ||                      ||¦  «        f¦  «         Œ/# t          j        $ r |                      |¦  «         Y ŒUw xY w|D ]}|                      |df¦  «         Œt	          |¦  «        S )z™Find the distance to null for all the keys in keys.

        :param keys: keys to lookup.
        :return: A dict key->distance for all of keys.
        éÿÿÿÿ)r•   r©   r   rœ   rJ   )r   r   rŸ   ÚghostsrO   s        r   Úfind_lefthand_distanceszGraph.find_lefthand_distancesŽ  sÉ   € ð ˆØˆØð 	#ð 	#ˆCð#Ø×#Ò#Ø˜$×4Ò4°S¸,ÑGÔGÐHñJô Jð Jð JøåÔ3ð #ð #ð #Ø—’˜cÑ"Ô"Ð"Ð"Ð"ð#øøøàð 	+ð 	+ˆCØ×Ò  b 	Ñ*Ô*Ð*Ð*Ý�LÑ!Ô!Ð!s   Š+6¶$AÁAc                 ó¸  — ||v rt          ¦   «         S |                      |g|¦  «        \  }}|j                             |j        ¦  «        }|s|S |                      |||¦  «        \  }}|                      ||||¦  «         |                     |j        ¦  «        }dt          j        v r0t          j	        dt          |¦  «        t          |¦  «        ¦  «         |S )ar  Find the unique ancestors for a revision versus others.

        This returns the ancestry of unique_revision, excluding all revisions
        in the ancestry of common_revisions. If unique_revision is in the
        ancestry, then the empty set will be returned.

        :param unique_revision: The revision_id whose ancestry we are
            interested in.
            (XXX: Would this API be better if we allowed multiple revisions on
            to be searched here?)
        :param common_revisions: Revision_ids of ancestries to exclude.
        :return: A set of revisions in the ancestry of unique_revision
        r…   z%Found %d truly unique nodes out of %d)r/   Ú_find_initial_unique_nodesrt   ru   Ú_make_unique_searchersÚ_refine_unique_nodesr   Údebug_flagsr   ÚmutterÚlen)	r   Úunique_revisionÚcommon_revisionsÚunique_searcherÚcommon_searcherÚunique_nodesÚall_unique_searcherÚunique_tip_searchersÚtrue_unique_nodess	            r   Úfind_unique_ancestorszGraph.find_unique_ancestors¢  s  € ð Ð.Ð.Ð.Ý‘5”5ˆLð* ,0×+JÒ+JØÐÐ/ñ,1ô ,1Ñ(ˆ˜ð 'Ô+×6Ò6°Ô7KÑLÔLˆØð 	 ØÐð "&×!<Ò!<Ø˜?¨Oñ"=ô "=ñ	Ð	Ø	ð 	×!Ò! /Ð3FØ"6¸ñ	Iô 	Ið 	Ià(×3Ò3°OÔ4HÑIÔIÐØ•eÔ'Ð'Ð'ÝŒLÐ@ÝÐ.Ñ/Ô/µ°\Ñ1BÔ1BñDô Dð Dà Ð r   c                 ó|  — |                       |¦  «        }t          |¦  «         |                       |¦  «        }|j        rùt          |                     ¦   «         ¦  «        }t          |                     ¦   «         ¦  «        }|                     |j        ¦  «        }|                     |                     |j        ¦  «        ¦  «         |rg|                     |¦  «        }|                     |                     |¦  «        ¦  «         | 	                    |¦  «         | 
                    |¦  «         |j        °ù||fS )züSteps 1-3 of find_unique_ancestors.

        Find the maximal set of unique nodes. Some of these might actually
        still be common, but we are sure that there are no other unique nodes.

        :return: (unique_searcher, common_searcher)
        )r€   r§   Ú_next_queryr/   rŒ   r‰   rt   r1   r‹   rŠ   Ústart_searching)	r   Úunique_revisionsr¶   r·   r¸   Únext_unique_nodesÚnext_common_nodesÚunique_are_common_nodesÚ	ancestorss	            r   r¯   z Graph._find_initial_unique_nodesÙ  sZ  € ð ×;Ò;Ð<LÑMÔMˆõ 	ˆ_ÑÔÐØ×;Ò;Ð<LÑMÔMˆð Ô)ð 	;Ý # O×$8Ò$8Ñ$:Ô$:Ñ ;Ô ;ÐÝ # O×$8Ò$8Ñ$:Ô$:Ñ ;Ô ;Ðð '8×&DÒ&DØÔ$ñ'&ô '&Ð#à#×*Ò*Ø!×.Ò.¨Ô/CÑDÔDñFô Fð Fà&ð 
;Ø+×?Ò?Ø+ñ-ô -�	ð × Ò Ø#×7Ò7¸	ÑBÔBñDô Dð Dà×2Ò2°9Ñ=Ô=Ð=Ø×/Ò/°	Ñ:Ô:Ð:ð) Ô)ð 	;ð,  Ð/Ð/r   c           
      ó  — |                       ||                      |¦  «        ¦  «        }t          |¦  «        dk    rg }|                     |¦  «        }nÂg }|D ]…}|                     |g¦  «        }|                     |                     |¦  «        ¦  «         |                      |¦  «        }	||	_        |	                     ¦   «          |                     |	¦  «         Œ†d}|D ]3}	|€t          |	j
        ¦  «        }Œ|                     |	j
        ¦  «        }Œ4|                      |¦  «        }
|r{|
                     ¦   «          |                     |                     |¦  «        ¦  «        }d}|D ]:}	|t          |	                     |	                     |¦  «        ¦  «        ¦  «        z  }Œ;dt          j        v rMt          j        dt          |¦  «        t          |¦  «        |t          |¦  «        t          |¦  «        ¦  «         |
|fS )a  Create a searcher for all the unique search tips (step 4).

        As a side effect, the common_searcher will stop searching any nodes
        that are ancestors of the unique searcher tips.

        :return: (all_unique_searcher, unique_tip_searchers)
        r   Nr   r…   zuFor %d unique nodes, created %d + 1 unique searchers (%d stopped search tips, %d common ancestors (%d stopped common))Ú_remove_simple_descendantsr   r´   r‹   r1   r€   Ú_labelrŒ   r•   r/   rt   r‰   rŠ   r   r²   r   r³   )r   r¹   r·   r¸   Úunique_tipsr»   Úancestor_all_uniqueÚtipÚrevs_to_searchr†   rº   Ústopped_commonÚtotal_stoppeds                r   r°   zGraph._make_unique_searchers  sg  € ð ×5Ò5Ø˜$×-Ò-¨lÑ;Ô;ñ=ô =ˆõ ˆ{ÑÔ˜qÒ Ð Ø#%Ð Ø"1×"EÒ"EØñ#ô #ÐÐð $&Ð Ø"ð 6ð 6�Ø!0×!DÒ!DÀcÀUÑ!KÔ!K�Ø×%Ò%Ø#×7Ò7¸ÑGÔGñIô Ið Ià×<Ò<¸^ÑLÔL�à"%�”Ø—’‘”�Ø$×+Ò+¨HÑ5Ô5Ð5Ð5à"&ÐØ0ð 'ð '�Ø&Ð.Ý*-¨h¬mÑ*<Ô*<Ð'Ð'à*=×*JÒ*JØ œñ+'ô +'Ð'Ð'ð #×?Ò?Øñ!ô !Ðàð 	Hð  ×$Ò$Ñ&Ô&Ð&ð -×?Ò?Ø×3Ò3Ð4GÑHÔHñJô JˆNð ˆMØ0ð Hð H�Ø¥ X×%@Ò%@Ø×0Ò0Ð1DÑEÔEñ&Gô &Gñ "Hô "Hñ H��à•eÔ'Ð'Ð'ÝŒLð 0õ ˜\Ñ*Ô*­CÐ0DÑ,EÔ,EØ&­Ð,?Ñ(@Ô(@Ý˜^Ñ,Ô,ñ.ô .ð .ð #Ð$8Ð8Ð8r   c                 ó  — t          |                     ¦   «         ¦  «        }t          ¦   «         }|D ]Ï}t          |                     ¦   «         ¦  «        }|                     |                     |¦  «        ¦  «         |                     |                     |¦  «        ¦  «         |D ]/}||u rŒ|                     |                     |¦  «        ¦  «         Œ0|                     |¦  «         |                     |¦  «         ŒÐ||fS )zStep all the searchers)r/   rŒ   r1   r‹   rÀ   )	r   r¸   r»   r·   Únewly_seen_commonÚnewly_seen_uniquer†   r§   Úalt_searchers	            r   Ú!_step_unique_and_common_searchersz'Graph._step_unique_and_common_searchers>  s  € õ   × 4Ò 4Ñ 6Ô 6Ñ7Ô7ÐÝ™EœEÐØ,ð 		+ð 		+ˆHÝ�x—}’}‘”Ñ'Ô'ˆDØ�KŠK˜×;Ò;¸DÑAÔAÑBÔBÐBØ�KŠK˜×;Ò;¸DÑAÔAÑBÔBÐBØ 4ð Dð D�Ø 8Ð+Ð+ØØ—’˜L×<Ò<¸TÑBÔBÑCÔCÐCÐCØ×$Ò$ TÑ*Ô*Ð*Ø×$Ò$ TÑ*Ô*Ð*Ð*Ø Ð"3Ð3Ð3r   c                 óÜ  — |                      ¦   «         }|D ]}|                     |j        ¦  «         Œ|                     |j        ¦  «         |rœt          j        ¦   «         }|                     ¦   «         }|                     |¦  «         dt          j        v rRt          j        ¦   «         |z
  }	t          j
        d|	t          |¦  «        t          |j        ¦  «        |j        ¦  «         |S )zŸFind nodes that are common to all unique_tip_searchers.

        If it is time, step the all_unique_searcher, and add its nodes to the
        result.
        r…   zKall_unique_searcher step() took %.3fsfor %d nodes (%d total), iteration: %s)ÚcopyÚintersection_updatert   r   Úperf_counterrŒ   r1   r   r²   r   r³   r´   Ú_iterations)
r   r»   rº   rÑ   Ústep_all_uniqueÚcommon_to_all_unique_nodesr†   ÚtstartÚnodesÚtdeltas
             r   Ú _find_nodes_common_to_all_uniquez&Graph._find_nodes_common_to_all_uniqueP  sý   € ð &7×%;Ò%;Ñ%=Ô%=Ð"Ø,ð 	Jð 	JˆHØ&×:Ò:¸8¼=ÑIÔIÐIÐIØ"×6Ò6ØÔ$ñ	&ô 	&ð 	&ð
 ð 		>ÝÔ)Ñ+Ô+ˆFØ'×,Ò,Ñ.Ô.ˆEØ&×-Ò-¨eÑ4Ô4Ð4Ø�%Ô+Ð+Ð+Ý Ô-Ñ/Ô/°&Ñ8�Ý”ð Fà#¥S¨¡Z¤ZµÐ5HÔ5MÑ1NÔ1NØ0Ô<ñ>ô >ð >ð *Ð)r   c           	      óþ  — i }|D ]�}|                      |¦  «        }t          |j        ¦  «        }|s=dt          j        v r.t          j        d|j        |j        t          |¦  «        ¦  «         Œj||vr|g||<   Œu||          
                    |¦  «         Œ‘g }|                     ¦   «         D ]Ð}t          |¦  «        dk    r| 
                    |d         ¦  «         Œ1|d         }	|dd…         D ]!}|	j                             |j        ¦  «         Œ"dt          j        v rHt          j        dt          |¦  «        t          |	j        ¦  «        t          |	j        ¦  «        ¦  «         | 
                    |	¦  «         ŒÑ|S )aW  Combine searchers that are searching the same tips.

        When two searchers are searching the same tips, we can stop one of the
        searchers. We also know that the maximal set of common ancestors is the
        intersection of the two original searchers.

        :return: A list of searchers that are searching unique nodes.
        r…   z@Unique searcher %s was stopped. (%s iterations) %d nodes stoppedr   r   NzQCombining %d searchers into a single searcher searching %d nodes with %d ancestry)rŠ   Ú	frozensetr¿   r   r²   r   r³   rÈ   rØ   r´   r•   Úvaluesrt   rÖ   )
r   r»   rÚ   Úunique_search_tipsr†   ÚstoppedÚwill_search_setÚnext_unique_searchersry   Únext_searchers
             r   Ú_collapse_unique_searchersz Graph._collapse_unique_searchersl  s»  € ð  ÐØ,ð 	Eð 	EˆHØ×1Ò1Ð2LÑMÔMˆGÝ'¨Ô(<Ñ=Ô=ˆOØ"ð EØ�eÔ/Ð/Ð/Ý”Lð "Eà!)¤Ø!)Ô!5Ý!$ W¡¤ñ	/ô /ð /øð
 !Ð(:Ð:Ð:à7?°jÐ" ?Ñ3Ð3à" ?Ô3×:Ò:¸8ÑDÔDÐDÐDð !#ÐØ+×2Ò2Ñ4Ô4ð 	<ð 	<ˆIÝ�9‰~Œ~ Ò"Ð"à%×,Ò,¨Y°q¬\Ñ:Ô:Ð:Ð:ð !*¨!¤�Ø )¨!¨"¨"¤ð Jð J�HØ!Ô&×:Ò:¸8¼=ÑIÔIÐIÐIØ�eÔ/Ð/Ð/Ý”Lð "0õ "% Y¡¤Ý!$ ]Ô%>Ñ!?Ô!?Ý!$ ]Ô%7Ñ!8Ô!8ñ:ô :ð :ð &×,Ò,¨]Ñ;Ô;Ð;Ð;Ø$Ð$r   c                 ó²  — d}|j         �rL|                      |||¦  «        \  }}|                      ||||dk    ¦  «        }|dz   t          z  }|r-|                     |j                             |¦  «        ¦  «         |rR|                     |                     |¦  «        ¦  «         | 	                    |¦  «         |                     |¦  «         |  
                    ||¦  «        }	t          |¦  «        t          |	¦  «        k    rDdt          j        v r6t          j        dt          |¦  «        t          |	¦  «        |j        ¦  «         |	}|j         �°JdS dS )zŽSteps 5-8 of find_unique_ancestors.

        This function returns when common_searcher has stopped searching for
        more nodes.
        r   r   r…   z4Collapsed %d unique searchers => %d at %s iterationsN)r¿   rÓ   rÞ   ÚSTEP_UNIQUE_SEARCHER_EVERYrŠ   rt   r‰   r1   r‹   rÀ   rç   r´   r   r²   r   r³   rØ   )
r   r·   rº   r»   r¸   Ústep_all_unique_counterrÐ   rÑ   rÚ   rå   s
             r   r±   zGraph._refine_unique_nodes¡  sÊ  € ð #$ÐàÔ)ñ '	9à"&×"HÒ"HØÐ!5°ñ#Hô #Hñ ÐØð *.×)NÒ)NØ$Ð&9Ð;LØ'¨1Ò,ñ*.ô *.Ð&ð )@À!Ñ(CÝ)Cñ(DÐ#ð !ð Nð  ×2Ò2Ø'Ô,×9Ò9Ð:KÑLÔLñNô Nð Nà)ð OØ*×1Ò1Ø#×7Ò7Ø2ñ4ô 4ñ5ô 5ð 5ð $×3Ò3Ð4NÑOÔOÐOØ×2Ò2Ð3MÑNÔNÐNà$(×$CÒ$CØ$Ð&@ñ%Bô %BÐ!åÐ'Ñ(Ô(­CÐ0EÑ,FÔ,FÒFÐFØ�eÔ/Ð/Ð/Ý”Lð "5å!$Ð%9Ñ!:Ô!:Ý!$Ð%:Ñ!;Ô!;Ø!4Ô!@ñ	Bô Bð Bð
 $9Ð ðO Ô)ñ '	9ð '	9ð '	9ð '	9ð '	9r   c                 óN   — i }|                       |¦  «        D ]\  }}|�|||<   Œ|S )z¯Get a map of key:parent_list for revisions.

        This implementation delegates to get_parents, for old parent_providers
        that do not supply get_parent_map.
        )rg   )r   rm   rX   Úrevr˜   s        r   r   zGraph.get_parent_mapÕ  s?   € ð ˆØ ×,Ò,¨YÑ7Ô7ð 	&ð 	&‰LˆC�ØÐ"Ø%��s‘øØˆr   c                 ó"   — t          || ¦  «        S r   )Ú_BreadthFirstSearcher)r   rm   s     r   r€   z"Graph._make_breadth_first_searcherá  s   € Ý$ Y°Ñ5Ô5Ð5r   c                 óÈ  ‡ — d|v rt          j        d‰ ¦  «        ‚t          ¦   «         }ˆ fd„|D ¦   «         }t          ¦   «         }	 t          ¦   «         }|D ]-}|                     ¦   «         }|r|                     |¦  «         Œ.t          ¦   «         }|D ]V}	|	|v r|                     |	¦  «         Œ|D ]}|	|j        vr n+Œ|                     |	¦  «         |                     |	¦  «         ŒW|r\|D ]*}|                     |                     |¦  «        ¦  «         Œ+|D ]}|                     |¦  «         Œ|                     |¦  «         t          ¦   «         }
|D ]/}t          |j
        ¦  «        }||
vr|
                     |¦  «         Œ0t          |
¦  «        dk    rA|
                     ¦   «         }|                     |¦  «        }|rt          d|›d|›�¦  «        ‚n�Œ™|||fS )aW  Find common ancestors with at least one uncommon descendant.

        Border ancestors are identified using a breadth-first
        search starting at the bottom of the graph.  Searches are stopped
        whenever a node or one of its descendants is determined to be common.

        This will scale with the number of uncommon ancestors.

        As well as the border ancestors, a set of seen common ancestors and a
        list of sets of seen ancestors for each input revision is returned.
        This allows calculation of graph difference from the results of this
        operation.
        Nc                 ó<   •— g | ]}‰                      |g¦  «        ‘ŒS r   ©r€   )r   Úrr   s     €r   ú
<listcomp>z0Graph._find_border_ancestors.<locals>.<listcomp>õ  s9   ø€ ð )ð )ð )Øð ×6Ò6¸°sÑ;Ô;ð )ð )ð )r   Tr   zXSomehow we ended up converging without actually marking them as in common.
Start_nodes: z
uncommon_nodes: )r   ÚInvalidRevisionIdr/   rŒ   r1   r[   rt   r‹   rÀ   rà   r¿   r´   Úpopru   rC   )r   rm   Úcommon_ancestorsry   Úborder_ancestorsÚ
newly_seenr†   Únew_ancestorsÚ
new_commonr   Úunique_search_setsrä   rÜ   Úuncommon_nodess   `             r   rk   zGraph._find_border_ancestorsä  s|  ø€ ð �9ÐÐÝÔ*¨4°Ñ6Ô6Ð6Ý™5œ5Ðð)ð )ð )ð )Ø'ð)ñ )ô )ˆ	å™5œ5Ðð1	Ý™œˆJØ%ð 5ð 5�Ø (§¢¡¤�Ø ð 5Ø×%Ò% mÑ4Ô4Ð4øÝ™œˆJØ&ð -ð -�ØÐ/Ð/Ð/ð —N’N 8Ñ,Ô,Ð,ØØ )ð -ð -�HØ x¤}Ð4Ð4Ø˜ð 5ð
 %×(Ò(¨Ñ2Ô2Ð2Ø—N’N 8Ñ,Ô,Ð,øØð 4Ø )ð Pð P�HØ×%Ò% h×&BÒ&BÀ:Ñ&NÔ&NÑOÔOÐOÐOØ )ð 9ð 9�HØ×,Ò,¨ZÑ8Ô8Ð8Ð8Ø ×'Ò'¨
Ñ3Ô3Ð3õ "%¡¤ÐØ%ð <ð <�Ý"+¨HÔ,@Ñ"AÔ"A�Ø"Ð*<Ð<Ð<à&×*Ò*¨?Ñ;Ô;Ð;øåÐ%Ñ&Ô&¨!Ò+Ð+Ø*×.Ò.Ñ0Ô0�Ø!&×!1Ò!1Ð2BÑ!CÔ!C�Ø!ð HÝ(˜.ð
 -6¨I¨I°~°~ð*Gñ Hô Hð Hð ñc1	ðd  Ð!1°9Ð<Ð<r   c                 óä  ‡ — t          |¦  «        }t          j        |v r.|                     t          j        ¦  «         |st          j        hS t	          |¦  «        dk     r|S ˆ fd„|D ¦   «         }t          |¦  «        }|                     ¦   «         D ]}t          |¦  «         Œ‰                      g ¦  «        }t	          |¦  «        dk    �r¢t          ¦   «         }	 t          |¦  «         n# t          $ r Y nw xY wt          |¦  «        D ]R}	 ||         }n# t          $ r Y Œw xY w	 |                     t          |¦  «        ¦  «         Œ@# t          $ r ||= Y ŒOw xY wt          ¦   «         }	|D ]×}
|
|v r|                     |
¦  «         ||
= |
|v r||
= |
|j        v r0|
h}|                     ¦   «         D ]}|                     |¦  «         ŒŒ^|                     ¦   «         D ]}|
|j        vr nXŒ|	                     |
¦  «         |                     ¦   «         D ]-}|                     |
g¦  «        }|                     |¦  «         Œ.ŒØ|                     |	¦  «         t	          |¦  «        dk    �°¢|S )aa  Return the heads from amongst keys.

        This is done by searching the ancestries of each key.  Any key that is
        reachable from another key is not returned; all the others are.

        This operation scales with the relative depth between any two keys. If
        any two keys are completely disconnected all ancestry of both sides
        will be retrieved.

        :param keys: An iterable of keys.
        :return: A set of the heads. Note that as a set there is no ordering
            information. Callers will need to filter their input to create
            order if they need it.
        é   c                 ó>   •— i | ]}|‰                      |g¦  «        “ŒS r   rñ   )r   Úcr   s     €r   r   zGraph.heads.<locals>.<dictcomp>D  s;   ø€ ð 3ð 3ð 3Øð ˜×9Ò9¸1¸#Ñ>Ô>ð 3ð 3ð 3r   r   )r/   r   r›   Úremover´   rJ   rá   r§   r€   ÚStopIterationr�   ÚKeyErrorr1   rt   rŠ   r[   r‹   rÀ   )r   r   Úcandidate_headsry   Úactive_searchersr†   Úcommon_walkerrÅ   Ú	candidaterú   ÚancestorÚancestor_setÚseen_ancestorss   `            r   rl   zGraph.heads-  s0  ø€ õ ˜d™)œ)ˆÝÔ! _Ð4Ð4à×"Ò"¥8Ô#9Ñ:Ô:Ð:Ø"ð 0Ý Ô.Ð/Ð/ÝˆÑÔ !Ò#Ð#Ø"Ð"ð3ð 3ð 3ð 3Ø"1ð3ñ 3ô 3ˆ	å 	™?œ?Ðà(×/Ò/Ñ1Ô1ð 	ð 	ˆHÝ�‰NŒNˆNˆNð ×9Ò9¸"Ñ=Ô=ˆÝÐ"Ñ#Ô# aÒ'Ñ'Ý™œˆIðÝ�]Ñ#Ô#Ð#Ð#øÝ ð ð ð à�ðøøøõ "Ð"2Ñ3Ô3ð ð �	ðØ/°	Ô:�H�HøÝð ð ð ð �Hð	øøøð
Ø×$Ò$¥T¨(¡^¤^Ñ4Ô4Ð4Ð4øÝ$ð ð ð Ø(¨Ð3Ø�Hðøøøõ ™œˆJØ%ð Hð H�Ø˜Ð.Ð.Ø#×*Ò*¨8Ñ4Ô4Ð4Ø! (Ð+ØÐ#3Ð3Ð3Ø,¨XÐ6à˜}Ô1Ð1Ð1ð %- :�LØ$-×$4Ò$4Ñ$6Ô$6ð Bð B˜Ø ×3Ò3°LÑAÔAÐAÐAðBð %.×$4Ò$4Ñ$6Ô$6ð Hð H˜Ø#¨8¬=Ð8Ð8Ø!˜Eð 9ð #Ÿš xÑ0Ô0Ð0Ø(1×(8Ò(8Ñ(:Ô(:ð Hð H˜Hà (× <Ò <¸h¸ZÑ HÔ Hð +à$×7Ò7¸ÑGÔGÐGÐGøØ×)Ò)¨*Ñ5Ô5Ð5õe Ð"Ñ#Ô# aÒ'Ñ'ðf Ðs6   ÃC- Ã-
C:Ã9C:ÄDÄ
D%Ä$D%Ä)"EÅEÅEc                 ó¤  — t          |¦  «        dk    rt          |¦  «        S t          |¦  «        }|g}g }t          ¦   «         }|�r|�r|                     ¦   «         }|                     |¦  «         ||v rf|                     |¦  «         |                     |¦  «         t          |¦  «        dk    r(|                     |                     ¦   «         ¦  «         nsŒ™|                      |g¦  «                             |d¦  «        }|sŒÆt          |¦  «        D ]0}	|	|vr|                     |	¦  «         |                     |	¦  «         Œ1|r|�°|S )z¶Find the order that each revision was merged into tip.

        This basically just walks backwards with a stack, and walks left-first
        until it finds a node to stop.
        r   N)
r´   r�   r/   rõ   r[   r•   r  r   rU   Úreversed)
r   Útip_revision_idÚlca_revision_idsÚlooking_forÚstackr4   r�   r§   Ú
parent_idsÚ	parent_ids
             r   Úfind_merge_orderzGraph.find_merge_order†  sq  € õ ÐÑ Ô  AÒ%Ð%ÝÐ(Ñ)Ô)Ð)ÝÐ*Ñ+Ô+ˆð !Ð!ˆØˆÝ‰uŒuˆØñ 	$˜ñ 	$Ø—9’9‘;”;ˆDØ�HŠH�T‰NŒNˆNØ�{Ð"Ð"Ø—’˜TÑ"Ô"Ð"Ø×"Ò" 4Ñ(Ô(Ð(Ý�{Ñ#Ô# qÒ(Ð(Ø—L’L §¢Ñ!2Ô!2Ñ3Ô3Ð3ØØØ×,Ò,¨d¨VÑ4Ô4×8Ò8¸¸tÑDÔDˆJØð ØÝ% jÑ1Ô1ð $ð $�	ð  DÐ(Ð(à—L’L Ñ+Ô+Ð+Ø—’˜Ñ#Ô#Ð#Ð#ð1 ð 	$˜ñ 	$ð2 ˆr   c                 ó~   — |                       ||¦  «        }|                      |¦  «        }d}|D ]}||vr|c S |}ŒdS )a  Find the first lefthand ancestor of tip_key that merged merged_key.

        We do this by first finding the descendants of merged_key, then
        walking through the lefthand ancestry of tip_key until we find a key
        that doesn't descend from merged_key.  Its child is the key that
        merged merged_key.

        :return: The first lefthand ancestor of tip_key to merge merged_key.
            merged_key if it is a lefthand ancestor of tip_key.
            None if no ancestor of tip_key merged merged_key.
        N)r‡   Úiter_lefthand_ancestry)r   Ú
merged_keyÚtip_keyrŽ   Úcandidate_iteratorÚlast_candidater  s          r   Úfind_lefthand_mergerzGraph.find_lefthand_mergerµ  si   € ð ×+Ò+¨J¸Ñ@Ô@ˆØ!×8Ò8¸ÑAÔAÐØˆØ+ð 	'ð 	'ˆIØ Ð+Ð+Ø%Ð%Ð%Ð%Ø&ˆNˆNð	'ð 	'r   Fc                 óâ   — ||g}d}	 |dz  } | j         |Ž }t          |¦  «        dk    r|                     ¦   «         }|r||fS |S t          |¦  «        dk    rt          j        ||¦  «        ‚|}Œi)a‚  Find a unique LCA.

        Find lowest common ancestors.  If there is no unique  common
        ancestor, find the lowest common ancestors of those ancestors.

        Iteration stops when a unique lowest common ancestor is found.
        The graph origin is necessarily a unique lowest common ancestor.

        Note that None is not an acceptable substitute for NULL_REVISION.
        in the input for this method.

        :param count_steps: If True, the return value will be a tuple of
            (unique_lca, steps) where steps is the number of times that
            find_lca was run.  If False, only unique_lca is returned.
        r   Tr   )rq   r´   rõ   r   ÚNoCommonAncestor)r   rv   rw   Úcount_stepsrm   ÚstepsÚlcarX   s           r   Úfind_unique_lcazGraph.find_unique_lcaÉ  sŽ   € ð" # NÐ3ˆ	Øˆð	Ø�Q‰JˆEØ�$”- Ð+ˆCÝ�3‰xŒx˜1Š}ˆ}ØŸš™œ�Øð "Ø! 5˜=Ð(à!�MÝ�3‰xŒx˜1Š}ˆ}ÝÔ-¨m¸^ÑLÔLÐLØˆIð	r   c              #   óŠ  ‡K  — t          |¦  «        }t          ¦   «         Š|r ‰                     |¦  «         |                      |¦  «        }t          ¦   «         }|                     ¦   «         D ]-}|V — |                     ˆfd„|d         D ¦   «         ¦  «         Œ.|                     |¦  «        }|D ]}|dfV — Œ	|}|°ždS dS )aÕ  Iterate the ancestry of this revision.

        :param revision_ids: Nodes to start the search
        :return: Yield tuples mapping a revision_id to its parents for the
            ancestry of revision_id.
            Ghosts will be returned with None as their parents, and nodes
            with no parents will have NULL_REVISION as their only parent. (As
            defined by get_parent_map.)
            There will also be a node for (NULL_REVISION, ())
        c              3   ó$   •K  — | ]
}|‰v¯|V — Œd S r   r   )r   ÚpÚ	processeds     €r   ú	<genexpr>z&Graph.iter_ancestry.<locals>.<genexpr>ü  s-   øè è € Ð#MÐ#M¨!¸!À9Ð:LÐ:L AÐ:LÐ:LÐ:LÐ:LÐ#MÐ#Mr   r   N)r/   r1   r   r“   ru   )	r   Úrevision_idsÚpendingÚnext_mapÚnext_pendingÚitemr¬   Úghostr$  s	           @r   Úiter_ancestryzGraph.iter_ancestryé  s  øè è € õ �lÑ#Ô#ˆÝ‘E”Eˆ	Øð 
	#Ø×Ò˜WÑ%Ô%Ð%Ø×*Ò*¨7Ñ3Ô3ˆHÝ™5œ5ˆLØ ŸšÑ(Ô(ð Nð N�Ø�
�
�
Ø×#Ò#Ð#MÐ#MÐ#MÐ#M¨t°A¬wÐ#MÑ#MÔ#MÑMÔMÐMÐMØ×'Ò'¨Ñ1Ô1ˆFØð $ð $�Ø˜d�mÐ#Ð#Ð#Ð#Ø"ˆGð ð 
	#ð 
	#ð 
	#ð 
	#ð 
	#r   Nc              #   óŠ   ‡ ‡K  — |€d}|Šˆˆ fd„}	 ‰|v rd S  |‰¦  «        }‰V — t          |¦  «        dk    rd S |d         ŠŒ3)Nr   c                 óŽ   •— 	 ‰j                              | g¦  «        |          S # t          $ r t          j        ‰‰¦  «        ‚w xY wr   )rh   r   r  r   ÚRevisionNotPresent)rO   Únext_keyr   s    €€r   rg   z1Graph.iter_lefthand_ancestry.<locals>.get_parents  sY   ø€ ð@ØÔ-×<Ò<¸c¸UÑCÔCÀCÔHÐHøÝð @ð @ð @ÝÔ/°¸$Ñ?Ô?Ð?ð@øøøs	   ƒ $ ¤ ATr   )r´   )r   Ú	start_keyÚ	stop_keysrg   r˜   r0  s   `    @r   r  zGraph.iter_lefthand_ancestry  s�   øøè è € ØÐØˆIØˆð	@ð 	@ð 	@ð 	@ð 	@ð 	@ð
	&Ø˜9Ð$Ð$Ø�Ø!�k (Ñ+Ô+ˆGØˆNˆNˆNÝ�7‰|Œ|˜qÒ Ð Ø�à" 1œ:�ð	&r   c                 ó†   — ddl m} |                     |                      |¦  «        ¦  «        }|                     ¦   «         S )a  Iterate through the input revisions in topological order.

        This sorting only ensures that parents come before their children.
        An ancestor may sort after a descendant if the relationship is not
        visible in the supplied list of revisions.
        r   )Útsort)Úbreezyr4  Ú
TopoSorterr   Úiter_topo_order)r   rm   r4  Úsorters       r   r7  zGraph.iter_topo_order  sI   € ð 	!Ð Ð Ð Ð Ð Ø×!Ò! $×"5Ò"5°iÑ"@Ô"@ÑAÔAˆØ×%Ò%Ñ'Ô'Ð'r   c                 ó:   — |h|                       ||g¦  «        k    S )zýDetermine whether a revision is an ancestor of another.

        We answer this using heads() as heads() has the logic to perform the
        smallest number of parent lookups to determine the ancestral
        relationship between N revisions.
        )rl   )r   Úcandidate_ancestorÚcandidate_descendants      r   Úis_ancestorzGraph.is_ancestor!  s-   € ð %Ð%¨¯ªØÐ!5Ð6ñ*8ô *8ò 8ð 	8r   c                 ój   — |du s|                       ||¦  «        o|du p|                       ||¦  «        S )zšDetermine whether a revision is between two others.

        returns true if and only if:
        lower_bound_revid <= revid <= upper_bound_revid
        N)r<  )r   ÚrevidÚlower_bound_revidÚupper_bound_revids       r   Ú
is_betweenzGraph.is_between+  sP   € ð # dÐ*ð <Ø×!Ò! %Ð):Ñ;Ô;ð=à" dÐ*ð <Ø×!Ò!Ð"3°UÑ;Ô;ð	>r   c                 ó$  — t          |¦  «        dk    rt          d¦  «        ‚|}|d         }|d         }|j                             |j        ¦  «        }|sdS t          |¦  «        }|                      ||                      |¦  «        ¦  «        }t          |¦  «        }g }	|D ]i}
|
|j        v r|}n|}|                     |
g¦  «        }|s|
g}|                      |¦  «        }|                     ¦   «          |	 	                    |¦  «         Œjd}|	D ]3}|€t          |j        ¦  «        }Œ|                     |j        ¦  «        }Œ4t          j        d||¦  «         	 t          ¦   «         }|D ])}|                     |                     ¦   «         ¦  «         Œ*t          ¦   «         }|	D ])}|                     |                     ¦   «         ¦  «         Œ*t          ¦   «         }|D ]'}|	D ]}||j        vr nŒ|                     |¦  «         Œ(|rx|D ]*}|                     |                     |¦  «        ¦  «         Œ+|D ]}|                     |¦  «         Œ|                     |¦  «        }|r|D ]}|                     |¦  «         Œ|rü|	D ]*}|                     |                     |¦  «        ¦  «         Œ+|D ]*}|                     |                     |¦  «        ¦  «         Œ+|	D ]}|                     |¦  «         Œ|D ]}|                     |¦  «         Œ|                     |¦  «         g }t          ¦   «         }|	D ]D}t%          |j        ¦  «        }||vr*|                     |¦  «         | 	                    |¦  «         ŒE|}	|D ]}|j        r nŒdS �Œ6)ab  Make sure that unique nodes are genuinely unique.

        After _find_border_ancestors, all nodes marked "common" are indeed
        common. Some of the nodes considered unique are not, due to history
        shortcuts stopping the searches early.

        We know that we have searched enough when all common search tips are
        descended from all unique (uncommon) nodes because we know that a node
        cannot be an ancestor of its own ancestor.

        :param common: A set of common nodes
        :param searchers: The searchers returned from _find_border_ancestors
        :return: None
        rþ   z/Algorithm not yet implemented for > 2 searchersr   r   Nz3Started %d unique searchers for %d unique revisions)r´   ÚNotImplementedErrorrt   Úsymmetric_differencerÇ   r   r‹   r€   rŒ   r•   r/   r‰   r   r³   r1   r[   rÀ   rŠ   rà   r¿   )r   ro   ry   Úcommon_searchersÚleft_searcherÚright_searcherÚuniqueÚtotal_uniqueÚsimple_uniqueÚunique_searchersr¦   Úparent_searcherrÌ   r†   rÊ   rÐ   rÑ   Únew_common_uniquer   Ústop_searching_commonrå   rû   rä   s                          r   rs   zGraph._search_for_extra_common6  sÏ  € õ< ˆy‰>Œ>˜QÒÐÝ%ØAñCô Cð Cà$ÐØ! !œˆØ" 1œˆØÔ#×8Ò8¸Ô9LÑMÔMˆØð 	ØˆFÝ˜6‘{”{ˆØ×0Ò0°Ø15×1DÒ1DÀVÑ1LÔ1LñNô Nˆå˜F™œˆàÐØ!ð 	.ð 	.ˆKØ˜mÔ0Ð0Ð0Ø"/��à"0�Ø,×@Ò@À+ÀÑOÔOˆNØ!ð /Ø"- �Ø×8Ò8¸ÑHÔHˆHà�MŠM‰OŒOˆOØ×#Ò# HÑ-Ô-Ð-Ð-ð #ÐØ(ð 	#ð 	#ˆHØ"Ð*Ý&)¨(¬-Ñ&8Ô&8Ð#Ð#à&9×&FÒ&FØ”Mñ'#ô '#Ð#Ð#õ 	ŒÐJØ" Lñ	2ô 	2ð 	2ðJ	Ý #¡¤ÐØ,ð :ð :�Ø!×(Ò(¨¯ª©¬Ñ9Ô9Ð9Ð9Ý #¡¤ÐØ,ð :ð :�Ø!×(Ò(¨¯ª©¬Ñ9Ô9Ð9Ð9Ý #¡¤ÐØ-ð 4ð 4�Ø 0ð 4ð 4�HØ x¤}Ð4Ð4Ø˜ð 5ð
 &×)Ò)¨(Ñ3Ô3Ð3øØ ð Kð !1ð Ið I�HØ%×,Ò,Ø ×4Ò4Ð5FÑGÔGñIô Ið Ið Ið !1ð @ð @�HØ×,Ò,Ð->Ñ?Ô?Ð?Ð?ð )<×(HÒ(HØ%ñ)'ô )'Ð%à(ð KØ$4ð Kð K˜Ø ×3Ò3Ð4IÑJÔJÐJÐJØ ð 9à 0ð Ið I�HØ%×,Ò,Ø ×4Ò4Ð5FÑGÔGñIô Ið Ið Ið !1ð Ið I�HØ%×,Ò,Ø ×4Ò4Ð5FÑGÔGñIô Ið Ið Ið !1ð @ð @�HØ×,Ò,Ð->Ñ?Ô?Ð?Ð?Ø 0ð Cð C�HØ×/Ò/Ð0AÑBÔBÐBÐBØ#×*Ò*Ð+<Ñ=Ô=Ð=ð )+Ð%Ý%(¡U¤UÐ"Ø 0ð ?ð ?�HÝ&/°Ô0DÑ&EÔ&E�OØ&Ð.@Ð@Ð@ð +×.Ò.¨Ñ?Ô?Ð?Ø-×4Ò4°XÑ>Ô>Ð>øØ#8Ð Ø,ð ð �ØÔ'ð Ø�Eðð �ñUJ	r   c                 ó¨   — |                      ¦   «         }|                     ¦   «         D ](\  }}|€Œ|D ]}||v r|                     |¦  «          nŒŒ)|S )aM  remove revisions which are children of other ones in the set

        This doesn't do any graph searching, it just checks the immediate
        parent_map to find if there are any children which can be removed.

        :param revisions: A set of revision_ids
        :return: A set of revision_ids with the children removed
        )rÕ   r“   Údiscard)r   rm   rW   Úsimple_ancestorsr   r  r  s          r   rÇ   z Graph._remove_simple_descendantsË  s‚   € ð %Ÿ>š>Ñ+Ô+Ðð( %/×$4Ò$4Ñ$6Ô$6ð 	ð 	Ñ ˆH�jØÐ!ØØ'ð ð �	Ø 	Ð)Ð)ð %×,Ò,¨XÑ6Ô6Ð6Ø�Eð	 *øð
  Ðr   )Fr   )"r    r!   r"   r#   r   r   rq   r|   r‡   r   r~   r©   r­   r½   r¯   r°   rÓ   rÞ   rç   r±   r   r€   rk   rl   r  r  r   r,  r  r7  r<  rA  rs   rÇ   r   r   r   re   re   ë   s  € € € € € ðð ð2ð 2ð 2ð"4ð 4ð 4ð&)ð &)ð &)ðP@ð @ð @ðð ð ð	6ð 	6ð 	6ðð ð ð31ð 31ð 31ðj"ð "ð "ð(5!ð 5!ð 5!ðn&0ð &0ð &0ðP;9ð ;9ð ;9ðz4ð 4ð 4ð$*ð *ð *ð83%ð 3%ð 3%ðj29ð 29ð 29ðh
ð 
ð 
ð6ð 6ð 6ðG=ð G=ð G=ðRWð Wð Wðr-ð -ð -ð^'ð 'ð 'ð* %*ðð ð ð ð@#ð #ð #ð2&ð &ð &ð &ð(	(ð 	(ð 	(ð8ð 8ð 8ð	>ð 	>ð 	>ðSð Sð Sðj& ð & ð & ð & ð & r   re   c                   ó   — e Zd ZdZd„ Zd„ ZdS )Ú
HeadsCachez)A cache of results for graph heads calls.c                 ó"   — || _         i | _        d S r   ©r…   Ú_heads©r   r…   s     r   r   zHeadsCache.__init__÷  ó   € ØˆŒ
ØˆŒˆˆr   c                 óÜ   — t          |¦  «        }	 t          | j        |         ¦  «        S # t          $ r6 | j                             |¦  «        }|| j        |<   t          |¦  «        cY S w xY w)a   Return the heads of keys.

        This matches the API of Graph.heads(), specifically the return value is
        a set which can be mutated, and ordering of the input is not preserved
        in the output.

        :see also: Graph.heads.
        :param keys: The keys to calculate heads for.
        :return: A set containing the heads, which may be mutated without
            affecting future lookups.
        )rà   r/   rV  r  r…   rl   ©r   r   rl   s      r   rl   zHeadsCache.headsû  sw   € õ ˜‰Œˆð	Ý�t”{ 4Ô(Ñ)Ô)Ð)øÝð 	ð 	ð 	Ø”J×$Ò$ TÑ*Ô*ˆEØ %ˆDŒK˜ÑÝ�u‘:”:ÐÐÐð	øøøs   ‘+ «=A+Á*A+N)r    r!   r"   r#   r   rl   r   r   r   rS  rS  ô  s8   € € € € € Ø3Ð3ðð ð ðð ð ð ð r   rS  c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )ÚFrozenHeadsCachez;Cache heads() calls, assuming the caller won't modify them.c                 ó"   — || _         i | _        d S r   rU  rW  s     r   r   zFrozenHeadsCache.__init__  rX  r   c                 óÂ   — t          |¦  «        }	 | j        |         S # t          $ r6 t          | j                             |¦  «        ¦  «        }|| j        |<   |cY S w xY w)a-  Return the heads of keys.

        Similar to Graph.heads(). The main difference is that the return value
        is a frozen set which cannot be mutated.

        :see also: Graph.heads.
        :param keys: The keys to calculate heads for.
        :return: A frozenset containing the heads.
        )rà   rV  r  r…   rl   rZ  s      r   rl   zFrozenHeadsCache.heads  sn   € õ ˜‰Œˆð	Ø”;˜tÔ$Ð$øÝð 	ð 	ð 	Ý˜dœj×.Ò.¨tÑ4Ô4Ñ5Ô5ˆEØ %ˆDŒK˜ÑØˆLˆLˆLð	øøøs   ‘ ž=AÁAc                 óN   — t          |¦  «        | j        t          |¦  «        <   dS )zStore a known value.N)rà   rV  rZ  s      r   rP   zFrozenHeadsCache.cache)  s"   € å'0°Ñ'7Ô'7ˆŒ•I˜d‘O”OÑ$Ð$Ð$r   N)r    r!   r"   r#   r   rl   rP   r   r   r   r\  r\    sG   € € € € € ØEÐEðð ð ðð ð ð$8ð 8ð 8ð 8ð 8r   r\  c                   ó^   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZeZ	d„ Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ ZdS )rî   zôParallel search breadth-first the ancestry of revisions.

    This class implements the iterator protocol, but additionally
    1. provides a set of seen ancestors, and
    2. allows some ancestries to be unsearched, via stop_searching_any
    c                 ó0  — d| _         t          |¦  «        | _        t          ¦   «         | _        t          | j        ¦  «        | _        t          ¦   «         | _        || _        d| _        t          ¦   «         | _        t          ¦   «         | _	        i | _
        d S )Nr   Únext_with_ghosts)rØ   r/   r¿   rt   Ú_started_keysÚ_stopped_keysrh   Ú
_returningÚ_current_presentÚ_current_ghostsÚ_current_parents)r   rm   r6   s      r   r   z_BreadthFirstSearcher.__init__6  sw   € ØˆÔÝ˜y™>œ>ˆÔÝ‘E”EˆŒ	Ý  Ô!1Ñ2Ô2ˆÔÝ ™UœUˆÔØ!1ˆÔØ,ˆŒÝ #¡¤ˆÔÝ"™uœuˆÔØ "ˆÔÐÐr   c                 ó¨   — | j         rd}nd}d                     |t          | j        ¦  «        ¦  «        }d| j         |t          | j        ¦  «        fz  S )NÚ	searchingÚstartingz{}={!r}z1_BreadthFirstSearcher(iterations=%d, %s, seen=%r))rØ   r+   r�   r¿   rt   )r   ÚprefixÚsearchs      r   r   z_BreadthFirstSearcher.__repr__B  s_   € ØÔð 	 Ø ˆFˆFàˆFØ×!Ò! &­$¨tÔ/?Ñ*@Ô*@ÑAÔAˆðØ#Ô/°½¸d¼i¹¼ÐIñJð 	Kr   c                 ó@  — | j         dk    rO|                      | j        ¦  «        \  }}}}| j                             |¦  «         |                     |¦  «        }n| j        }| j                             |¦  «        }| j                             |¦  «        }| j        ||fS )zvGet the current state of this searcher.

        :return: Tuple with started keys, excludes and included keys
        r§   )	re  Ú	_do_queryr¿   rt   r2   Úunionrd  ru   rc  )r   r4   r¬   r§   r˜   Ú
next_queryÚexcludesÚincluded_keyss           r   Ú	get_statez_BreadthFirstSearcher.get_stateK  sž   € ð
 Œ?˜fÒ$Ð$ð ,0¯>ª>¸$Ô:JÑ+KÔ+KÑ(ˆE�6˜4 ð ŒI×'Ò'¨Ñ-Ô-Ð-ØŸš FÑ+Ô+ˆJˆJàÔ)ˆJØÔ%×+Ò+¨JÑ7Ô7ˆØœ	×,Ò,¨XÑ6Ô6ˆØÔ! 8¨]Ð:Ð:r   c                 óD   — 	 t          | ¦  «        S # t          $ r Y dS w xY w)Nr   )r§   r  r   s    r   rŒ   z_BreadthFirstSearcher.stepa  s5   € ð	Ý˜‘:”:ÐøÝð 	ð 	ð 	Ø�2�2ð	øøøs   ‚ ‘
žc                 ó  — | j         dk    rd| _         | xj        dz  c_        n|                      ¦   «          t          | j        ¦  «        dk    rt          ¦   «         ‚| j                             | j        ¦  «         | j        S )aJ  Return the next ancestors of this revision.

        Ancestors are returned in the order they are seen in a breadth-first
        traversal.  No ancestor will be returned more than once. Ancestors are
        returned before their parentage is queried, so ghosts and missing
        revisions (including the start revisions) are included in the result.
        This can save a round trip in LCA style calculation by allowing
        convergence to be detected without reading the data for the revision
        the convergence occurs on.

        :return: A set of revision_ids.
        r§   r   r   )re  rØ   Ú_advancer´   r¿   r  rt   r1   r   s    r   Ú__next__z_BreadthFirstSearcher.__next__g  s€   € ð Œ?˜fÒ$Ð$à$ˆDŒOØÐÔ Ñ!ÐÔÐà�MŠM‰OŒOˆOÝˆtÔÑ Ô  AÒ%Ð%Ý‘/”/Ð!ð 	Œ	×Ò˜Ô)Ñ*Ô*Ð*ØÔÐr   c                 óÞ   — | j         dk    rd| _         |                      ¦   «          t          | j        ¦  «        dk    rt	          ¦   «         ‚|                      ¦   «          | j        | j        fS )a­  Return the next found ancestors, with ghosts split out.

        Ancestors are returned in the order they are seen in a breadth-first
        traversal.  No ancestor will be returned more than once. Ancestors are
        returned only after asking for their parents, which allows us to detect
        which revisions are ghosts and which are not.

        :return: A tuple with (present ancestors, ghost ancestors) sets.
        rb  r   )re  rw  r´   r¿   r  rf  rg  r   s    r   rb  z&_BreadthFirstSearcher.next_with_ghostsƒ  sd   € ð Œ?Ð0Ò0Ð0à0ˆDŒOØ�MŠM‰OŒOˆOÝˆtÔÑ Ô  AÒ%Ð%Ý‘/”/Ð!Ø�Š‰ŒˆØÔ$ dÔ&:Ð:Ð:r   c                 óÐ   — | xj         dz  c_         |                      | j        ¦  «        \  }}}}|| _        || _        || _        || _        | j                             |¦  «         dS )z«Advance the search.

        Updates self.seen, self._next_query, self._current_present,
        self._current_ghosts, self._current_parents and self._iterations.
        r   N)rØ   ro  r¿   rf  rg  rh  rd  r1   )r   r4   r¬   r§   r˜   s        r   rw  z_BreadthFirstSearcher._advance–  st   € ð 	ÐÔ˜AÑÐÔØ'+§~¢~°dÔ6FÑ'GÔ'GÑ$ˆˆv�t˜WØ %ˆÔØ%ˆÔØˆÔØ 'ˆÔð 	Ô×!Ò! &Ñ)Ô)Ð)Ð)Ð)r   c                 ól  ‡	— t          ¦   «         }t          ¦   «         }| j        Š	‰	                     |¦  «         | j                             |¦  «        }|                     |¦  «         |                     ¦   «         D ]-\  }}|€Œˆ	fd„|D ¦   «         }|r|                     |¦  «         Œ.||z
  }||||fS )a  Query for revisions.

        Adds revisions to the seen set.

        :param revisions: Revisions to query.
        :return: A tuple: (set(found_revisions), set(ghost_revisions),
           set(parents_of_found_revisions), dict(found_revisions:parents)).
        Nc                 ó   •— g | ]}|‰v¯|‘Œ	S r   r   )r   r#  rt   s     €r   ró   z3_BreadthFirstSearcher._do_query.<locals>.<listcomp>º  s   ø€ Ð EÐ EÐ E q°qÀ°}°} °}°}°}r   )r/   rt   r1   rh   r   r“   )
r   rm   Úfound_revisionsÚparents_of_foundrW   Úrev_idr˜   Únew_found_parentsÚghost_revisionsrt   s
            @r   ro  z_BreadthFirstSearcher._do_query¦  sØ   ø€ õ ™%œ%ˆÝ™5œ5Ðð ŒyˆØ�Š�IÑÔÐØÔ+×:Ò:¸9ÑEÔEˆ
Ø×Ò˜zÑ*Ô*Ð*Ø)×/Ò/Ñ1Ô1ð 	;ð 	;‰OˆF�GØˆØØ EÐ EÐ EÐ E¨GÐ EÑ EÔ EÐØ ð ;ð !×'Ò'Ð(9Ñ:Ô:Ð:øØ# oÑ5ˆØ Ð1AÀ:ÐMÐMr   c                 ó   — | S r   r   r   s    r   Ú__iter__z_BreadthFirstSearcher.__iter__Â  s   € Øˆr   c                 ó  — | j         }t          |¦  «                             |¦  «        }t          |¦  «        }| j        dk    r| j        }nd}|                     |¦  «         | j        j        }|r� ||¦  «        }g }|                     ¦   «         D ]}	| 	                    |	¦  «         Œ|                     |¦  «         
                    |¦  «        }
|                     |
¦  «         |
                     |¦  «         |
}|°�|S )a  Find ancestors of these revisions that have already been seen.

        This function generally makes the assumption that querying for the
        parents of a node that has already been queried is reasonably cheap.
        (eg, not a round trip to a remote host).
        r§   r   )rt   r/   r‰   re  r¿   r2   rh   r   rá   Úextendru   r1   )r   rm   Úall_seenr'  r
  Únot_searched_yetr   rW   Úall_parentsr  r)  s              r   r‹   z)_BreadthFirstSearcher.find_seen_ancestorsÅ  s(  € ð ”9ˆÝ�i‘.”.×-Ò-¨hÑ7Ô7ˆÝ˜W™œˆàŒ?˜fÒ$Ð$ð  $Ô/ÐÐà!ÐØ×!Ò!Ð"2Ñ3Ô3Ð3ØÔ/Ô>ˆØð 	#Ø'˜¨Ñ0Ô0ˆJØˆKð )×/Ò/Ñ1Ô1ð /ð /�
Ø×"Ò" :Ñ.Ô.Ð.Ð.Ø#×0Ò0Øñô ß'šZ¨Ñ7Ô7ð à×!Ò! ,Ñ/Ô/Ð/Ø×*Ò*Ð+;Ñ<Ô<Ð<Ø"ˆGð ð 	#ð Ðr   c                 ó¬  — t          |¦  «        }| j        dk    r;| j                             |¦  «        }| j                             |¦  «        | _        �nJ| j                             |¦  «        }|                     | j                             |¦  «        ¦  «        }| j                             |¦  «         | j                             |¦  «         i }|D ]+}| j	        |         D ]}||vrd||<   ||xx         dz  cc<   ŒŒ,| j	         
                    ¦   «         D ](}|D ]#}	 ||xx         dz  cc<   Œ# t          $ r Y Œ w xY wŒ)t          ¦   «         }|                     ¦   «         D ] \  }	}
|
dk    r|                     |	¦  «         Œ!| j                             |¦  «         | j                             |¦  «         | j                             |¦  «         |S )a1  
        Remove any of the specified revisions from the search list.

        None of the specified revisions are required to be present in the
        search list.

        It is okay to call stop_searching_any() for revisions which were seen
        in previous iterations. It is the callers responsibility to call
        find_seen_ancestors() to make sure that current search tips that are
        ancestors of those revisions are also stopped.  All explicitly stopped
        revisions will be excluded from the search result's get_keys(), though.
        r§   r   r   )rà   re  r¿   r‰   ru   rf  rp  rg  r2   rh  rá   r  r/   r“   r[   rd  r1   )r   rm   rã   Ústopped_presentÚstop_rev_referencesrì   r  r˜   Ústop_parentsr  Úrefss              r   rŠ   z(_BreadthFirstSearcher.stop_searching_anyì  s0  € õ  ˜iÑ(Ô(ˆ	ØŒ?˜fÒ$Ð$ØÔ&×3Ò3°IÑ>Ô>ˆGØ#Ô/×:Ò:¸9ÑEÔEˆDÔÑà"Ô3×@Ò@ÀÑKÔKˆOØ%×+Ò+ØÔ$×1Ò1°)Ñ<Ô<ñ>ô >ˆGàÔ!×3Ò3°GÑ<Ô<Ð<ØÔ ×2Ò2°7Ñ;Ô;Ð;ð #%ÐØ&ð 8ð 8�Ø!%Ô!6°sÔ!;ð 8ð 8�IØ Ð(;Ð;Ð;Ø9:Ð+¨IÑ6Ø'¨	Ð2Ð2Ô2°aÑ7Ð2Ð2Ñ2Ð2ð8ð  Ô0×7Ò7Ñ9Ô9ð ð �Ø!(ð ð �IðØ+¨IÐ6Ð6Ô6¸!Ñ;Ð6Ð6Ñ6Ð6øÝ#ð ð ð Ø˜ðøøøðõ
 ™5œ5ˆLØ 3× 9Ò 9Ñ ;Ô ;ð -ð -‘�˜Ø˜1’9�9Ø ×$Ò$ VÑ,Ô,Ð,øØÔ×.Ò.¨|Ñ<Ô<Ð<ØÔ×!Ò! 'Ñ*Ô*Ð*ØÔ×!Ò! )Ñ,Ô,Ð,Øˆs   Ä!D2Ä2
D?Ä>D?c                 óJ  — t          |¦  «        }| j                             |¦  «         |                     | j        ¦  «        }| j        dk    r6| j                             |¦  «         | j                             |¦  «         dS |                      |¦  «        \  }}}}| j                             |¦  «         | j	                             |¦  «         | j
                             |¦  «         | j                             |¦  «         | j                             |¦  «         ||fS )aW  Add revisions to the search.

        The parents of revisions will be returned from the next call to next()
        or next_with_ghosts(). If next_with_ghosts was the most recently used
        next* call then the return value is the result of looking up the
        ghost/not ghost status of revisions. (A tuple (present, ghosted)).
        r§   N)rà   rc  r1   ru   rt   re  r¿   ro  rd  rf  rg  rh  )r   rm   Únew_revisionsÚrevsr¬   Úqueryr˜   s          r   rÀ   z%_BreadthFirstSearcher.start_searching  s  € õ ˜iÑ(Ô(ˆ	ØÔ×!Ò! )Ñ,Ô,Ð,Ø!×,Ò,¨T¬YÑ7Ô7ˆØŒ?˜fÒ$Ð$ØÔ×#Ò# MÑ2Ô2Ð2ØŒI×Ò˜]Ñ+Ô+Ð+Ð+Ð+ð ,0¯>ª>¸)Ñ+DÔ+DÑ(ˆD�&˜% ØÔ×%Ò% fÑ-Ô-Ð-ØÔ!×(Ò(¨Ñ.Ô.Ð.ØÔ ×'Ò'¨Ñ/Ô/Ð/ØÔ×#Ò# EÑ*Ô*Ð*ØÔ!×(Ò(¨Ñ1Ô1Ð1Ø˜�<Ðr   N)r    r!   r"   r#   r   r   rt  rŒ   rx  r§   rb  rw  ro  rƒ  r‹   rŠ   rÀ   r   r   r   rî   rî   .  sá   € € € € € ðð ð
#ð 
#ð 
#ðKð Kð Kð;ð ;ð ;ð,ð ð ð ð  ð  ð4 €Dð;ð ;ð ;ð&*ð *ð *ð Nð Nð Nð8ð ð ð%ð %ð %ðN1ð 1ð 1ðf ð  ð  ð  ð  r   rî   c                 ó|   — i }|                       ¦   «         D ]$\  }}|D ]}||vr|f||<   Œ||         |fz   ||<   ŒŒ%|S )zCGiven a map from child => parents, create a map of parent=>children)r“   )rW   r„   r—   r˜   r#  s        r   Úinvert_parent_mapr“  8  sr   € à€IØ$×*Ò*Ñ,Ô,ð 7ð 7‰ˆˆwØð 	7ð 	7ˆAð ˜	Ð!Ð!Ø %˜x�	˜!‘�à(¨œ|¨u¨hÑ6�	˜!‘�ð	7ð Ðr   c                 ó~  — i }|                       ¦   «         D ]I\  }}|                     |g ¦  «         |D ]+}|                     |g ¦  «                             |¦  «         Œ,ŒJt          ¦   «         }t	          | ¦  «        }| D ]¼}||         }t          |¦  «        dk    rŸ||d                  }t          |¦  «        dk    rŒ?||         }	t          |	¦  «        dk    rŒ[|                     |	d         d¦  «        }
t          |
¦  «        dk    rŒ‹|||	d         <   |	||d         <   ||= ||= |                     |¦  «         Œ½|S )a!  Collapse regions of the graph that are 'linear'.

    For example::

      A:[B], B:[C]

    can be collapsed by removing B and getting::

      A:[C]

    :param parent_map: A dictionary mapping children to their parents
    :return: Another dictionary with 'linear' chains collapsed
    r   r   N)r“   r”   r•   r/   rJ   r´   rU   r[   )rW   Úchildrenr—   r˜   r#  ÚremovedrX   ÚnodeÚparent_childrenÚnode_childrenÚchild_parentss              r   Úcollapse_linear_regionsr›  G  sq  € ðN €HØ$×*Ò*Ñ,Ô,ð 5ð 5‰ˆˆwØ×Ò˜E 2Ñ&Ô&Ð&Øð 	5ð 	5ˆAØ×Ò  2Ñ&Ô&×-Ò-¨eÑ4Ô4Ð4Ð4ð	5õ ‰eŒe€GÝ�*ÑÔ€FØð ð ˆØ˜”,ˆÝˆw‰<Œ<˜1ÒÐØ& w¨q¤zÔ2ˆOÝ�?Ñ#Ô# qÒ(Ð(àØ$ TœNˆMÝ�=Ñ!Ô! QÒ&Ð&ØØ"ŸJšJ }°QÔ'7¸Ñ>Ô>ˆMÝ�=Ñ!Ô! QÒ&Ð&àð (/ˆF�= Ô#Ñ$Ø#0ˆH�W˜Q”ZÑ Ø�t�Ø˜�Ø�KŠK˜ÑÔÐøà€Mr   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚGraphThunkIdsToKeysz7Forwards calls about 'ids' to be about keys internally.c                 ó   — || _         d S r   )Ú_graphrW  s     r   r   zGraphThunkIdsToKeys.__init__’  s   € ØˆŒˆˆr   c                 óH   — d„ | j                              ¦   «         D ¦   «         S )Nc                 ó   — g | ]\  }|‘ŒS r   r   )r   rò   s     r   ró   z1GraphThunkIdsToKeys.topo_sort.<locals>.<listcomp>–  s   € Ð6Ð6Ð6‘d�q�Ð6Ð6Ð6r   )rŸ  Ú	topo_sortr   s    r   r¢  zGraphThunkIdsToKeys.topo_sort•  s$   € Ø6Ð6˜dœk×3Ò3Ñ5Ô5Ð6Ñ6Ô6Ð6r   c                 óf   — d„ |D ¦   «         }| j                              |¦  «        }d„ |D ¦   «         S )zSee Graph.heads()c                 ó   — g | ]}|f‘ŒS r   r   )r   Úis     r   ró   z-GraphThunkIdsToKeys.heads.<locals>.<listcomp>š  s   € Ð%Ð%Ð%˜A�A�4Ð%Ð%Ð%r   c                 ó   — h | ]
}|d          ’ŒS )r   r   )r   Úhs     r   rS   z,GraphThunkIdsToKeys.heads.<locals>.<setcomp>œ  s   € Ð(Ð(Ð(˜��!”Ð(Ð(Ð(r   )rŸ  rl   )r   ÚidsÚas_keysÚ	head_keyss       r   rl   zGraphThunkIdsToKeys.heads˜  s>   € à%Ð% Ð%Ñ%Ô%ˆØ”K×%Ò% gÑ.Ô.ˆ	Ø(Ð(˜iÐ(Ñ(Ô(Ð(r   c                 ój   — | j                              |f¦  «        }|D ]}|j        d         |_        Œ|S )Nr   )rŸ  Ú
merge_sortrO   )r   Útip_revisionrÜ   r—  s       r   r¬  zGraphThunkIdsToKeys.merge_sortž  s<   € Ø”×&Ò&¨ Ñ7Ô7ˆØð 	#ð 	#ˆDØ”x ”{ˆDŒHˆHØˆr   c                 óR   — | j                              |fd„ |D ¦   «         ¦  «         d S )Nc                 ó   — g | ]}|f‘ŒS r   r   )r   r#  s     r   ró   z0GraphThunkIdsToKeys.add_node.<locals>.<listcomp>¥  s   € Ð*AÐ*AÐ*A°A¨A¨4Ð*AÐ*AÐ*Ar   )rŸ  Úadd_node)r   r   r˜   s      r   r°  zGraphThunkIdsToKeys.add_node¤  s1   € ØŒ×Ò˜h˜[Ð*AÐ*A¸Ð*AÑ*AÔ*AÑBÔBÐBÐBÐBr   N)	r    r!   r"   r#   r   r¢  rl   r¬  r°  r   r   r   r�  r�  �  sj   € € € € € ØAÐAðð ð ð7ð 7ð 7ð)ð )ð )ðð ð ðCð Cð Cð Cð Cr   r�  )r   r   r   r   r   r   r   )Ú
KnownGraph)ÚtimeÚ r   r   r   r   r   ré   r   r%   r:   r]   re   rS  r\  rî   r“  r›  r�  Ú	_countersÚ_known_graph_pyxr±  ÚImportErrorÚeÚfailed_to_load_extensionÚ_known_graph_pyr   r   r   ú<module>rº     sŒ  ðð" €€€ðð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð ð2?ð ?ð ?ð ?ð ?ñ ?ô ?ð ?ð(4ð 4ð 4ð 4ð 4ñ 4ô 4ð 4ðnX'ð X'ð X'ð X'ð X'ñ X'ô X'ð X'ðv#ð #ð #ð #ð #ñ #ô #ð #ð"F ð F ð F ð F ð F ñ F ô F ð F ðR ð ð ð ð ñ ô ð ð88ð 8ð 8ð 8ð 8ñ 8ô 8ð 8ð<G ð G ð G ð G ð G ñ G ô G ð G ðTð ð ðEð Eð EðPCð Cð Cð Cð Cñ Cô Cð Cð2 "Ð!Ð!€	ð,Ø,Ð,Ð,Ð,Ð,Ð,Ð,Ð,øØð ,ð ,ð ,Ø$€GÔ$ QÑ'Ô'Ð'Ø+Ð+Ð+Ð+Ð+Ð+Ð+Ð+Ð+Ð+Ð+Ð+øøøøð,øøøs   ÂB ÂCÂ"B>Â>C