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__/tsort.cpython-39.pyc
a

�*�^:~�@sbdZddlmZddlmZmZmZgd�Z	dd�Z
Gdd	�d	e�Zddd
�Z
Gdd�de�Zd
S)zTopological sorting routines.�)�absolute_import�)�errors�graph�revision)�	topo_sort�
TopoSorter�
merge_sort�MergeSortercCst�t|��}|��S)a�Topological sort a graph.

    graph -- sequence of pairs of node->parents_list.

    The result is a list of node names, such that all parents come before their
    children.

    node identifiers can be any hashable object, and are typically strings.

    This function has the same purpose as the TopoSorter class, but uses a
    different algorithm to sort the graph. That means that while both return a
    list with parents before their child nodes, the exact ordering can be
    different.

    topo_sort is faster when the whole list is needed, while when iterating
    over a part of the list, TopoSorter.iter_topo_order should be used.
    )�
_mod_graphZ
KnownGraph�dictr)rZkg�r
�./usr/lib/python3/dist-packages/breezy/tsort.pyr src@s$eZdZdd�Zdd�Zdd�ZdS)rcCst|�|_dS)aTopological sorting of a graph.

        :param graph: sequence of pairs of node_name->parent_names_list.
                      i.e. [('C', ['B']), ('B', ['A']), ('A', [])]
                      For this input the output from the sort or
                      iter_topo_order routines will be:
                      'A', 'B', 'C'

        node identifiers can be any hashable object, and are typically strings.

        If you have a graph like [('a', ['b']), ('a', ['c'])] this will only use
        one of the two values for 'a'.

        The graph is sorted lazily: until you iterate or sort the input is
        not processed other than to create an internal representation.

        iteration or sorting may raise GraphCycleError if a cycle is present
        in the graph.
        N)r�_graph)�selfrr
r
r�__init__8szTopoSorter.__init__cCst|���S�z|Sort the graph and return as a list.

        After calling this the sorter is empty and you must create a new one.
        ��list�iter_topo_order�rr
r
r�sortedOszTopoSorter.sortedccs�|j}t|�}g}g}t�}|r�|��\}}|�|�|�t|��|r|d}|sv|��}	|��|�|	�|	VqD|��}
|
|vr�qD|
|vr�qDz|�|
�}Wnty�t�	|��Yn0|�|
�|�t|��qDqdS)��Yield the nodes of the graph in a topological order.

        After finishing iteration the sorter is empty and you cannot continue
        iteration.
        ���N)
