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

�*�^v*�@s`ddlmZddlmZmZmZddlmZddlm	Z	m
Z
mZddlm
Z
Gdd�de�Zd	S)
�)�absolute_import�)�osutils�progress�trace)�gettext)�BytesIO�	viewitems�
viewvalues)�
ui_factoryc@s�eZdZdZdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zedd��Zdd�Z
dd�Zdd�Zeddd��Zdd�ZdS)�	RenameMapzDetermine a mapping of renames.cCs||_i|_dS�N)�tree�edge_hashes)�selfr�r�3/usr/lib/python3/dist-packages/breezy/rename_map.py�__init__%szRenameMap.__init__ccs8d}tt|��D]"}tt|||d���|VqdS)a8Iterate through the hashes of line pairs (which make up an edge).

        The hash is truncated using a modulus to avoid excessive memory
        consumption by the hitscount dict.  A modulus of 10Mi means that the
        maximum number of keys is 10Mi.  (Keys are normally 32 bits, e.g.
        4 Gi)
        i��N)�range�len�hash�tuple)�lines�modulus�nrrr�iter_edge_hashes)s	zRenameMap.iter_edge_hashescCs*|�|�D]}|j�|t���|�q
dS)z�Update edge_hashes to include the given lines.

        :param lines: The lines to update the hashes for.
        :param tag: A tag uniquely associated with these lines (i.e. file-id)
        N)rr�
setdefault�set�add)rr�tag�my_hashrrr�add_edge_hashes6szRenameMap.add_edge_hashesc	s��fdd�|D�}t���l}t��|��D]L\}\}}|�td�|t|��t�}|�|�|�	d�|�
|��|�q*Wd�n1s�0YdS)z�Update to reflect the hashes for files in the tree.

        :param tree: The tree containing the files.
        :param file_ids: A list of file_ids to perform the updates for.
        csg|]}��|�|f�qSr)�id2path)�.0�f�rrr�
<listcomp>E�z2RenameMap.add_file_edge_hashes.<locals>.<listcomp>zCalculating hashesrN)r�nested_progress_bar�	enumerateZiter_files_bytes�updaterrr�
writelines�seekr"�	readlines)	rrZfile_idsZ
desired_files�task�num�file_id�contents�srr&r�add_file_edge_hashes?s
�

zRenameMap.add_file_edge_hashescCsdi}|�|�D]P}|j�|�}|dur(qt|�}|D](}||vrHd||<||d|7<q4q|S)a^Count the number of hash hits for each tag, for the given lines.

        Hits are weighted according to the number of tags the hash is
        associated with; more tags means that the hash is less rare and should
        tend to be ignored.
        :param lines: The lines to calculate hashes of.
        :return: a dict of {tag: hitcount}
        Nrg�?)rr�getr)rr�hitsr!ZtagsZtaglenr rrr�	hitcountsOs	zRenameMap.hitcountscs�g}t���f}t|�D]L\}�|�td�|t|��|�|j����}|�	�fdd�t
|�D��qWd�n1sx0Y|S)z~Find all the hit counts for the listed paths in the tree.

        :return: A list of tuples of count, path, file_id.
        zDetermining hash hitsc3s|]\}}|�|fVqdSr
r)r$�k�v��pathrr�	<genexpr>nr(z)RenameMap.get_all_hits.<locals>.<genexpr>N)rr)r*r+rrr7rZget_file_lines�extendr	)r�paths�all_hitsr/r0r6rr:r�get_all_hitsds
<zRenameMap.get_all_hitscCs|�|�|��S)z5Return a mapping from file_ids to the supplied paths.)�_match_hitsr@)rr>rrr�
file_matchqszRenameMap.file_matchcCsJt�}i}t|dd�D].\}}}||vs||vr2q|||<|�|�q|S)z�Using a hit list, determine a path-to-fileid map.

        The hit list is a list of (count, path, file_id), where count is a
        (possibly float) number, with higher numbers indicating stronger
        matches.
        T)�reverse)r�sortedr)Zhit_listZ
seen_file_idsZpath_map�countr;r1rrrrAuszRenameMap._match_hitsc
Cs�i}|D]4}|}t�|�}|j�|�r(q|�|g��|�qqi}t|�D]<\}}t�}|D] }|�|�}	|	dur\|�	|	�q\|||<qJ|S)z�Return a dict of all file parents that must be versioned.

        The keys are the required parents and the values are sets of their
        children.
        N)
r�dirnamerZis_versionedr�appendr	rr5r)
r�matches�required_parentsr;�childZrequire_ids�parent�childrenZchild_file_idsr1rrr�get_required_parents�s 


zRenameMap.get_required_parentsc	CsXg}t|�D]@\}}t|�D].\}}t|�|��}|dkr|�|||f�qq|�|�S)z�Map parent directories to file-ids.

        This is done by finding similarity between the file-ids of children of
        required parent directories and the file-ids of children of missing
        parent directories.
        r)r	r�intersectionrGrA)	rrI�missing_parentsr?r1Zfile_id_childrenr;Z
path_childrenr6rrr�
match_parents�szRenameMap.match_parentscCs^t�}i}t�}t����(}|jj|d|d�}|D�]�}|jddur�|jdr�|j�|j�|j	d��s�|�
|j	dt���|j�|jddkr�|�|j�n|jdkr2|j�
|jd�r�q2|jddkr�|�|jd�|jddkr2|j�|jd�D]2\}}	|	D]"}
|
ddk�r
|�|
d��q
�q�q2Wd�n1�sJ0Y|||fS)	NT)Zwant_unversionedZpbrr�file)FFZ	directoryr)rrr)rZiter_changes�kindZ	versionedZhas_filenamer#�	parent_idrrr1Z
is_ignoredr;Zwalkdirs)rZbasis�
missing_filesrO�candidate_filesr/�iteratorZchangeZ_dirrLrJrrr�_find_missing_files�s<
�
���
8zRenameMap._find_missing_filesFc	Cs6i}t����}t�dd|�}|���D||�}|��|�|�\}}	}
|��|�||�Wd�n1sp0Y|��|�|
�}|}t	|�dkr�|�
|�}|�||	�}|�|�q�|��|�
|�}
|
D]"\}}}}t�td��||��q�|�s|�|�|�|
�Wd�n1�s(0YdS)a+Guess which files to rename, and perform the rename.

        We assume that unversioned files and missing files indicate that
        versioned files have been renamed outside of Bazaar.

        :param from_tree: A tree to compare from
        :param to_tree: A write-locked working tree.
        zGuessing renames�Nrz
{0} => {1})rr)rZ
ProgressPhaseZ	lock_readZ
next_phaserWr4rBrrMrPr+�_make_inventory_deltarZnoter�formatrZapply_inventory_delta)�klassZ	from_treeZto_treeZdry_runrIr/ZppZrnrTrOrUrHZparents_matches�delta�old�newr1�entryrrr�
guess_renames�s8

�*
��

zRenameMap.guess_renamesc	Cs2g}tdd�t|�D��}g}t|�D]0}z|�|j�|��Wq&tjyTYq&0q&|jj|d�D]�\}}||j	}t
�|�\}	}
|�|	�}|dur�|j�
|	�}|dur�|jj|	gdd�\}}
t|
�dkr�|
d|	kr�qfn|j�
|	�}|j|
k�r|j|k�rqf|��}||_|
|_|�|||j	|f�qf|S)Ncss|]\}}||fVqdSr
r)r$�pr%rrrr<�r(z2RenameMap._make_inventory_delta.<locals>.<genexpr>)Zspecific_filesF)Zrecurser)�dictr	r
rGrr#�errorsZNoSuchIdZiter_entries_by_dirr1r�splitr5Zpath2idZ	smart_addr�namerS�copy)rrHr\Zfile_id_matchesZ
file_id_queryr%Zold_pathr_�new_path�parent_path�new_namerSZaddedZignoredZ	new_entryrrrrY�s<�

�
zRenameMap._make_inventory_deltaN)F)�__name__�
__module__�__qualname__�__doc__r�staticmethodrr"r4r7r@rBrArMrPrW�classmethodr`rYrrrrr"s"
	

$rN)Z
__future__r�rrrZi18nrZsixishrr	r
Zuir�objectrrrrr�<module>s