§
    cÌc 4  ã                   ó<   — d Z ddlmZmZmZmZ  G d„ d¦  «        ZdS )z8Functionality for doing annotations in the 'optimal' wayé   )ÚerrorsÚgraphÚosutilsÚuic                   óh   — e Zd ZdZd„ Zd„ Zd„ Zdd„Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )Ú	Annotatorz)Class that drives performing annotations.c                 óh   — || _         i | _        i | _        i | _        i | _        d| _        i | _        dS )z,Create a new Annotator from a VersionedFile.N)Ú_vfÚ_parent_mapÚ_text_cacheÚ_num_needed_childrenÚ_annotations_cacheÚ_heads_providerÚ_ann_tuple_cache)ÚselfÚvfs     ú6/usr/lib/python3/dist-packages/breezy/_annotator_py.pyÚ__init__zAnnotator.__init__   s?   € àˆŒØˆÔØˆÔà$&ˆÔ!Ø"$ˆÔØ#ˆÔØ "ˆÔÐÐó    c                 ób   — |D ]+}|| j         v r| j         |xx         dz  cc<   Œ!d| j         |<   Œ,d S )Nr   )r   )r   ÚkeyÚparent_keysÚ
parent_keys       r   Ú_update_needed_childrenz!Annotator._update_needed_children)   s[   € Ø%ð 	:ð 	:ˆJØ˜TÔ6Ð6Ð6ØÔ)¨*Ð5Ð5Ô5¸Ñ:Ð5Ð5Ñ5Ð5à89�Ô)¨*Ñ5Ð5ð		:ð 	:r   c                 óî  ‡— | j         Šd| j        |<   t          ¦   «         }t          ¦   «         }|h}|�r>g }i }|D ]ƒ}|| j         v rN|| j        vr|                     |¦  «         Œ*|| j        vr%|                     |¦  «         | j         |         ||<   ŒY|                     |¦  «         |                     |¦  «         Œ„t          ¦   «         }|                     | j         	                    |¦  «        ¦  «         | 
                    ¦   «         D ]E\  }}|€d}d||<   |                      ||¦  «         |                     ˆfd„|D ¦   «         ¦  «         ŒF‰                     |¦  «         d| _        |�°>||fS )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.
        r   N© c                 ó   •— g | ]}|‰v¯|‘Œ	S r   r   )Ú.0r   Ú
parent_maps     €r   ú
<listcomp>z.Annotator._get_needed_keys.<locals>.<listcomp>X   s-   ø€ ð $>ð $>ð $>¨CØ'*°*Ð'<Ð'<ð %(Ø'<Ð'<Ð'<r   )r   r   Úsetr   Úaddr   ÚappendÚupdater
   Úget_parent_mapÚitemsr   r   )	r   r   Úvf_keys_neededÚann_keys_neededÚneeded_keysÚparent_lookupÚnext_parent_mapr   r   s	           @r   Ú_get_needed_keyszAnnotator._get_needed_keys0   sØ  ø€ ð Ô%ˆ
ð *+ˆÔ! #Ñ&Ý™œˆÝ™%œ%ˆØ�eˆØñ 	(ØˆMØ ˆOØ"ð ,ð ,�Ø˜$Ô*Ð*Ð*à $Ô"2Ð2Ð2à&×*Ò*¨3Ñ/Ô/Ð/Ð/Ø DÔ$;Ð;Ð;à'×+Ò+¨CÑ0Ô0Ð0Ø/3Ô/?ÀÔ/D˜¨Ñ,øà!×(Ò(¨Ñ-Ô-Ð-Ø"×&Ò& sÑ+Ô+Ð+Ð+Ý™%œ%ˆKØ×"Ò" 4¤8×#:Ò#:¸=Ñ#IÔ#IÑJÔJÐJØ$3×$9Ò$9Ñ$;Ô$;ð ?ð ?Ñ ��[ØÐ&Ø"$�KØ+-�O CÑ(Ø×,Ò,¨S°+Ñ>Ô>Ð>Ø×"Ò"ð $>ð $>ð $>ð $>°;ð $>ñ $>ô $>ñ ?ô ?ð ?ð ?à×Ò˜oÑ.Ô.Ð.ð $(ˆDÔ ð9 ñ 	(ð: ˜Ð.Ð.r   Nc              #   óP  K  — |                       |¦  «        \  }}|�$|                     ddt          |¦  «        ¦  «         | j                             |dd¦  «        }t          |¦  «        D ]‘\  }}|�$|                     ddt          |¦  «        ¦  «         |j        dk    rt          j        |j	        | j        ¦  «        ‚|j	        }| 
                    d¦  «        }	t          |	¦  «        }