r�set�popitem�appendr�pop�add�KeyErrorr�GraphCycleError)rrZ	visitableZpending_node_stack�pending_parents_stack�completed_node_names�	node_name�parents�parents_to_visitZpopped_node�next_node_namer
r
rr`s6


zTopoSorter.iter_topo_orderN)�__name__�
__module__�__qualname__rrrr
r
r
rr6srNFcCst||||���S)a�Topological sort a graph which groups merges.

    :param graph: sequence of pairs of node->parents_list.
    :param branch_tip: the tip of the branch to graph. Revisions not
                       reachable from branch_tip are not included in the
                       output.
    :param mainline_revisions: If not None this forces a mainline to be
                               used rather than synthesised from the graph.
                               This must be a valid path through some part
                               of the graph. If the mainline does not cover all
                               the revisions, output stops at the start of the
                               old revision listed in the mainline revisions
                               list.
                               The order for this parameter is oldest-first.
    :param generate_revno: Optional parameter controlling the generation of
        revision number sequences in the output. See the output description of
        the MergeSorter docstring for details.
    :result: See the MergeSorter docstring for details.

    Node identifiers can be any hashable object, and are typically strings.
    )r
r)r�
branch_tip�mainline_revisions�generate_revnor
r
rr	�s�r	c@s>eZdZgd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)r
)�_node_name_stack�_node_merge_depth_stack�_pending_parents_stack�_first_child_stack�_left_subtree_pushed_stack�_generate_revnor�_mainline_revisions�_stop_revision�_original_graph�_revnos�_revno_to_branch_count�_completed_node_names�_scheduled_nodesNFc
CsB||_t|�|_|dur&g|_d|_nt|�|_|jd|_t|jdd��D]\\}}|j|}|durjqN|j|}|szqN|d|kr�qN|j|�|�|j|�d|�qN|j�	�|_
tdd�|jD��|_i|_g|_
g|_g|_g|_t�|_g|_g|_|du�r>|tjk�r>|tjfk�r>|j�|�}	|�|d|	�dS)aNMerge-aware topological sorting of a graph.

        :param graph: sequence of pairs of node_name->parent_names_list.
                      i.e. [('C', ['B']), ('B', ['A']), ('A', [])]
                      For this input the output from the sort or
                      iter_topo_order routines will be:
                      'A', 'B', 'C'
        :param branch_tip: the tip of the branch to graph. Revisions not
                       reachable from branch_tip are not included in the
                       output.
        :param mainline_revisions: If not None this forces a mainline to be
                               used rather than synthesised from the graph.
                               This must be a valid path through some part
                               of the graph. If the mainline does not cover all
                               the revisions, output stops at the start of the
                               old revision listed in the mainline revisions
                               list.
                               The order for this parameter is oldest-first.
        :param generate_revno: Optional parameter controlling the generation of
            revision number sequences in the output. See the output description
            for more details.

        The result is a list sorted so that all parents come before
        their children. Each element of the list is a tuple containing:
        (sequence_number, node_name, merge_depth, end_of_merge)
         * sequence_number: The sequence of this row in the output. Useful for
           GUIs.
         * node_name: The node name: opaque text to the merge routine.
         * merge_depth: How many levels of merging deep this node has been
           found.
         * revno_sequence: When requested this field provides a sequence of
             revision numbers for all revisions. The format is:
             (REVNO, BRANCHNUM, BRANCHREVNO). BRANCHNUM is the number of the
             branch that the revno is on. From left to right the REVNO numbers
             are the sequence numbers within that branch of the revision.
             For instance, the graph {A:[], B:['A'], C:['A', 'B']} will get
             the following revno_sequences assigned: A:(1,), B:(1,1,1), C:(2,).
             This should be read as 'A is the first commit in the trunk',
             'B is the first commit on the first branch made from A', 'C is the
             second commit in the trunk'.
         * end_of_merge: When True the next node is part of a different merge.


        node identifiers can be any hashable object, and are typically strings.

        If you have a graph like [('a', ['b']), ('a', ['c'])] this will only use
        one of the two values for 'a'.

        The graph is sorted lazily: until you iterate or sort the input is
        not processed other than to create an internal representation.

        iteration or sorting may raise GraphCycleError if a cycle is present
        in the graph.

        Background information on the design:
        -------------------------------------
        definition: the end of any cluster or 'merge' occurs when:
            1 - the next revision has a lower merge depth than we do.
              i.e.
              A 0
              B  1
              C   2
              D  1
              E 0
              C, D are the ends of clusters, E might be but we need more data.
            2 - or the next revision at our merge depth is not our left most
              ancestor.
              This is required to handle multiple-merges in one commit.
              i.e.
              A 0    [F, B, E]
              B  1   [D, C]
              C   2  [D]
              D  1   [F]
              E  1   [F]
              F 0
              C is the end of a cluster due to rule 1.
              D is not the end of a cluster from rule 1, but is from rule 2: E
                is not its left most ancestor
              E is the end of a cluster due to rule 1
              F might be but we need more data.

        we show connecting lines to a parent when:
         - The parent is the start of a merge within this cluster.
           That is, the merge was not done to the mainline before this cluster
           was merged to the mainline.
           This can be detected thus:
            * The parent has a higher merge depth and is the next revision in
              the list.

          The next revision in the list constraint is needed for this case:
          A 0   [D, B]
          B  1  [C, F]   # we do not want to show a line to F which is depth 2
                           but not a merge
          C  1  [H]      # note that this is a long line to show back to the
                           ancestor - see the end of merge rules.
          D 0   [G, E]
          E  1  [G, F]
          F   2 [G]
          G  1  [H]
          H 0
         - Part of this merges 'branch':
          The parent has the same merge depth and is our left most parent and we
           are not the end of the cluster.
          A 0   [C, B] lines: [B, C]
          B  1  [E, C] lines: [C]
          C 0   [D]    lines: [D]
          D 0   [F, E] lines: [E, F]
          E  1  [F]    lines: [F]
          F 0
         - The end of this merge/cluster:
          we can ONLY have multiple parents at the end of a cluster if this
          branch was previously merged into the 'mainline'.
          - if we have one and only one parent, show it
            Note that this may be to a greater merge depth - for instance if
            this branch continued from a deeply nested branch to add something
            to it.
          - if we have more than one parent - show the second oldest (older ==
            further down the list) parent with
            an equal or lower merge depth
             XXXX revisit when awake. ddaa asks about the relevance of each one
             - maybe more than one parent is relevant
        Nrrcss|]}|ddgfVqdS)NTr
)�.0rr
r
r�	<genexpr>vs�z'MergeSorter.__init__.<locals>.<genexpr>)r2rrr3r4r�	enumerate�remove�insert�copyr5r6r7r-r.r/r0rr8r9r1�
_mod_revisionZ
NULL_REVISIONr�
_push_node)
rrr*r+r,�indexr�parentZgraph_parent_idsr$r
r
rr�sJ|



�


�
�zMergeSorter.__init__cCst|���Srrrr
r
rr�szMergeSorter.sortedc
cs|j}|j}|j}|j}|j}|j}|jj}|j|j|j|j|j	j|j
fdd�}|j|j|j	j|j|j|j|j
|jj|j|j
f
dd�}	|�rV|d}
|
s�|	�q�|dr�|ds�|d�d�}d}d|d<n|d��}d}||vr�q�z||�}
Wn0t�y"||jv�rt�|��nYq�Yn0d}|�r4d}nd	}|d|}||||
�q�q�q�d}|j}|j}|j}|�r|��\}}}||k�r�d
St|��s�d}nJ|dd	|k�r�d}n2|dd	|k�r�|dd||v�r�d}nd}|�r|||||fVn||||fV|d	7}�qld
S)rc	Ssz||�||�|d�|t|��d}	|rPz||d}	WntyNYn0|	durj|	d}
d|	d<nd}
||
�dS)aAdd node_name to the pending node stack.

            Names in this stack will get emitted into the output as they are popped
            off the stack.

            This inlines a lot of self._variable.append functions as local
            variables.
            FNrr)rr)r#�merge_depthr$Znode_name_stack_appendZnode_merge_depth_stack_appendZ left_subtree_pushed_stack_appendZpending_parents_stack_appendZfirst_child_stack_append�revnos�parent_info�first_childr
r
r�	push_node�s
z.MergeSorter.iter_topo_order.<locals>.push_nodec
Ss|�}
|�}|�}|�|�||
}
d}|
rVz||
dd}WntyTYn0|dur�|s�|d}|	�|d�}|d7}||	|<|d|df}q�|dd�|ddf}n0|	�dd�}|d7}|r�d|df}nd}||	d<|||
d<||
�||
||f�|
S)zcPop the top node off the stack

            The node is appended to the sorted output.
            Nrrr�r)r�get)Znode_name_stack_popZnode_merge_depth_stack_popZfirst_child_stack_popZleft_subtree_pushed_stack_popZpending_parents_stack_pop�original_graphrEZcompleted_node_names_addZscheduled_nodes_appendZrevno_to_branch_countr#rDrGr$�parent_revno�
base_revno�branch_count�revno�
root_countr
r
r�pop_node�s<z-MergeSorter.iter_topo_order.<locals>.pop_noderrTFrN)r-r.r/r1r8r9rrrr0r6r5rr7rrr r4r2�len)rZnode_name_stackZnode_merge_depth_stackr!Zleft_subtree_pushed_stackr"Zscheduled_nodesZ	graph_poprHrQr%r&Zis_left_subtreer$Znext_merge_depthZsequence_numberZ
stop_revisionr,rKr#rDrOZend_of_merger
r
rr�s��
&�
>
	

��


��zMergeSorter.iter_topo_ordercCs�|j�|�|j�|�|j�d�|j�t|��d}|rbz|j|d}Wnty`Yn0|dur||d}d|d<nd}|j�|�dS)z�Add node_name to the pending node stack.

        Names in this stack will get emitted into the output as they are popped
        off the stack.
        FNrr)	r-rr.r1r/rr6rr0)rr#rDr$rFrGr
r
rrAys
zMergeSorter._push_nodec
CsL|j��}|j��}|j��}|j��|j��|j|}d}|rnz|j|dd}WntylYn0|dur�|s�|d}|j	�
|d�}|d7}||j	|<|d|df}n|dd�|ddf}nD|j	�
dd�}	|j	�
dd�}	|	d7}	|	�rd|	df}nd}|	|j	d<||j|d<|j�|�|j
�|||j|df�|S)z[Pop the top node off the stack

        The node is appended to the sorted output.
        NrrrrI)r-rr.r0r1r/r5r6rr7rJr8rr9r)
rr#rDrGr$rLrMrNrOrPr
r
r�	_pop_node�sB







�zMergeSorter._pop_node)NF)	r'r(r)�	__slots__rrrrArSr
r
r
rr
�s�
VPr
)NF)�__doc__Z
__future__r�rrrrr@�__all__r�objectrr	r
r
r
r
r�<module>sl