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

�*�^Q5�@s`dZddlmZddlmZee�d�ddlmZmZmZddl	m
Z
mZGdd	�d	e�Z
d
S)z8Functionality for doing annotations in the 'optimal' way�)�absolute_import�)�lazy_importz�

import patiencediff

from breezy import (
    annotate, # Must be lazy to avoid circular importing
    graph as _mod_graph,
    )
)�errors�osutils�ui)�range�	viewitemsc@s�eZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �	Annotatorz)Class that drives performing annotations.cCs.||_i|_i|_i|_i|_d|_i|_dS)z,Create a new Annotator from a VersionedFile.N)�_vf�_parent_map�_text_cache�_num_needed_children�_annotations_cache�_heads_providerZ_ann_tuple_cache)�selfZvf�r�6/usr/lib/python3/dist-packages/breezy/_annotator_py.py�__init__-szAnnotator.__init__cCs6|D],}||jvr&|j|d7<qd|j|<qdS)Nr)r)r�key�parent_keys�
parent_keyrrr�_update_needed_children8s
z!Annotator._update_needed_childrencs|j�d|j|<t�}t�}|h}|�rg}i}|D]\}||jvr|||jvrX|�|�q�||jvr�|�|�|j|||<q4|�|�|�|�q4t�}|�|j�	|��t
|�D]@\}}|dur�d}d||<|�||�|��fdd�|D��q���|�d|_q"||fS)a�Determine the texts we need to get from the backing vf.

        :return: (vf_keys_needed, ann_keys_needed)
            vf_keys_needed  These are keys that we need to get from the vf
            ann_keys_needed Texts which we have in self._text_cache but we
                            don't have annotations for. We need to yield these
                            in the proper order so that we can get proper
                            annotations.
        rNrcsg|]}|�vr|�qSrr)�.0r�Z
parent_maprr�
<listcomp>gs�z.Annotator._get_needed_keys.<locals>.<listcomp>)
rr�setr
�addr�append�updaterZget_parent_mapr	rr)rrZvf_keys_neededZann_keys_neededZneeded_keysZ
parent_lookupZnext_parent_maprrrr�_get_needed_keys?s8







zAnnotator._get_needed_keysNccs�|�|�\}}|dur(|�ddt|��|j�|dd�}t|�D]j\}}|durb|�ddt|��|jdkr|t�|j	|j��|j	}|�
d�}	t|	�}
|	|j|<||	|
fVq@|D]"}|j|}	t|	�}
||	|
fVq�dS)	a�Get the texts we need to properly annotate key.

        :param key: A Key that is present in self._vf
        :return: Yield (this_key, text, num_lines)
            'text' is an opaque object that just has to work with whatever
            matcher object we are using. Currently it is always 'lines' but
            future improvements may change this to a simple text string.
        Nzgetting streamrZtopologicalTZ
extractingZabsent�lines)r r�lenrZget_record_stream�	enumerateZstorage_kindr�RevisionNotPresentrZget_bytes_asr
)rr�pb�keysZann_keys�stream�idx�recordZthis_keyr!�	num_linesrrr�_get_needed_textsos$	



zAnnotator._get_needed_textscCs2|j|}|j|}t�d||�}|��}||fS)a�Get the list of annotations for the parent, and the matching lines.

        :param text: The opaque value given by _get_needed_texts
        :param parent_key: The key for the parent text
        :return: (parent_annotations, matching_blocks)
            parent_annotations is a list as long as the number of lines in
                parent
            matching_blocks is a list of (parent_idx, text_idx, len) tuples
                indicating which lines match between the two texts
        N)r
rZpatiencediffZPatienceSequenceMatcherZget_matching_blocks)rr�textrZparent_lines�parent_annotationsZmatcher�matching_blocksrrr�#_get_parent_annotations_and_matches�s

�z-Annotator._get_parent_annotations_and_matchesc
CsB|�|||�\}}|D]&\}}}	||||	�||||	�<qdS)z2Reannotate this text relative to its first parent.N)r/)
rr�annotationsr!rr-r.�
parent_idx�	lines_idx�	match_lenrrr�_update_from_first_parent�s���z#Annotator._update_from_first_parentcCs�|�|||�\}}d}d}	d}
|D]�\}}}
||||
�}||||
�}||krVq"t|
�D]�}||}||}||}||kr�q^||kr�|||<q^||kr�||	kr�|
||<q^t|�}|�|�tt|��}|||<|}|}	|}
q^q"dS)z;Reannotate this text relative to a second (or more) parent.N)r/rrr�tuple�sorted)rrr0r!�this_annotationrr-r.Zlast_annZlast_parentZlast_resr1r2r3Zann_subZpar_subr(�annZpar_annZann_idxZnew_annrrr�_update_from_other_parents�s>��

z$Annotator._update_from_other_parentscCsL||j|<|D]8}|j|}|d8}|dkr<|j|=|j|=||j|<qdS)Nrr)rrr
)rrrr0rZnumrrr�_record_annotation�s

zAnnotator._record_annotationcCsh|f}|g|}|j|}|rV|�||||d�|dd�D]}|�|||||�q>|�|||�dS)Nrr)rr4r9r:)rrr,r*r7r0r�parentrrr�
_annotate_one�s


�
�zAnnotator._annotate_onecCs$||j|<t�|�|j|<d|_dS)a�Add a specific text to the graph.

        This is used to add a text which is not otherwise present in the
        versioned file. (eg. a WorkingTree injecting 'current:' into the
        graph to annotate the edited content.)

        :param key: The key to use to request this text be annotated
        :param parent_keys: The parents of this text
        :param text: A string containing the content of the text
        N)rrZsplit_linesr
r)rrrr,rrr�add_special_text�s
zAnnotator.add_special_textcCs�tj���8}|j||d�D]\}}}|�|||�qWd�n1sH0Yz|j|}Wn ty�t�||j	��Yn0||j
|fS)akReturn annotated fulltext for the given key.

        :param key: A tuple defining the text to annotate
        :return: ([annotations], [lines])
            annotations is a list of tuples of keys, one for each line in lines
                        each key is a possible source for the given line.
            lines the text of "key" as a list of lines
        )r%N)rZ
ui_factoryZnested_progress_barr+r<r�KeyErrorrr$rr
)rrr%Ztext_keyr,r*r0rrr�annotates	�.zAnnotator.annotatecCs|jdurt�|j�|_|jS)N)rZ
_mod_graphZ
KnownGraphr)rrrr�_get_heads_providers
zAnnotator._get_heads_providercCsP|durt|�d}n6t|�}t|�}|D] }||f||ff}||�d}q*|S)Nr)r6�iter�next)r�	the_heads�lineZ
tiebreaker�headZ	next_headZ
possible_headZannotated_linesrrr�_resolve_annotation_tiesz!Annotator._resolve_annotation_tiecCs�tj}|�|�\}}g}|��j}|j}t||�D]\\}}	t|�dkrP|d}
n2||�}t|�dkrt|D]}
q�qhn|�||	|�}
||
|	f�q2|S)aDetermine the single-best-revision to source for each line.

        This is meant as a compatibility thunk to how annotate() used to work.
        :return: [(ann_key, line)]
            A list of tuples with a single annotation key for each line.
        rr)r?Z_break_annotation_tier@�headsr�zipr"rF)rrZcustom_tiebreakerr0r!�outrGr�
annotationrDrErCrrr�
annotate_flat&s"

�zAnnotator.annotate_flat)N)�__name__�
__module__�__qualname__�__doc__rrr r+r/r4r9r:r<r=r?r@rFrKrrrrr
*s0
0

r
N)rOZ
__future__rr�globals�rrrZsixishrr	�objectr
rrrr�<module>s