§
    cÌcFK  ã                   ó.  — d Z ddlZddlmZmZmZ ddlmZmZm	Z	  G d„ d¦  «        Z
 G d„ d	¦  «        Z G d
„ de
¦  «        Z G d„ de
¦  «        Z G d„ de
¦  «        Z G d„ de
¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Zd„ Zd„ Zd„ Zd„ ZdS )z)Searching in versioned file repositories.é    Né   )ÚdebugÚrevisionÚtrace)ÚDictParentsProviderÚGraphÚinvert_parent_mapc                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚAbstractSearchResultz¶The result of a search, describing a set of keys.

    Search results are typically used as the 'fetch_spec' parameter when
    fetching revisions.

    :seealso: AbstractSearch
    c                 ó*   — t          | j        ¦  «        ‚)a  Return a recipe that can be used to replay this search.

        The recipe allows reconstruction of the same results at a later date.

        :return: A tuple of `(search_kind_str, *details)`.  The details vary by
            kind of search result.
        ©ÚNotImplementedErrorÚ
get_recipe©Úselfs    ú6/usr/lib/python3/dist-packages/breezy/bzr/vf_search.pyr   zAbstractSearchResult.get_recipe+   s   € õ " $¤/Ñ2Ô2Ð2ó    c                 ó*   — t          | j        ¦  «        ‚)z=Return a tuple that can be transmitted via the HPSS protocol.)r   Úget_network_structr   s    r   r   z'AbstractSearchResult.get_network_struct5   s   € å! $Ô"9Ñ:Ô:Ð:r   c                 ó*   — t          | j        ¦  «        ‚©zOReturn the keys found in this search.

        :return: A set of keys.
        )r   Úget_keysr   s    r   r   zAbstractSearchResult.get_keys9   s   € õ
 " $¤-Ñ0Ô0Ð0r   c                 ó*   — t          | j        ¦  «        ‚)ú5Return false if the search lists 1 or more revisions.)r   Úis_emptyr   s    r   r   zAbstractSearchResult.is_empty@   s   € å! $¤-Ñ0Ô0Ð0r   c                 ó*   — t          | j        ¦  «        ‚)zûCreate a new search by refining this search.

        :param seen: Revisions that have been satisfied.
        :param referenced: Revision references observed while satisfying some
            of this search.
        :return: A search result.
        )r   Úrefine©r   ÚseenÚ
referenceds      r   r   zAbstractSearchResult.refineD   s   € õ " $¤+Ñ.Ô.Ð.r   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   © r   r   r   r   "   si   € € € € € ðð ð3ð 3ð 3ð;ð ;ð ;ð1ð 1ð 1ð1ð 1ð 1ð/ð /ð /ð /ð /r   r   c                   ó   — e Zd ZdZd„ ZdS )ÚAbstractSearchzbA search that can be executed, producing a search result.

    :seealso: AbstractSearchResult
    c                 ó*   — t          | j        ¦  «        ‚)zòConstruct a network-ready search result from this search description.

        This may take some time to search repositories, etc.

        :return: A search result (an object that implements
            AbstractSearchResult's API).
        )r   Úexecuter   s    r   r)   zAbstractSearch.executeU   s   € õ " $¤,Ñ/Ô/Ð/r   N)r!   r"   r#   r$   r)   r%   r   r   r'   r'   O   s-   € € € € € ðð ð
0ð 0ð 0ð 0ð 0r   r'   c                   ó<   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	S )
ÚSearchResultzŸThe result of a breadth first search.

    A SearchResult provides the ability to reconstruct the search or access a
    set of the keys the search found.
    c                 óD   — d|||f| _         t          |¦  «        | _        dS )aÑ  Create a SearchResult.

        :param start_keys: The keys the search started at.
        :param exclude_keys: The keys the search excludes.
        :param key_count: The total number of keys (from start to but not
            including exclude).
        :param keys: The keys the search found. Note that in future we may get
            a SearchResult from a smart server, in which case the keys list is
            not necessarily immediately available.
        ÚsearchN)Ú_recipeÚ	frozensetÚ_keys)r   Ú
