§
    cÌcý)  ã                   óX   — d dl mZ ddlmZmZmZ ddlmZ ddlm	Z	  G d„ d¦  «        Z
dS )	é    )ÚBytesIOé   )ÚosutilsÚprogressÚtrace)Úgettext)Ú
ui_factoryc                   ó’   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zd„ Zd„ Z	d„ Z
d„ Zed	„ ¦   «         Zd
„ Zd„ Zd„ Zedd„¦   «         Zd„ ZdS )Ú	RenameMapzDetermine a mapping of renames.c                 ó"   — || _         i | _        d S ©N)ÚtreeÚedge_hashes)Úselfr   s     ú3/usr/lib/python3/dist-packages/breezy/rename_map.pyÚ__init__zRenameMap.__init__   s   € ØˆŒ	ØˆÔÐÐó    c           	   #   ó¤   K  — d}t          t          | ¦  «        ¦  «        D ].}t          t          | ||dz   …         ¦  «        ¦  «        |z  V — Œ/dS )a8  Iterate 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Úns      r   Úiter_edge_hasheszRenameMap.iter_edge_hashes#   sd   è è € ð #ˆÝ•s˜5‘z”zÑ"Ô"ð 	8ð 	8ˆAÝ•u˜U 1 Q¨¡U 7œ^Ñ,Ô,Ñ-Ô-°Ñ7Ð7Ð7Ð7Ð7ð	8ð 	8r   c                 óª   — |                       |¦  «        D ]<}| j                             |t          ¦   «         ¦  «                             |¦  «         Œ=dS )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)r   r   Ú
setdefaultÚsetÚadd)r   r   ÚtagÚmy_hashs       r   Úadd_edge_hasheszRenameMap.add_edge_hashes0   s]   € ð ×,Ò,¨UÑ3Ô3ð 	Að 	AˆGØÔ×'Ò'¨µ±´Ñ7Ô7×;Ò;¸CÑ@Ô@Ð@Ð@ð	Að 	Ar   c           	      óö  ‡— ˆfd„|D ¦   «         }t          j        ¦   «         5 }t          ‰                     |¦  «        ¦  «        D ]™\  }\  }}|                     t          d¦  «        |t          |¦  «        ¦  «         t          ¦   «         }|                     |¦  «         | 	                    d¦  «         |  
                    |                     ¦   «         |¦  «         Œš	 ddd¦  «         dS # 1 swxY w Y   dS )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.
        c                 ó>   •— g | ]}‰                      |¦  «        |f‘ŒS © )Úid2path)Ú.0Úfr   s     €r   ú