|	| j        |<   ||	|
fV — Œ’|D ]%}| j        |         }	t          |	¦  «        }
||	|
fV — Œ&dS )	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.
        Nzgetting streamé    ÚtopologicalTÚ
extractingÚabsentÚlines)r,   r$   Úlenr
   Úget_record_streamÚ	enumerateÚstorage_kindr   ÚRevisionNotPresentr   Úget_bytes_asr   )r   r   ÚpbÚkeysÚann_keysÚstreamÚidxÚrecordÚthis_keyr2   Ú	num_liness              r   Ú_get_needed_textszAnnotator._get_needed_texts`   sJ  è è € ð ×.Ò.¨sÑ3Ô3‰ˆˆhØˆ>Ø�IŠIÐ&¨­3¨t©9¬9Ñ5Ô5Ð5Ø”×+Ò+¨D°-ÀÑFÔFˆÝ$ VÑ,Ô,ð 		-ð 		-‰KˆC�Øˆ~Ø—	’	˜,¨­3¨t©9¬9Ñ5Ô5Ð5ØÔ" hÒ.Ð.ÝÔ/°´
¸D¼HÑEÔEÐEØ”zˆHØ×'Ò'¨Ñ0Ô0ˆEÝ˜E™
œ
ˆIØ).ˆDÔ˜XÑ&Ø˜E 9Ð,Ð,Ð,Ð,Ð,Øð 	(ð 	(ˆCØÔ$ SÔ)ˆEÝ˜E™
œ
ˆIØ�u˜iÐ'Ð'Ð'Ð'Ð'ð	(ð 	(r   c                 óŒ   — | j         |         }| j        |         }ddlm}  |d||¦  «        }|                     ¦   «         }||fS )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
        r.   )ÚPatienceSequenceMatcherN)r   r   ÚpatiencediffrC   Úget_matching_blocks)	r   r   Útextr   Úparent_linesÚparent_annotationsrC   ÚmatcherÚmatching_blockss	            r   Ú#_get_parent_annotations_and_matchesz-Annotator._get_parent_annotations_and_matches|   sf   € ð Ô'¨
Ô3ˆØ!Ô4°ZÔ@Ðà8Ð8Ð8Ð8Ð8Ð8Ø)Ð)Ø�, ñ&ô &ˆà!×5Ò5Ñ7Ô7ˆØ! ?Ð2Ð2r   c                 óv   — |                       |||¦  «        \  }}|D ]\  }}}	||||	z   …         ||||	z   …<   ŒdS )z2Reannotate this text relative to its first parent.N)rK   )
r   r   Úannotationsr2   r   rH   rJ   Ú
parent_idxÚ	lines_idxÚ	match_lens
             r   Ú_update_from_first_parentz#Annotator._update_from_first_parent�   s{   € ð !×DÒDØ�%˜ñ%ô %ñ	Ð	Ø	ð 1@ð 	Fð 	FÑ,ˆJ˜	 9ð # :¨j¸9Ñ.DÐ#DÔEð ˜	 )¨iÑ"7Ð7Ñ8Ð8ð	Fð 	Fr   c                 óÈ  — |                       |||¦  «        \  }}d}d}	d}
|D ]¾\  }}}||||z   …         }||||z   …         }||k    rŒ't          |¦  «        D ]‡}||         }||         }||z   }||k    rŒ||k    r|||<   Œ*||k    r||	k    r|
||<   Œ<t          |¦  «        }|                     |¦  «         t	          t          |¦  «        ¦  «        }|||<   |}|}	|}
ŒˆŒ¿dS )z;Reannotate this text relative to a second (or more) parent.N)rK   Úranger!   r$   ÚtupleÚsorted)r   r   rM   r2   Úthis_annotationr   rH   rJ   Úlast_annÚlast_parentÚlast_resrN   rO   rP   Úann_subÚpar_subr=   ÚannÚpar_annÚann_idxÚnew_anns                        r   Ú_update_from_other_parentsz$Annotator._update_from_other_parents›   s_  € ð !×DÒDØ�%˜ñ%ô %ñ	Ð	Ø	ð ˆØˆØˆð 1@ð 	'ð 	'Ñ,ˆJ˜	 9ð " )¨I¸	Ñ,AÐ"AÔBˆGØ(¨°JÀÑ4JÐ)JÔKˆGØ˜'Ò!Ð!ØÝ˜YÑ'Ô'ð 'ð '�Ø˜c”l�Ø! #œ,�Ø# c™/�Ø˜'’>�>àØ˜/Ò)Ð)ð ,3�K Ñ(Øð ˜(’?�? w°+Ò'=Ð'=Ø+3�K Ñ(Ð(å! #™hœh�GØ—N’N 7Ñ+Ô+Ð+Ý#¥F¨7¡O¤OÑ4Ô4�GØ+2�K Ñ(Ø"�HØ")�KØ&�H�Hð/'ð	'ð 	'r   c                 óˆ   — || j         |<   |D ]4}| j        |         }|dz  }|dk    r| j        |= | j         |= || j        |<   Œ5d S )Nr   r.   )r   r   r   )r   r   r   rM   r   Únums         r   Ú_record_annotationzAnnotator._record_annotationË   so   € Ø'2ˆÔ Ñ$Ø%ð 	8ð 	8ˆJØÔ+¨JÔ7ˆCØ�1‰HˆCØ�aŠxˆxØÔ$ ZÐ0ØÔ+¨JÐ7ð 58ˆDÔ% jÑ1Ð1ð	8ð 	8r   c                 óì   — |f}|g|z  }| j         |         }|rD|                      ||||d         ¦  «         |dd …         D ]}|                      |||||¦  «         Œ|                      |||¦  «         d S )Nr.   r   )r   rQ   r`   rc   )r   r   rF   r@   rV   rM   r   Úparents           r   Ú_annotate_onezAnnotator._annotate_one×   s´   € Ø˜&ˆà&Ð'¨)Ñ3ˆØÔ& sÔ+ˆØð 	IØ×*Ò*¨3°¸TØ+6°q¬>ñ;ô ;ð ;à% a b bœ/ð Ið I�Ø×/Ò/°°[À$Ø0?ÀñIô Ið Ið Ià×Ò  [°+Ñ>Ô>Ð>Ð>Ð>r   c                 ó`   — || j         |<   t          j        |¦  «        | j        |<   d| _        dS )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   r   Úsplit_linesr   r   )r   r   r   rF   s       r   Úadd_special_textzAnnotator.add_special_textä   s7   € ð !,ˆÔ˜ÑÝ 'Ô 3°DÑ 9Ô 9ˆÔ˜ÑØ#ˆÔÐÐr   c                 óp  — t           j                             ¦   «         5 }|                      ||¬¦  «        D ]\  }}}|                      |||¦  «         Œ	 ddd¦  «         n# 1 swxY w Y   	 | j        |         }n-# t          $ r }t          j        || j	        ¦  «        |‚d}~ww xY w|| j
        |         fS )ak  Return 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
        )r9   N)r   Ú