start_keysÚexclude_keysÚ	key_countÚkeyss        r   Ú__init__zSearchResult.__init__g   s%   € ð ! *¨l¸IÐFˆŒÝ˜t‘_”_ˆŒ
ˆ
ˆ
r   c                 óŠ  — | j         \  }}}}t          |¦  «        dk    r0t          t          |¦  «        d d…         ¦  «        d d…         dz   }nt          |¦  «        }t          |¦  «        dk    r0t          t          |¦  «        d d…         ¦  «        d d…         dz   }nt          |¦  «        }d| j        j        ||||fz  S )Né   éÿÿÿÿú, ...]z<%s %s:(%s, %s, %d)>)r.   ÚlenÚreprÚlistÚ	__class__r!   )r   Úkindr1   r2   r3   Ústart_keys_reprÚexclude_keys_reprs          r   Ú__repr__zSearchResult.__repr__u   sÖ   € Ø48´LÑ1ˆˆj˜,¨	Ýˆz‰?Œ?˜QÒÐÝ"¥4¨
Ñ#3Ô#3°B°Q°BÔ#7Ñ8Ô8¸¸"¸Ô=ÀÑHˆOˆOå" :Ñ.Ô.ˆOÝˆ|ÑÔ˜qÒ Ð Ý $¥T¨,Ñ%7Ô%7¸¸¸Ô%;Ñ <Ô <¸S¸b¸SÔ AÀHÑ LÐÐå $ \Ñ 2Ô 2ÐØ%¨¬Ô)@Ø)-¨Ð@QÐS\ð)^ñ ^ð 	^r   c                 ó   — | j         S )a—  Return a recipe that can be used to replay this search.

        The recipe allows reconstruction of the same results at a later date
        without knowing all the found keys. The essential elements are a list
        of keys to start and to stop at. In order to give reproducible
        results when ghosts are encountered by a search they are automatically
        added to the exclude list (or else ghost filling may alter the
        results).

        :return: A tuple ('search', start_keys_set, exclude_keys_set,
            revision_count). To recreate the results of this search, create a
            breadth first searcher on the same graph starting at start_keys.
            Then call next() (or next_with_ghosts()) repeatedly, and on every
            result, call stop_searching_any on any keys from the exclude_keys
            set. The revision_count value acts as a trivial cross-check - the
            found revisions of the new search should have as many elements as
            revision_count. If it does not, then additional revisions have been
            ghosted since the search was executed the first time and the second
            time.
        ©r.   r   s    r   r   zSearchResult.get_recipe‚   s   € ð* Œ|Ðr   c                 óL  — d                      | j        d         ¦  «        }d                      | j        d         ¦  «        }t          | j        d         ¦  «                             d¦  «        }| j        d                              d¦  «        d                      |||f¦  «        fS )Nó    é   r   é   Úasciir   ó   
)Újoinr.   ÚstrÚencode)r   r1   Ú	stop_keysÚcounts       r   r   zSearchResult.get_network_struct™   sˆ   € Ø—Y’Y˜tœ|¨AœÑ/Ô/ˆ
Ø—I’I˜dœl¨1œoÑ.Ô.ˆ	Ý�D”L ”OÑ$Ô$×+Ò+¨GÑ4Ô4ˆØ”˜Q”×&Ò& wÑ/Ô/Ø—
’
˜J¨	°5Ð9Ñ:Ô:ð<ð 	<r   c                 ó   — | j         S r   )r0   r   s    r   r   zSearchResult.get_keys    s   € ð
 ŒzÐr   c                 ó$   — | j         d         dk    S )r   rG   r   rC   r   s    r   r   zSearchResult.is_empty§   s   € àŒ|˜AŒ !Ò#Ð#r   c                 óº  — | j         d         }| j         d         }| j         d         }|                      ¦   «         }t          |¦  «        }|                     |¦  «         |                     |¦  «         |                     |¦  «         |                     |¦  «        }|                     |¦  «         ||z
  }|t          |¦  «        z  }t          ||||¦  «        S )úÙCreate a new search by refining this search.

        :param seen: Revisions that have been satisfied.
        :param referenced: Revision references observed while satisfying some
            of this search.
        rF   r   rG   )r.   r   ÚsetÚupdateÚdifference_updateÚintersectionr:   r+   )	r   r   r    ÚstartÚexcluderN   r4   Úpending_refsÚ