<listcomp>z2RenameMap.add_file_edge_hashes.<locals>.<listcomp>?   s(   ø€ Ð@Ð@Ð@°!˜$Ÿ,š, q™/œ/¨1Ð-Ð@Ð@Ð@r   zCalculating hashesr   N)r	   Únested_progress_barÚ	enumerateÚiter_files_bytesÚupdater   r   r   Ú
writelinesÚseekr$   Ú	readlines)	r   r   Úfile_idsÚdesired_filesÚtaskÚnumÚfile_idÚcontentsÚss	    `       r   Úadd_file_edge_hasheszRenameMap.add_file_edge_hashes9   s8  ø€ ð AÐ@Ð@Ð@°xÐ@Ñ@Ô@ˆÝÔ+Ñ-Ô-ð 	=°Ý,5Ø×)Ò)¨-Ñ8Ô8ñ-:ô -:ð =ð =Ñ(�Ñ(�g˜xà—’�GÐ$8Ñ9Ô9¸3ÅÀHÁÄÑNÔNÐNÝ‘I”I�Ø—’˜XÑ&Ô&Ð&Ø—’�q‘	”	�	Ø×$Ò$ Q§[¢[¡]¤]°GÑ<Ô<Ð<Ð<ð=ð	=ð 	=ð 	=ñ 	=ô 	=ð 	=ð 	=ð 	=ð 	=ð 	=ð 	=ð 	=øøøð 	=ð 	=ð 	=ð 	=ð 	=ð 	=s   £B=C.Ã.C2Ã5C2c                 óÔ   — i }|                       |¦  «        D ]O}| j                             |¦  «        }|€Œt          |¦  «        }|D ]}||vrd||<   ||xx         d|z  z  cc<   ŒŒP|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}
        Nr   g      ð?)r   r   Úgetr   )r   r   Úhitsr#   ÚtagsÚtaglenr"   s          r   Ú	hitcountszRenameMap.hitcountsI   s˜   € ð ˆØ×,Ò,¨UÑ3Ô3ð 	*ð 	*ˆGØÔ#×'Ò'¨Ñ0Ô0ˆDØˆ|ØÝ˜‘Y”YˆFØð *ð *�Ø˜d�?�?Ø !�D˜‘IØ�S�	�	”	˜S 6™\Ñ)�	�	‘	�	ð*ð ˆr   c           	      ó°  ‡— g }t          j        ¦   «         5 }t          |¦  «        D ]–\  }Š|                     t	          d¦  «        |t          |¦  «        ¦  «         |                      | j                             ‰¦  «        ¦  «        }| 	                    ˆfd„| 
                    ¦   «         D ¦   «         ¦  «         Œ—	 ddd¦  «         n# 1 swxY w Y   |S )z~Find all the hit counts for the listed paths in the tree.

        :return: A list of tuples of count, path, file_id.
        zDetermining hash hitsc              3   ó(   •K  — | ]\  }}|‰|fV — Œd S r   r'   )r)   ÚkÚvÚpaths      €r   ú	<genexpr>z)RenameMap.get_all_hits.<locals>.<genexpr>h   s-   øè è € ÐFÐF±°°A  D¨! ÐFÐFÐFÐFÐFÐFr   N)r	   r,   r-   r/   r   r   r@   r   Úget_file_linesÚextendÚitems)r   ÚpathsÚall_hitsr5   r6   r=   rE   s         @r   Úget_all_hitszRenameMap.get_all_hits^   s  ø€ ð
 ˆÝÔ+Ñ-Ô-ð 	G°Ý& uÑ-Ô-ð Gð G‘	��TØ—’�GÐ$;Ñ<Ô<¸cÅ3ÀuÁ:Ä:ÑNÔNÐNØ—~’~ d¤i×&>Ò&>¸tÑ&DÔ&DÑEÔE�Ø—’ÐFÐFÐFÐF¸¿º¹¼ÐFÑFÔFÑFÔFÐFÐFðGð	Gð 	Gð 	Gñ 	Gô 	Gð 	Gð 	Gð 	Gð 	Gð 	Gð 	Gøøøð 	Gð 	Gð 	Gð 	Gð
 ˆs   —B'CÃCÃCc                 óR   — |                       |                      |¦  «        ¦  «        S )z5Return a mapping from file_ids to the supplied paths.)Ú_match_hitsrL   )r   rJ   s     r   Ú
file_matchzRenameMap.file_matchk   s$   € à×Ò × 1Ò 1°%Ñ 8Ô 8Ñ9Ô9Ð9r   c                 óœ   — t          ¦   «         }i }t          | d¬¦  «        D ])\  }}}||v s||v rŒ|||<   |                     |¦  «         Œ*|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!   )Úhit_listÚseen_file_idsÚpath_mapÚcountrE   r7   s         r   rN   zRenameMap._match_hitso   sr   € õ ™œˆØˆÝ$*¨8¸TÐ$BÑ$BÔ$Bð 	'ð 	'Ñ ˆE�4˜Ø�xÐÐ 7¨mÐ#;Ð#;ØØ$ˆH�T‰NØ×Ò˜gÑ&Ô&Ð&Ð&Øˆr   c                 óŒ  — i }|D ]^}	 |}t          j        |¦  «        }| j                             |¦  «        rn*|                     |g ¦  «                             |¦  «         Œ[Œ_i }|                     ¦   «         D ]I\  }}t          ¦   «         }|D ].}|                     |¦  «        }	|	�| 	                    |	¦  «         Œ/|||<   ŒJ|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.
        )
r   Údirnamer   Úis_versionedr   ÚappendrI   r    r<   r!   )
r   ÚmatchesÚrequired_parentsrE   ÚchildÚrequire_idsÚparentÚchildrenÚchild_file_idsr7   s
             r   Úget_required_parentszRenameMap.get_required_parents€   sû   € ð ÐØð 	Dð 	DˆDðDØ�Ý” tÑ,Ô,�Ø”9×)Ò)¨$Ñ/Ô/ð ØØ ×+Ò+¨D°"Ñ5Ô5×<Ò<¸UÑCÔCÐCðDð àˆØ 0× 6Ò 6Ñ 8Ô 8ð 	1ð 	1ÑˆF�HÝ ™UœUˆNØ!ð 0ð 0�Ø!Ÿ+š+ eÑ,Ô,�ØÐ&Ø"×&Ò& wÑ/Ô/Ð/øØ"0ˆK˜ÑÐØÐr   c                 ó  — g }|                      ¦   «         D ]_\  }}|                      ¦   «         D ]E\  }}t          |                     |¦  «        ¦  «        }|dk    r|                     |||f¦  «         ŒFŒ`|                      |¦  «        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   )rI   r   ÚintersectionrZ   rN   )	r   r\   Úmissing_parentsrK   r7   Úfile_id_childrenrE   Úpath_childrenr=   s	            r   Úmatch_parentszRenameMap.match_parents˜   s¤   € ð ˆØ)8×)>Ò)>Ñ)@Ô)@ð 	;ð 	;Ñ%ˆGÐ%Ø'7×'=Ò'=Ñ'?Ô'?ð ;ð ;Ñ#��mÝ˜=×5Ò5Ð6FÑGÔGÑHÔH�Ø˜!’8�8Ø—O’O T¨4°Ð$9Ñ:Ô:Ð:øð;ð ×Ò Ñ)Ô)Ð)r   c                 ó  — t          ¦   «         }i }t          ¦   «         }t          j        ¦   «         5 }| j                             |d|¬¦  «        }|D �]–}|j        d         €¼|j        d         r¯| j                             | j                             |j	        d         ¦  «        ¦  «        sE| 
                    |j	        d         t          ¦   «         ¦  «                             |j        ¦  «         |j        d         dk    r|                     |j        ¦  «         n	 |j        dk    r¿| j                             |j        d         ¦  «        rŒý|j        d         dk    r |                     |j        d         ¦  «         |j        d         dk    rW| j                             |j        d         ¦  «        D ]1\  }}	|	D ])}