ui_factoryÚnested_progress_barrA   rf   r   ÚKeyErrorr   r7   r
   r   )r   r   r9   Útext_keyrF   r@   rM   Úexcs           r   ÚannotatezAnnotator.annotateó   s  € õ Œ]×.Ò.Ñ0Ô0ð 	>°BØ-1×-CÒ-CØ˜Bð .Dñ . ô . ð >ð >Ñ)�˜$ 	à×"Ò" 8¨T°9Ñ=Ô=Ð=Ð=ð>ð	>ð 	>ð 	>ñ 	>ô 	>ð 	>ð 	>ð 	>ð 	>ð 	>ð 	>øøøð 	>ð 	>ð 	>ð 	>ð	DØÔ1°#Ô6ˆKˆKøÝð 	Dð 	Dð 	DÝÔ+¨C°´Ñ:Ô:ÀÐCøøøøð	Døøøà˜DÔ,¨SÔ1Ð1Ð1s)   Ÿ6A"Á"A&Á)A&Á.A< Á<
B&ÂB!Â!B&c                 óZ   — | j         €t          j        | j        ¦  «        | _         | j         S ©N)r   Ú
_mod_graphÚ
KnownGraphr   )r   s    r   Ú_get_heads_providerzAnnotator._get_heads_provider  s*   € ØÔÐ'Ý#-Ô#8¸Ô9IÑ#JÔ#JˆDÔ ØÔ#Ð#r   c                 ó®   — |€t          |¦  «        d         }n<t          |¦  «        }t          |¦  «        }|D ]}||f||ff} ||¦  «        d         }Œ|S )Nr.   )rU   ÚiterÚnext)r   Ú	the_headsÚlineÚ
tiebreakerÚheadÚ	next_headÚpossible_headÚannotated_liness           r   Ú_resolve_annotation_tiez!Annotator._resolve_annotation_tie  sq   € ØÐÝ˜)Ñ$Ô$ QÔ'ˆDˆDõ ˜Y™œˆIÝ˜	‘?”?ˆDØ!*ð 6ð 6�Ø$(¨$ <°-ÀÐ1FÐ"G�Ø!�z /Ñ2Ô2°1Ô5��Øˆr   c                 ó~  — ddl m} |}|                       |¦  «        \  }}g }|                      ¦   «         j        }|j        }t          ||¦  «        D ]i\  }	}
t          |	¦  «        dk    r	|	d         }n; ||	¦  «        }t          |¦  «        dk    r|D ]} n|                      ||
|¦  «        } |||
f¦  «         Œj|S )a   Determine 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.
        r   )Ú_break_annotation_tier.   )rp   r‚   ru   Úheadsr#   Úzipr3   r€   )r   r   r‚   Úcustom_tiebreakerrM   r2   Úoutrƒ   r#   Ú
