
    	^ck                         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dS )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                             ddd t          d          f           d S )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   sQ    "8>9gFFE	!HOO	lD!$L"M"MN    r   c                 x   t          j        |          }d}|                    dd          }|s|                    dd          }d|cxk    rdk    s#n t	          j        t          d                    |dk    r[t          j        |d         ||          }t          ||          \  }	}
t          j
        |d	
          }t          |||	|
|dz            }|                                5  |t          j        |dd|            | ||g|R i t          j        |          cddd           S # 1 swxY w Y   dS )z&Hook to check for moves at commit timeNs	   no_automvFr   r   r   d   s+   automv.similarity must be between 0 and 100T)legacyrelativevalueg      Y@ )r   byteskwargspop	configintr   Abortr   r
   match_interestingfilesgetuipathfn_findrenameswlock_markchanges	strkwargs)origr   repopatsoptsrenamesdisabled	thresholdr#   addedremoveduipathfns               r   r   r   9   s   %%DGxxe,,H 
LLM::	I$$$$$$$$+a NOOPPPq==M$t*dD99E.tU;;NE7*4TJJJH"hw	E0A G 
 A A r2w777tB@t@@@x'9$'?'?@@A A A A A A A A A A A A A A A A A As   *8D//D36D3c                     |                      |          }|j        }|j        }t          j        | d         | d         |          fd|D             }||fS )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#      .Nc                     g | ]}|v|	S r   r   ).0fcopys     r   
<listcomp>z%_interestingfiles.<locals>.<listcomp>]   s    ///1$Qr   )statusr1   r2   r   
pathcopies)r+   matcherstatr1   r2   r9   s        @r   r$   r$   P   se     ;;W;%%DJElGT$ZdW==D///////E'>r   c                 j   i }|dk    rqt          j        | |||          D ]Y\  }}}| j        j        rB| j                            t          d           ||           ||          |dz  fz             |||<   Z|r7| 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   verboser;   r   len)	r+   r3   r1   r2   
similarityr.   srcdstscores	            r   r&   r&   b   s     GA~~&2%* 
  
 	 	OCe w CDDx}}hhsmmUS[AB   GCLL Iq7883w<<GHHHNr   N)__doc__mercurial.i18nr   	mercurialr   r   r   r   r   r	   r
   r   configtable
configitemr   r   r$   r&   r   r   r   <module>rL      s  	 	*      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !Y!+..
 

     A A A.  $    r   