HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/multiwalker.cpython-39.pyc
a

�*�^�.�@sDdZddlmZddlmZmZddlmZmZGdd�de	�Z
dS)	z$Walk multiple trees simultaneously.
�)�absolute_import�)�errors�osutils)�	text_type�
viewvaluesc@sleZdZdZdd�Zedd��Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�MultiWalkerz=Walk multiple trees simultaneously, getting combined results.cCs||_||_t�|_dS)aCCreate a new MultiWalker.

        All trees being walked must implement "iter_entries_by_dir()", such
        that they yield (path, object) tuples, where that object will have a
        '.file_id' member, that can be used to check equality.

        :param master_tree: All trees will be 'slaved' to the master_tree such
            that nodes in master_tree will be used as 'first-pass' sync points.
            Any nodes that aren't in master_tree will be merged in a second
            pass.
        :param other_trees: A list of other trees to walk simultaneously.
        N)�_master_tree�_other_trees�set�_out_of_order_processed)�selfZmaster_treeZother_trees�r�4/usr/lib/python3/dist-packages/breezy/multiwalker.py�__init__*s
zMultiWalker.__init__cCs4zt|�\}}Wnty$YdS0d||fSdS)z�Step an iter_entries_by_dir iterator.

        :return: (has_more, path, ie)
            If has_more is False, path and ie will be None.
        �FNNTN)�next�
StopIteration)�iterator�pathZierrr�	_step_one?s
zMultiWalker._step_onecCs\||krdSt|t�s*tdt|�|f��t|t�sHtdt|�|f��t�|�t�|�kS)a�Compare two paths based on what directory they are in.

        This generates a sort order, such that all children of a directory are
        sorted together, and grandchildren are in the same order as the
        children appear. But all grandchildren come after all children.

        :param path1: first path
        :param path2: the second path
        :return: negative number if ``path1`` comes first,
            0 if paths are equal
            and a positive number if ``path2`` sorts first
        Fz,'path1' must be a unicode string, not %s: %rz,'path2' must be a unicode string, not %s: %r)�
isinstancer�	TypeError�typer�_path_to_key)Zpath1Zpath2rrr�_lt_path_by_dirblockMs

�

��z MultiWalker._lt_path_by_dirblockcCst�|�\}}|�d�|fS)N�/)r�split)r�dirname�basenamerrrrjszMultiWalker._path_to_keycCs|�|||j�|��S)N)�_lookup_by_file_idr	Zpath2id)r
�
extra_entries�
other_treeZmaster_pathrrr�_lookup_by_master_pathos
�z"MultiWalker._lookup_by_master_pathcCst||vr|�|�Sz|�|�}Wntjy8d}Yn0|durFdS|j�|�t|j|gd��d}||fSdS)aLookup an inventory entry by file_id.

        This is called when an entry is missing in the normal order.
        Generally this is because a file was either renamed, or it was
        deleted/added. If the entry was found in the inventory and not in
        extra_entries, it will be added to self._out_of_order_processed

        :param extra_entries: A dictionary of {file_id: (path, ie)}.  This
            should be filled with entries that were found before they were
            used. If file_id is present, it will be removed from the
            dictionary.
        :param other_tree: The Tree to search, in case we didn't find the entry
            yet.
        :param file_id: The file_id to look for
        :return: (path, ie) if found or (None, None) if not present.
        N�NN)Zspecific_filesr)�popZid2pathrZNoSuchIdr�addr�iter_entries_by_dir)r
r!r"�file_idZcur_pathZcur_ierrrr ts

��zMultiWalker._lookup_by_file_idccs4|��D]
}|Vq|��|��D]
}|Vq$dS)z+Match up the values in the different trees.N)�_walk_master_tree�_finish_others�_walk_others)r
�resultrrr�iter_all�s
zMultiWalker.iter_allc#s��j��}dd��jD�}�fdd�|D�}dd�tt�j��D�}d}�j}�j}�j}|�r�||�\}}	}
|sv�q�g}|j}g}
|
j}t	|�D�]
\}\}}}|s�|��
||�j||	��|d�q�|
j|jkr�|||f�||||��q�||}||}|�rH��||	��rH|j}||v�r6||f||<||�\}}}�q|�rx|j|
jk�rx|||f�||�\}}}n|��
|�j||	��||||f�q�|
}|	|
j|
|fVqZ|�_
|�_|�_dS)z�First pass, walk all trees in lock-step.

        When we are done, all nodes in the master_tree will have been
        processed. _other_walkers, _other_entries, and _others_extra will be
        set on 'self' for future processing.
        cSsg|]}|���qSr)r')�.0�otherrrr�
<listcomp>�s�z1MultiWalker._walk_master_tree.<locals>.<listcomp>csg|]}��|��qSr)r)r.Zwalker�r
rrr0��cSsg|]}i�qSrr)r.�_rrrr0�r2TrN)r	r'r
�range�lenrr r�append�	enumerater#r(r�_other_walkers�_other_entries�
_others_extra)r
Zmaster_iteratorZ
other_walkersZ
other_entriesZothers_extraZmaster_has_moreZstep_oneZlookup_by_file_idZout_of_order_processedrZ	master_ie�other_valuesZother_values_appendZnext_other_entriesZnext_other_entries_append�idx�other_has_more�
other_path�other_ieZother_walker�other_extra�
other_file_idrr1rr)�sh

��

�
��
��zMultiWalker._walk_master_treecCsht|j�D]T\}}|j|}|\}}}|r
|j}||jvrF||f||<|�|j|�\}}}q&q
|`dS)z:Finish walking the other iterators, so we get all entries.N)r7r9r:r(rrr8)r
r<�infor@r=r>r?rArrrr*�s


�zMultiWalker._finish_othersc
#s�t�j�D]�\}}tt|��fdd�d�}|D]�\}}|j}|�|�dg|}|�||f�t�j|dd��D]<\}}	||d}�j|}	�j|}
|���|	|
|��qt||d|fVq.q
dS)z.Finish up by walking all the 'deferred' nodes.cs��|d�S)Nr)r)�xr1rr�<lambda>�r2z*MultiWalker._walk_others.<locals>.<lambda>)�keyr$rN)	r7r:�sortedrr(r%r6r
r )r
r<r@Zothersr>r?r(r;Zalt_idxZ	alt_extraZalt_treerr1rr+�s"
�



�zMultiWalker._walk_othersN)�__name__�
__module__�__qualname__�__doc__r�staticmethodrrrr#r r-r)r*r+rrrrr!s



K
rN)rJZ
__future__r�rrZsixishrr�objectrrrrr�<module>s