seen_headss	            r   r   zSearchResult.refine«   sË   € ð ”˜Q”ˆØ”,˜q”/ˆØ”˜Q”ˆØ�}Š}‰Œˆå˜:‘”ˆØ×Ò˜EÑ"Ô"Ð"Ø×&Ò& tÑ,Ô,Ð,Ø×&Ò& wÑ/Ô/Ð/à×'Ò'¨Ñ-Ô-ˆ
Ø�Š�zÑ"Ô"Ð"à�d‰{ˆà•�T‘”ÑˆÝ˜L¨'°5¸$Ñ?Ô?Ð?r   N©r!   r"   r#   r$   r5   rA   r   r   r   r   r   r%   r   r   r+   r+   `   s�   € € € € € ðð ð%ð %ð %ð^ð ^ð ^ðð ð ð.<ð <ð <ðð ð ð$ð $ð $ð@ð @ð @ð @ð @r   r+   c                   óB   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
S )ÚPendingAncestryResultzÖA search result that will reconstruct the ancestry for some graph heads.

    Unlike SearchResult, this doesn't hold the complete search result in
    memory, it just holds a description of how to generate it.
    c                 ó<   — t          |¦  «        | _        || _        dS )z«Constructor.

        :param heads: an iterable of graph heads.
        :param repo: a repository to use to generate the ancestry for the given
            heads.
        N)r/   ÚheadsÚrepo)r   r_   r`   s      r   r5   zPendingAncestryResult.__init__Ì   s   € õ ˜uÑ%Ô%ˆŒ
ØˆŒ	ˆ	ˆ	r   c                 óF  — t          | j        ¦  «        dk    rPt          t          | j        ¦  «        d d…         ¦  «        d d…         }|dt          | j        ¦  «        dz
  fz  z  }nt          | j        ¦  «        }d                     | j        j        || j        ¦  «        S )Nr7   r8   z, <%d more>...]z<{} heads:{} repo:{!r}>)r:   r_   r;   r<   Úformatr=   r!   r`   )r   Ú
heads_reprs     r   rA   zPendingAncestryResult.__repr__Ö   s•   € ÝˆtŒz‰?Œ?˜QÒÐÝ�d 4¤:Ñ.Ô.¨r°¨rÔ2Ñ3Ô3°C°R°CÔ8ˆJØÐ+­s°4´:©¬ÀÑ/BÐ.DÑDÑDˆJˆJå˜dœjÑ)Ô)ˆJØ(×/Ò/ØŒNÔ# Z°´ñ<ô <ð 	<r   c                 ó0   — d| j         t          ¦   «         dfS )ai  Return a recipe that can be used to replay this search.

        The recipe allows reconstruction of the same results at a later date.

        :seealso SearchResult.get_recipe:

        :return: A tuple ('proxy-search', start_keys_set, set(), -1)
            To recreate this result, create a PendingAncestryResult with the
            start_keys_set.
        zproxy-searchr8   )r_   rS   r   s    r   r   z PendingAncestryResult.get_recipeß   s   € ð  ¤
