
    q&fL                         d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZ i Z e	j                  e      Z eddd       d Zd	 Zd
 Zd Zy)ax  check for unrecorded moves at commit time (EXPERIMENTAL)

This extension checks at commit/amend time if any of the committed files
comes from an unrecorded mv.

The threshold at which a file is considered a move can be set with the
``automv.similarity`` config option. This option takes a percentage between 0
(disabled) and 100 (files must be identical), the default is 95.

    )_)commandscopieserror
extensionspycompat	registrarscmutilsimilar   automv
   similarity_   )defaultc                     t        j                  t        j                  dt              }|d   j                  ddd t        d      f       y )Ns   commit       s	   no-automvs%   disable automatic file move detection)r   wrapcommandr   tablemvcheckappendr   )uientrys     ./usr/lib/python3/dist-packages/hgext/automv.pyextsetupr   2   s<    ""8>>9gFE	!HOO	lD!$L"MNr   c           	      v   d}|j                  dd      }|j                         5  |s|j                  dd      }d|cxk  rdk  s n t        j                  t        d            |dkD  ret        j                  |d   |t        j                  |            }t        ||      \  }	}
t        j                  |d	
      }t        |||	|
|dz        }|<|j                  j                  |      5  t        j                  |dd|       ddd        | ||g|i |cddd       S # 1 sw Y   xY w# 1 sw Y   yxY w)z&Hook to check for moves at commit timeN	no_automvFr   r   r   d   s+   automv.similarity must be between 0 and 100T)legacyrelativevalueg      Y@ )popwlock	configintr   Abortr   r
   matchr   byteskwargs_interestingfilesgetuipathfn_findrenamesdirstatechanging_files_markchanges)origr   repopatsoptsrenamesdisabled	thresholdr$   addedremoveduipathfns               r   r   r   9   s:   GxxU+H	 -Y>I	(S(kkDE  1}Jh&:&:4&@ "34!?w"..tN&(E7I4E --d3 < $$T2r7;< B,t,t,3- -$< <%- -s$   CD/,D#D/#D,	(D//D8c                     | j                  |      }|j                  }|j                  }t        j                  | d   | d   |      }|D cg c]	  }||vs| }}||fS c c}w )zFind what files were added or removed in this commit.

    Returns a tuple of two lists: (added, removed). Only files not *already*
    marked as moved are included in the added list.

    )r$      .N)statusr3   r4   r   
pathcopies)r-   matcherstatr3   r4   copyfs          r   r&   r&   Y   sj     ;;W;%DJJEllGT$ZdW=D/1$Q/E/'> 0s   	A A c                 b   i }|dkD  rut        j                  | |||      D ]Z  \  }}}| j                  j                  r9| j                  j	                  t        d       ||       ||      |dz  fz         |||<   \ |r0| j                  j	                  t        d      t        |      z         |S )zFind what files in added are really moved files.

    Any file named in removed that is at least similarity% similar to a file
    in added is seen as a rename.

    r   s)   detected move of %s as %s (%d%% similar)
r   s   detected move of %d files
)r   findrenamesr   verboser8   r   len)	r-   r5   r3   r4   
similarityr0   srcdstscores	            r   r(   r(   k   s     GA~&22%* 
 	OCe wwCD}hsmUS[AB GCL	 q783w<GHNr   N)__doc__mercurial.i18nr   	mercurialr   r   r   r   r   r	   r
   r   configtable
configitemr   r   r&   r(   r   r   r   <module>rK      s]   	* 	 	 	 !Y!!+.
 
-@$r   