
    q&f                     F    d dl mZ d dlmZ d Zd Zd Zd Zd Zd Z	d	 Z
y
)   )_)mdiffc              #      K   i }| j                   j                  t        d      t        |      t        |      z   t        d            }|D ]J  }|j	                          t        |j                               }||vr|g||<   7||   j                  |       L |D ]_  }|j	                          |j                         }t        |      }|j                  |g       D ]  }||j                         k(  s||f  _ a |j                          yw)zfind renamed files that have no changes

    Takes a list of new filectxs and a list of removed filectxs, and yields
    (before, after) tuples of exact matches.
    s   searching for exact renames   files)totalunitN)
uimakeprogressr   len	incrementhashdataappendgetcomplete)	repoaddedremovedhashesprogressfctxhadatarfctxs	            3/usr/lib/python3/dist-packages/mercurial/similar.py_findexactmatchesr      s     Fww##	
()5zCL(x[ $ H
  #F?F1I1IT"#  		KZZ2& 	E

$dm#			 s   C/D2Dc                 P    | j                         }|t        j                  |      fS N)r   r   splitnewlines)r   origs     r   _ctxdatar!   4   s#    99;D$$T***    c                     |\  }}| j                         }d}t        j                  ||      }|D ]  \  }}}	}
||	|
 D ]  }|t        |      z  } ! t        |      t        |      z   }|dz  |z  S )N    g       @)r   r   blocksr   )r   	otherdatar    linestextequalmatchesx1x2y1y2linelengthss                r   _scorer1   :   s    KD%99;D Ell4&G! BB"RL 	DSYE	 $i#d)#G3;  r"   c                 ,    t        | t        |            S r   )r1   r!   )fctx1fctx2s     r   scorer5   I   s    %%))r"   c              #     K   i }| j                   j                  t        d      t        d      t        |            }|D ]X  }|j	                          d}|D ]?  }|j                  |d|f      d   }	|t        |      }t        ||      }
|
|	kD  s9||
f||<   A Z |j                          |j                         D ]  \  }}|\  }}|||f  yw)zfind potentially renamed files based on similar file content

    Takes a list of new filectxs and a list of removed filectxs, and yields
    (before, after, score) tuples of partial matches.
    s   searching for similar filesr   )r   r   Nr   )
r	   r
   r   r   r   r   r!   r1   r   items)r   r   r   	thresholdcopiesr   rr   a	bestscoremyscoredestvsourcebscores                  r   _findsimilarmatchesrB   M   s      Fww##	
()(3w< $ H  	) 	)A

1tY&78;I|{QoG"Lq		)	) <<> #adF""#s   BCA Cc                 T    | D cg c]  }|j                         dkD  s| c}S c c}w )Nr$   )size)fctxsxs     r   
_dropemptyrG   h   s"    -!1A---s   %%c              #     K   | d   j                         t        fdt        |      D              }t        fdt        |      D              }t               }t	        | ||      D ]9  \  }}|j                  |       |j                         |j                         df ; |dk  rO|D 	cg c]	  }	|	|vs|	 }}	t        | |||      D ])  \  }}}
|j                         |j                         |
f + yyc c}	w w)z:find renamed files -- yields (before, after, score) tuplesNc              3   (   K   | ]	  }|     y wr    ).0fpwctxs     r   	<genexpr>zfindrenames.<locals>.<genexpr>t   s     =DH=s   c              3   2   K   | ]  }|v s|     y wr   rJ   )rK   rL   pctxs     r   rN   zfindrenames.<locals>.<genexpr>u   s     O2B$Jd2hOs   	
g      ?)p1rG   sortedsetr   addpathrB   )r   r   r   r8   
addedfilesremovedfilesmatchedfilesr;   brF   r5   rP   rM   s              @@r   findrenamesrZ   l   s     :D779D
 =ve}==JOOOL 5L#D*lC (Avvx3''(
 3!+EAq/DaE
E0*lI
 	.MQ5 668QVVXu--	. Es   B,D0	C<:C<>ADN)i18nr    r   r   r!   r1   r5   rB   rG   rZ   rJ   r"   r   <module>r]      s3    
"J+!*#6..r"   