­C©E¬E°2Ð6Ð6r   c                 ó@   — dg}|                      | j        ¦  «         |S )Ns   ancestry-of)Úextendr_   )r   Úpartss     r   r   z(PendingAncestryResult.get_network_structì   s#   € ØÐ ˆØ�Š�T”ZÑ Ô Ð Øˆr   c                 óZ   — |                       | j                             ¦   «         ¦  «        S )z�See SearchResult.get_keys.

        Returns all the keys for the ancestry of the heads, excluding
        NULL_REVISION.
        )Ú	_get_keysr`   Ú	get_graphr   s    r   r   zPendingAncestryResult.get_keysñ   s$   € ð �~Š~˜dœi×1Ò1Ñ3Ô3Ñ4Ô4Ð4r   c                 ól   ‡— t           j        Šˆfd„|                     | j        ¦  «        D ¦   «         }|S )Nc                 ó*   •— g | ]\  }}|‰k    ¯|®|‘ŒS ©Nr%   )Ú.0ÚkeyÚparentsÚNULL_REVISIONs      €r   ú
<listcomp>z3PendingAncestryResult._get_keys.<locals>.<listcomp>û   s9   ø€ ð Að Að A™˜˜gØ˜-Ò'Ð'¨GÐ,?ð Ø,?Ð,?Ð,?r   )r   rq   Úiter_ancestryr_   )r   Úgraphr4   rq   s      @r   ri   zPendingAncestryResult._get_keysù   sN   ø€ Ý Ô.ˆðAð Að Að A¨%×*=Ò*=¸d¼jÑ*IÔ*Ið Añ Aô Aˆàˆr   c                 óˆ   — t           j        | j        v rt          | j        ¦  «        dk    S t          | j        ¦  «        dk    S )r   rF   r   )r   rq   r_   r:   r   s    r   r   zPendingAncestryResult.is_emptyÿ   s8   € åÔ! T¤ZÐ/Ð/Ý�t”z‘?”? aÒ'Ð'å�t”z‘?”? aÒ'Ð'r   c                 óf   — | j                              |¦  «        }t          ||z
  | j        ¦  «        S )rR   )r_   Úunionr]   r`   r   s      r   r   zPendingAncestryResult.refine  s0   € ð ”Z×%Ò% jÑ1Ô1ˆ