annotationrz   r|   ry   s                r   Úannotate_flatzAnnotator.annotate_flat  sù   € ð 	4Ð3Ð3Ð3Ð3Ð3Ø1ÐØ!Ÿ]š]¨3Ñ/Ô/Ñˆ�UØˆØ×(Ò(Ñ*Ô*Ô0ˆØ”ˆÝ # K°Ñ 7Ô 7ð 	!ð 	!ÑˆJ˜Ý�:‰Œ !Ò#Ð#Ø! !”}��à!˜E *Ñ-Ô-�	Ý�y‘>”> QÒ&Ð&Ø )ð ð ˜Øøà×7Ò7¸	À4Ø8IñKô K�DàˆF�D˜$�<Ñ Ô Ð Ð Øˆ
r   rr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r,   rA   rK   rQ   r`   rc   rf   ri   rp   ru   r€   rˆ   r   r   r   r   r      sö   € € € € € Ø3Ð3ð	#ð 	#ð 	#ð:ð :ð :ð./ð ./ð ./ð`(ð (ð (ð (ð83ð 3ð 3ð(	Fð 	Fð 	Fð.'ð .'ð .'ð`
8ð 
8ð 
8ð?ð ?ð ?ð$ð $ð $ð2ð 2ð 2ð&$ð $ð $ð
ð ð ðð ð ð ð r   r   N)rŒ   Ú r   r   rs   r   r   r   r   r   r   ú<module>rŽ      s…   ðð" ?Ð >ðð ð ð ð ð ð ð ð ð ð ð ðVð Vð Vð Vð Vñ Vô Vð Vð Vð Vr   