|
d         dk    r|                     |
d         ¦  «         Œ*Œ2�Œ˜	 d d d ¦  «         n# 1 swxY w Y   |||fS )	NT)Úwant_unversionedÚpbr   r   Úfile)FFÚ	directoryr   )r    r	   r,   r   Úiter_changesÚkindÚ	versionedÚhas_filenamer(   Ú	parent_idr   r!   r7   Ú
is_ignoredrE   Úwalkdirs)r   ÚbasisÚmissing_filesre   Úcandidate_filesr5   ÚiteratorÚchangeÚ_dirr`   r]   s              r   Ú_find_missing_fileszRenameMap._find_missing_files§   s_  € Ý™œˆØˆÝ™%œ%ˆÝÔ+Ñ-Ô-ð 	B°Ø”y×-Ò-¨eÀdØ15ð .ñ 7ô 7ˆHà"ð Bñ B�Ø”;˜q”>Ð)¨fÔ.>¸qÔ.AÐ)Øœ9×1Ò1Ø œI×-Ò-¨fÔ.>¸qÔ.AÑBÔBñDô Dð Là'×2Ò2Ø"Ô,¨QÔ/µ±´ñ8ô 8ß8;º¸F¼NÑ8KÔ8KÐ8KØ”{ 1”~¨Ò/Ð/Ø%×)Ò)¨&¬.Ñ9Ô9Ð9Ð9ð ØÔ# ~Ò5Ð5Ø”y×+Ò+¨F¬K¸¬NÑ;Ô;ð !Ø Ø”{ 1”~¨Ò/Ð/Ø'×+Ò+¨F¬K¸¬NÑ;Ô;Ð;Ø”{ 1”~¨Ò4Ð4Ø.2¬i×.@Ò.@ÀÄÈQÄÑ.PÔ.Pð Bð B™N˜D (Ø)1ð Bð B Ø#(¨¤8¨vÒ#5Ð#5Ø$3×$7Ò$7¸¸a¼Ñ$AÔ$AÐ$AøðBùð%Bð	Bð 	Bð 	Bñ 	Bô 	Bð 	Bð 	Bð 	Bð 	Bð 	Bð 	Bøøøð 	Bð 	Bð 	Bð 	Bð0 ˜o¨Ð>Ð>s   ²F8G7Ç7G;Ç>G;Fc                 óô  — i }t          j        ¦   «         5 }t          j        dd|¦  «        }|                     ¦   «         5   | |¦  «        }|                     ¦   «          |                     |¦  «        \  }}	}
|                     ¦   «          |                     ||¦  «         ddd¦  «         n# 1 swxY w Y   |                     ¦   «          |                     |
¦  «        }|}t          |¦  «        dk    rS| 
                    |¦  «        }|                     ||	¦  «        }|                     |¦  «         t          |¦  «        dk    °S|                     ¦   «          |                     |¦  «        }|D ]<\  }}}}t          j        t!          d¦  «                             ||¦  «        ¦  «         Œ=|s*|                     |¦  «         |                     |¦  «         ddd¦  «         dS # 1 swxY w Y   dS )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.
        zGuessing renamesé   Nr   z
{0} => {1})r	   r,   r   ÚProgressPhaseÚ	lock_readÚ
next_phaser{   r:   rO   r   rb   rh   r/   Ú_make_inventory_deltar   Únoter   Úformatr!   Úapply_inventory_delta)ÚklassÚ	from_treeÚto_treeÚdry_runr\   r5   ÚppÚrnrv   re   rw   r[   Úparents_matchesÚdeltaÚoldÚnewr7   Úentrys                     r   Úguess_renameszRenameMap.guess_renamesÅ   sŒ  € ð ÐÝÔ+Ñ-Ô-ð 	5°ÝÔ'Ð(:¸A¸tÑDÔDˆBØ×$Ò$Ñ&Ô&ð Bð BØ�U˜7‘^”^�Ø—’‘”�à×*Ò*¨9Ñ5Ô5ñ @�˜°à—’‘”�Ø×'Ò'¨	°=ÑAÔAÐAðBð Bð Bñ Bô Bð Bð Bð Bð Bð Bð Bøøøð Bð Bð Bð Bð �MŠM‰OŒOˆOØ—m’m OÑ4Ô4ˆGØ%ˆOÝ�oÑ&Ô&¨Ò*Ð*Ø#%×#:Ò#:Ø#ñ$%ô $%Ð à"$×"2Ò"2Ð3CØ3Bñ#Dô #D�à—’˜Ñ/Ô/Ð/õ �oÑ&Ô&¨Ò*Ð*ð �MŠM‰OŒOˆOØ×,Ò,¨WÑ5Ô5ˆEØ,1ð Cð CÑ(��S˜' 5Ý”
�7 <Ñ0Ô0×7Ò7¸¸SÑAÔAÑBÔBÐBÐBØð 5Ø—’Ð,Ñ-Ô-Ð-Ø×-Ò-¨eÑ4Ô4Ð4ð1	5ð 	5ð 	5ñ 	5ô 	5ð 	5ð 	5ð 	5ð 	5ð 	5ð 	5ð 	5øøøð 	5ð 	5ð 	5ð 	5ð 	5ð 	5s7   –+G-ÁA#B0Â$G-Â0B4	Â4G-Â7B4	Â8D(G-Ç-G1Ç4G1c                 óT  — g }d„ |                      ¦   «         D ¦   «         }g }|                     ¦   «         D ]E}	 |                     | j                             |¦  «        ¦  «         Œ1# t
          j        $ r Y ŒBw xY w| j                             |¬¦  «        D �]\  }}||j                 }t          j
        |¦  «        \  }	}
|                     |	¦  «        }|€v| j                             |	¦  «        }|€Z| j                             |	gd¬¦  «        \  }}t          |¦  «        dk    r|d         |	k    rŒ�| j                             |	¦  «        }|j        |
k    r|j        |k    rŒÎ|                     ¦   «         }||_        |
|_        |                     |||j        |f¦  «         �Œ|S )Nc                 ó   — i | ]\  }}||“Œ	S r'   r'   )r)   Úpr*   s      r   ú
<dictcomp>z3RenameMap._make_inventory_delta.<locals>.<dictcomp>ì   s   € Ð<Ð<Ð<¡D A q˜1˜aÐ<Ð<Ð<r   )Úspecific_filesF)Úrecurser   )rI   ÚvaluesrZ   r   r(   ÚerrorsÚNoSuchIdÚiter_entries_by_dirr7   r   Úsplitr<   Úpath2idÚ	smart_addr   Únamerr   Úcopy)r   r[   rŒ   Úfile_id_matchesÚfile_id_queryr*   Úold_pathr�   Únew_pathÚparent_pathÚnew_namerr   ÚaddedÚignoredÚ	new_entrys                  r   r�   zRenameMap._make_inventory_deltaê   sË  € ØˆØ<Ð<¨G¯MªM©O¬OÐ<Ñ<Ô<ˆØˆØ—’Ñ!Ô!ð 	ð 	ˆAðØ×$Ò$ T¤Y×%6Ò%6°qÑ%9Ô%9Ñ:Ô:Ð:Ð:øÝ”?ð ð ð Ø�ðøøøà#œy×<Ò<Ø,ð  =ñ  .ô  .ð 	Mñ 	M‰OˆH�eà& u¤}Ô5ˆHÝ$+¤M°(Ñ$;Ô$;Ñ!ˆK˜ØŸš KÑ0Ô0ˆIØÐ Ø œI×-Ò-¨kÑ:Ô:�	ØÐ$Ø%)¤Y×%8Ò%8Ø$˜¨uð &9ñ &6ô &6‘N�E˜7å˜7‘|”| aÒ'Ð'¨G°A¬J¸+Ò,EÐ,EØ à$(¤I×$5Ò$5°kÑ$BÔ$B˜	ØŒz˜XÒ%Ð%¨%¬/¸YÒ*FÐ*FØØŸ
š
™œˆIØ"+ˆIÔØ%ˆIŒNØ�LŠL˜( H¨iÔ.?ÀÐKÑLÔLÐLÑLØˆs   º-A(Á(A:Á9A:N)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústaticmethodr   r$   r:   r@   rL   rO   rN   rb   rh   r{   Úclassmethodr�   r�   r'   r   r   r   r      s
  € € € € € Ø)Ð)ðð ð ð ð
8ð 
8ñ „\ð
8ðAð Að Að=ð =ð =ð ð ð ð*ð ð ð:ð :ð :ð ðð ñ „\ðð ð ð ð0*ð *ð *ð?ð ?ð ?ð< ð"5ð "5ð "5ñ „[ð"5ðHð ð ð ð r   r   N)Úior   Ú r   r   r   Úi18nr   Úuir	   r   r'   r   r   ú<module>r³      s­   ðð" Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð
 Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðkð kð kð kð kñ kô kð kð kð kr   