Ý$ Z°$Ñ%6¸¼	ÑBÔBÐBr   N)r!   r"   r#   r$   r5   rA   r   r   r   ri   r   r   r%   r   r   r]   r]   Å   s›   € € € € € ðð ðð ð ð<ð <ð <ð7ð 7ð 7ðð ð ð
5ð 5ð 5ðð ð ð(ð (ð (ðCð Cð Cð Cð Cr   r]   c                   ó   — e Zd ZdZd„ ZdS )ÚEmptySearchResultzAn empty search result.c                 ó   — dS )NTr%   r   s    r   r   zEmptySearchResult.is_empty  s   € Øˆtr   N)r!   r"   r#   r$   r   r%   r   r   ry   ry     s)   € € € € € Ø!Ð!ðð ð ð ð r   ry   c                   ó<   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	S )
ÚEverythingResultzBA search result that simply requests everything in the repository.c                 ó   — || _         d S rm   )Ú_repo)r   r`   s     r   r5   zEverythingResult.__init__  s   € ØˆŒ
ˆ
ˆ
r   c                 óL   — d                      | j        j        | j        ¦  «        S )Nz{}({!r}))rb   r=   r!   r~   r   s    r   rA   zEverythingResult.__repr__  s   € Ø× Ò  ¤Ô!8¸$¼*ÑEÔEÐEr   c                 ó*   — t          | j        ¦  «        ‚rm   r   r   s    r   r   zEverythingResult.get_recipe!  s   € Ý! $¤/Ñ2Ô2Ð2r   c                 ó   — dS )N)s
   everythingr%   r   s    r   r   z#EverythingResult.get_network_struct$  s   € ØÐr   c                 óº   — dt           j        v r5ddlm} t	          | j        |j        ¦  «        rt          j        dd¦  «         | j         	                    ¦   «         S )NÚevilrF   )Úremoter   z6EverythingResult(RemoteRepository).get_keys() is slow.)
r   Údebug_flagsÚ r„   Ú
isinstancer~   ÚRemoteRepositoryr   Úmutter_callsiteÚall_revision_ids)r   r„   s     r   r   zEverythingResult.get_keys'  sl   € Ø•UÔ&Ð&Ð&Ø Ð Ð Ð Ð Ð Ý˜$œ* fÔ&=Ñ>Ô>ð QåÔ%ØÐOñQô Qð QàŒz×*Ò*Ñ,Ô,Ð,r   c                 ó   — dS )NFr%   r   s    r   r   zEverythingResult.is_empty0  s	   € ð ˆur   c                 óÌ   — t          | j                             ¦   «         ¦  «        }|                     |¦  «         |                     |¦  «         t          || j        ¦  «        S rm   )rS   r~   rŠ   rU   rT   r]   )r   r   r    r_   s       r   r   zEverythingResult.refine6  sU   € Ý�D”J×/Ò/Ñ1Ô1Ñ2Ô2ˆØ×Ò Ñ%Ô%Ð%Ø�Š�ZÑ Ô Ð Ý$ U¨D¬JÑ7Ô7Ð7r   Nr[   r%   r   r   r|   r|     s†   € € € € € ØLÐLðð ð ðFð Fð Fð3ð 3ð 3ð ð  ð  ð-ð -ð -ðð ð ð8ð 8ð 8ð 8ð 8r   r|   c                   ó    — e Zd ZdZdd„Zd„ ZdS )ÚEverythingNotInOtherz=Find all revisions in that are in one repo but not the other.Fc                 ó0   — || _         || _        || _        d S rm   )Úto_repoÚ	from_repoÚfind_ghosts)r   r�   r‘   r’   s       r   r5   zEverythingNotInOther.__init__@  s   € ØˆŒØ"ˆŒØ&ˆÔÐÐr   c                 óN   — | j                              | j        | j        ¬¦  «        S )N)r’   )r�   Úsearch_missing_revision_idsr‘   r’   r   s    r   r)   zEverythingNotInOther.executeE  s+   € ØŒ|×7Ò7ØŒN¨Ô(8ð 8ñ :ô :ð 	:r   N)F)r!   r"   r#   r$   r5   r)   r%   r   r   rŽ   rŽ   =  s=   € € € € € ØGÐGð'ð 'ð 'ð 'ð
:ð :ð :ð :ð :r   rŽ   c                   ó*   — e Zd ZdZ	 	 dd„Zd„ Zd„ ZdS )ÚNotInOtherForRevszAFind all revisions missing in one repo for a some specific heads.NFc                 óZ   — || _         || _        || _        || _        || _        || _        dS )a7  Constructor.

        :param required_ids: revision IDs of heads that must be found, or else
            the search will fail with NoSuchRevision.  All revisions in their
            ancestry not already in the other repository will be included in
            the search result.
        :param if_present_ids: revision IDs of heads that may be absent in the
            source repository.  If present, then their ancestry not already
            found in other will be included in the search result.
        :param limit: maximum number of revisions to fetch
        N)r�   r‘   r’   Úrequired_idsÚif_present_idsÚlimit)r   r�   r‘   r˜   r™   r’   rš   s          r   r5   zNotInOtherForRevs.__init__M  s5   € ð ˆŒØ"ˆŒØ&ˆÔØ(ˆÔØ,ˆÔØˆŒ
ˆ
ˆ
r   c                 ó   — t          | j        ¦  «        dk    r5t          t          | j        ¦  «        d d…         ¦  «        d d…         dz   }nt          | j        ¦  «        }| j        rMt          | j        ¦  «        dk    r5t          t          | j        ¦  «        d d…         ¦  «        d d…         dz   }nt          | j        ¦  «        }d| j        j        ›d| j        ›d| j        ›d| j	        ›d|›d	|›d
| j
        ›d�S )Nr7   r8   r9   ú<z from:z to:z find_ghosts:z req'd:z if-present:zlimit:ú>)r:   r˜   r;   r<   r™   r=   r!   r‘   r�   r’   rš   )r   Úreqd_revs_reprÚifp_revs_reprs      r   rA   zNotInOtherForRevs.__repr__a  s  € ÝˆtÔ Ñ!Ô! AÒ%Ð%Ý!¥$ tÔ'8Ñ"9Ô"9¸"¸1¸"Ô"=Ñ>Ô>¸sÀ¸sÔCÀhÑNˆNˆNå! $Ô"3Ñ4Ô4ˆNØÔð 	6¥3 tÔ':Ñ#;Ô#;¸aÒ#?Ð#?Ý ¥ dÔ&9Ñ!:Ô!:¸2¸A¸2Ô!>Ñ?Ô?ÀÀÀÔDÀxÑOˆMˆMå  Ô!4Ñ5Ô5ˆMøð ŒNÔ#Ð#Ð# T¤^ ^ ^°T´\°\°\ØÔÐÐ˜n˜n˜n¨m¨m¨mØŒJˆJˆJð	ð 	r   c                 ór   — | j                              | j        | j        | j        | j        | j        ¬¦  «        S )N)Úrevision_idsr™   r’   rš   )r�   r”   r‘   r˜   r™   r’   rš   r   s    r   r)   zNotInOtherForRevs.executeq  s;   € ØŒ|×7Ò7ØŒN¨Ô):ØÔ.¸DÔ<LØ”*ð 8ñ ô ð 	r   )NFN)r!   r"   r#   r$   r5   rA   r)   r%   r   r   r–   r–   J  sR   € € € € € ØKÐKàHLØ*.ðð ð ð ð(ð ð ð ð ð ð ð r   r–   c                 ó¼  — | sg g dfS t          | ¦  «        }t          t          j                             |                      ¦   «         ¦  «        ¦  «        }|                     |¦  «        }|                     |¦  «         t          | ¦  «        }t          j	        |v rt          j	        |v r|dz  }| 
                    |¦  «        }|                     |¦  «         |||fS )z5Transform a parent_map into SearchResult information.r   rF   )rS   Ú	itertoolsÚchainÚfrom_iterableÚvaluesÚ
differencerU   r:   r   rq   rV   )Ú
parent_mapÚmissing_keysÚ	start_setÚresult_parentsrM   r3   Úincluded_keyss          r   Úsearch_result_from_parent_mapr­   x  sÙ   € àð à�2�qˆyÐå�J‘”€Iå�œ×6Ò6°z×7HÒ7HÑ7JÔ7JÑKÔKÑLÔL€NØ×)Ò)¨)Ñ4Ô4€Ið ×Ò Ñ-Ô-Ð-Ý�J‘”€IÝÔ .Ð0Ð0ÝÔ&¨,Ð6Ð6ð
 	�Q‰ˆ	Ø×*Ò*¨>Ñ:Ô:€MØ×Ò Ñ.Ô.Ð.Ø�i Ð*Ð*r   c                 óF  — t          t          | ¦  «        ¦  «        }|                     |¦  «        }t          ¦   «         }	 	 t	          |¦  «        }n# t
          $ r Y nyw xY w|j                             ¦   «         D ].}|                     |¦  «        }|r| 	                    |¦  «         Œ/|                     |¦  «        }	|	r| 
                    |	¦  «         Œ–|j                             ¦   «         D ].}|                     |¦  «        }|r| 	                    |¦  «         Œ/||fS )a¨  Given a parent map, run a _BreadthFirstSearcher on it.

    Start at heads, walk until you hit exclude_keys. As a further improvement,
    watch for any heads that you encounter while walking, which means they were
    not heads of the search.

    This is mostly used to generate a succinct recipe for how to walk through
    most of parent_map.

    :return: (_BreadthFirstSearcher, set(heads_encountered_by_walking))
    )r   r   Ú_make_breadth_first_searcherrS   ÚnextÚStopIterationÚ_current_parentsr¦   rV   rT   Ústop_searching_any)
r¨   r_   r2   ÚgÚsÚfound_headsÚ	next_revsrp   Úf_headsrM   s
             r   Ú_run_searchr¹   ’  sI  € õ 	Õ! *Ñ-Ô-Ñ.Ô.€AØ	×&Ò& uÑ-Ô-€AÝ‘%”%€Kð,ð	Ý˜Q™œˆIˆIøÝð 	ð 	ð 	ØˆEð	øøøàÔ)×0Ò0Ñ2Ô2ð 	,ð 	,ˆGØ×(Ò(¨Ñ1Ô1ˆGØð ,Ø×"Ò" 7Ñ+Ô+Ð+øØ ×-Ò-¨iÑ8Ô8ˆ	Øð 	,Ø× Ò  Ñ+Ô+Ð+ð,ð Ô%×,Ò,Ñ.Ô.ð (ð (ˆØ×$Ò$ WÑ-Ô-ˆØð 	(Ø×Ò˜wÑ'Ô'Ð'øØˆkˆ>Ðs   ÁA Á
AÁAc                 ó´  — t          | ¦  «        }t          ¦   «         }|}t          |¦  «        }|r�|dk    rŠ|dz  }t          ¦   «         }|j        }|D ]9}		  |||	         ¦  «         Œ# t          $ r |                     |	¦  «         Y Œ6w xY w|                     |¦  «        }|                     |¦  «         |}|r|dk    °Š|r|                     |¦  «         |S )z”Walk backwards (towards children) through the parent_map.

    This finds 'heads' that will hopefully succinctly describe our search
    graph.
    r   rF   )r	   rS   rT   ÚKeyErrorÚaddr§   )
r¨   Útip_keysÚdepthÚ	child_mapr_   Úcurrent_rootsÚwalkedÚchildrenÚchildren_updateÚps
             r   Ú_find_possible_headsrÅ   ´  s  € õ " *Ñ-Ô-€IÝ‰EŒE€EØ€MÝ�ÑÔ€FØ
ð !˜E AšI˜IØ�‰
ˆÝ‘5”5ˆØ"œ/ˆØð 	ð 	ˆAðØ� 	¨!¤Ñ-Ô-Ð-Ð-øÝð ð ð Ø—	’	˜!‘”���ðøøøð ×&Ò& vÑ.Ô.ˆØ�Š�hÑÔÐØ ˆð# ð !˜E AšI˜Ið$ ð $à�Š�]Ñ#Ô#Ð#Ø€Ls   ÁA(Á(B
Â	B
c                 ó  — | sg g dfS t          | ||¦  «        }t          | |t          |¦  «        ¦  «        \  }}|                     ¦   «         \  }}}	|r"t          |¦  «                             |¦  «        }||t          |	¦  «        fS )an  Transform a parent_map that is searching 'tip_keys' into an
    approximate SearchResult.

    We should be able to generate a SearchResult from a given set of starting
    keys, that covers a subset of parent_map that has the last step pointing at
    tip_keys. This is to handle the case that really-long-searches shouldn't be
    started from scratch on each get_parent_map request, but we *do* want to
    filter out some of the keys that we've already seen, so we don't get
    information that we already know about on every request.

    The server will validate the search (that starting at start_keys and
    stopping at stop_keys yields the exact key_count), so we have to be careful
    to give an exact recipe.

    Basic algorithm is:
        1) Invert parent_map to get child_map (todo: have it cached and pass it
           in)
        2) Starting at tip_keys, walk towards children for 'depth' steps.
        3) At that point, we have the 'start' keys.
        4) Start walking parent_map from 'start' keys, counting how many keys
           are seen, and generating stop_keys for anything that would walk
           outside of the parent_map.

    :param parent_map: A map from {child_id: (parent_ids,)}
    :param missing_keys: parent_ids that we know are unavailable
    :param tip_keys: the revision_ids that we are searching
    :param depth: How far back to walk.
    r   )rÅ   r¹   rS   Ú	get_stater§   r:   )
r¨   r©   r½   r¾   r_   rµ   r¶   r1   r2   r4   s
             r   Ú%limited_search_result_from_parent_maprÈ   Ö  sŽ   € ð< ð à�2�qˆyÐÝ  ¨X°uÑ=Ô=€EÝ  ¨UµC¸±M´MÑBÔB�N€A€{Ø%&§[¢[¡]¤]Ñ"€J�˜dØð =õ ˜‘_”_×/Ò/°Ñ<Ô<ˆ
Ø�|¥S¨¡Y¤YÐ.Ð.r   )r$   r£   r†   r   r   r   rt   r   r   r	   r   r'   r+   r]   ry   r|   rŽ   r–   r­   r¹   rÅ   rÈ   r%   r   r   ú<module>rÉ      s:  ðð" 0Ð /à Ð Ð Ð ðð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð*/ð */ð */ð */ð */ñ */ô */ð */ðZ0ð 0ð 0ð 0ð 0ñ 0ô 0ð 0ð"b@ð b@ð b@ð b@ð b@Ð'ñ b@ô b@ð b@ðJICð ICð ICð ICð ICÐ0ñ ICô ICð ICðXð ð ð ð Ð,ñ ô ð ð"8ð "8ð "8ð "8ð "8Ð+ñ "8ô "8ð "8ðJ
:ð 
:ð 
:ð 
:ð 
:˜>ñ 
:ô 
:ð 
:ð+ð +ð +ð +ð +˜ñ +ô +ð +ð\+ð +ð +ð4ð ð ðDð ð ðD(/ð (/ð (/ð (/ð (/r   