a
    %0_                  	   @   s  d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ dZi Ze
eZed	d
dd edejZdddZdddZd0ddZdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zeeeeeeeed%Zd&d' Zd(d) Z d*d+ Z!d,d- Z"d.d/ Z#dS )1a  perform automatic newline conversion (DEPRECATED)

  Deprecation: The win32text extension requires each user to configure
  the extension again and again for each clone since the configuration
  is not copied when cloning.

  We have therefore made the ``eol`` as an alternative. The ``eol``
  uses a version controlled file for its configuration and each clone
  will therefore use the right settings from the start.

To perform automatic newline conversion, use::

  [extensions]
  win32text =
  [encode]
  ** = cleverencode:
  # or ** = macencode:

  [decode]
  ** = cleverdecode:
  # or ** = macdecode:

If not doing conversion, to make sure you do not commit CRLF/CR by accident::

  [hooks]
  pretxncommit.crlf = python:hgext.win32text.forbidcrlf
  # or pretxncommit.cr = python:hgext.win32text.forbidcr

To do the same check on a server to prevent CRLF/CR from being
pushed or pulled::

  [hooks]
  pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
  # or pretxnchangegroup.cr = python:hgext.win32text.forbidcr
    )absolute_importN)_)short)pycompat	registrar)
stringutils   ships-with-hg-core	   win32text   warnT)defaults	   (^|[^])
s   CRLFs   CR)   
   s   clevers   macc                 C   s<   || v r8|r8|r8|r8| td|t| |jdf  d S )Ns   WARNING: %s already has %s line endings
and does not need EOL conversion by the win32text plugin.
Before your next commit, please reconsider your encode/decode settings in 
Mercurial.ini or %s.
s   hgrc)warnr   
newlinestrZvfsjoin)snewlineuirepofilename r   1/usr/lib/python3/dist-packages/hgext/win32text.pychecknewlineK   s    r   c                 K   s   t | dfi | td| S )Nr   s   \1
)r   re_single_lfsubr   cmdkwargsr   r   r   
dumbdecode\   s    r   c                 C   s   |  ddS )Nr      
replacer   r   r   r   r   
dumbencodeb   s    r"   c                 K   s   t | dfi | | ddS Nr   r   )r   r    r   r   r   r   macdumbdecodef   s    r$   c                 C   s   |  ddS r#   r   r!   r   r   r   macdumbencodek   s    r%   c                 K   s    t | st| |fi |S | S N)r   binaryr   r   r   r   r   cleverdecodeo   s    
r(   c                 C   s   t | st| |S | S r&   )r   r'   r"   r!   r   r   r   cleverencodeu   s    

r)   c                 K   s    t | st| |fi |S | S r&   )r   r'   r$   r   r   r   r   	macdecode{   s    
r*   c                 C   s   t | st| |S | S r&   )r   r'   r%   r!   r   r   r   	macencode   s    

r+   )s   dumbdecode:s   dumbencode:s   cleverdecode:s   cleverencode:s   macdumbdecode:s   macdumbencode:s
   macdecode:s
   macencode:c                 K   s  d}t  }|d }t|j ||  d dD ]}	||	 }
|
 D ]}||v sF||vsF||
vrdqF|| |
|  }t	
|sF||v rF|s| tdt|   | tdt|
 |f  d}qFq2|r
|dkr
t|  }t| }| td	||||f  |S )
NFs   tip   s=   attempt to commit or push text file(s) using %s line endings
s
   in %s: %s
Ts   pretxnchangegroups   
To prevent this mistake in your local repository,
add to Mercurial.ini or .hg/hgrc:

[hooks]
pretxncommit.%s = python:hgext.win32text.forbid%s

and also consider adding:

[extensions]
win32text =
[encode]
** = %sencode:
[decode]
** = %sdecode:
)setr   ZxrangeZ	changelogZtiprevrevfilesadddatar   r'   r   r   r   r   nodelower	filterstr)r   r   hooktyper3   r   r   ZhaltseenZtipr/   cfr2   Zcrlffilterr   r   r   forbidnewline   sD    

r;   c                 K   s   t | |||dfi |S )Nr   r;   r   r   r6   r3   r   r   r   r   
forbidcrlf   s    r>   c                 K   s   t | |||dfi |S )Nr   r<   r=   r   r   r   forbidcr   s    r?   c                 C   s0   |  sd S ttD ]\}}||| qd S r&   )Zlocalr   Z	iteritems_filtersZadddatafilter)r   r   namefnr   r   r   	reposetup   s    rC   c                 C   s   |  ddr| td d S )Nr   r	   sK   win32text is deprecated: https://mercurial-scm.org/wiki/Win32TextExtension
)Z
configboolr   r   )r   r   r   r   extsetup   s    rD   )NNN)$__doc__Z
__future__r   reZmercurial.i18nr   Zmercurial.noder   Z	mercurialr   r   Zmercurial.utilsr   Z
testedwithZconfigtableZ
configitemcompile	MULTILINEr   r   r5   r   r   r"   r$   r%   r(   r)   r*   r+   r@   r;   r>   r?   rC   rD   r   r   r   r   <module>   sL   $



6