Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/hgext/eol.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


��Qc@s/dZddlmZddlmZmZmZmZmZddl	Z	ddl
Z
dZe	jd�Z
e	jd�Zd�Zd	�Zd
�Zd�Zied6ed
6ed6ed6ed6Zdefd��YZd�Zd�Zd�Zd�ZeZd�Zd�Zd�Zd�ZdS(s'automatically manage newlines in repository files

This extension allows you to manage the type of line endings (CRLF or
LF) that are used in the repository and in the local working
directory. That way you can get CRLF line endings on Windows and LF on
Unix/Mac, thereby letting everybody use their OS native line endings.

The extension reads its configuration from a versioned ``.hgeol``
configuration file found in the root of the working copy. The
``.hgeol`` file use the same syntax as all other Mercurial
configuration files. It uses two sections, ``[patterns]`` and
``[repository]``.

The ``[patterns]`` section specifies how line endings should be
converted between the working copy and the repository. The format is
specified by a file pattern. The first match is used, so put more
specific patterns first. The available line endings are ``LF``,
``CRLF``, and ``BIN``.

Files with the declared format of ``CRLF`` or ``LF`` are always
checked out and stored in the repository in that format and files
declared to be binary (``BIN``) are left unchanged. Additionally,
``native`` is an alias for checking out in the platform's default line
ending: ``LF`` on Unix (including Mac OS X) and ``CRLF`` on
Windows. Note that ``BIN`` (do nothing to line endings) is Mercurial's
default behaviour; it is only needed if you need to override a later,
more general pattern.

The optional ``[repository]`` section specifies the line endings to
use for files stored in the repository. It has a single setting,
``native``, which determines the storage line endings for files
declared as ``native`` in the ``[patterns]`` section. It can be set to
``LF`` or ``CRLF``. The default is ``LF``. For example, this means
that on Windows, files configured as ``native`` (``CRLF`` by default)
will be converted to ``LF`` when stored in the repository. Files
declared as ``LF``, ``CRLF``, or ``BIN`` in the ``[patterns]`` section
are always stored as-is in the repository.

Example versioned ``.hgeol`` file::

  [patterns]
  **.py = native
  **.vcproj = CRLF
  **.txt = native
  Makefile = LF
  **.jpg = BIN

  [repository]
  native = LF

.. note::
   The rules will first apply when files are touched in the working
   copy, e.g. by updating to null and back to tip to touch all files.

The extension uses an optional ``[eol]`` section read from both the
normal Mercurial configuration files and the ``.hgeol`` file, with the
latter overriding the former. You can use that section to control the
overall behavior. There are three settings:

- ``eol.native`` (default ``os.linesep``) can be set to ``LF`` or
  ``CRLF`` to override the default interpretation of ``native`` for
  checkout. This can be used with :hg:`archive` on Unix, say, to
  generate an archive where files have line endings for Windows.

- ``eol.only-consistent`` (default True) can be set to False to make
  the extension convert files with inconsistent EOLs. Inconsistent
  means that there is both ``CRLF`` and ``LF`` present in the file.
  Such files are normally not touched under the assumption that they
  have mixed EOLs on purpose.

- ``eol.fix-trailing-newline`` (default False) can be set to True to
  ensure that converted files end with a EOL character (either ``\n``
  or ``\r\n`` as per the configured patterns).

The extension provides ``cleverencode:`` and ``cleverdecode:`` filters
like the deprecated win32text extension does. This means that you can
disable win32text and enable eol and your filters will still work. You
only need to these filters until you have prepared a ``.hgeol`` file.

The ``win32text.forbid*`` hooks provided by the win32text extension
have been unified into a single hook named ``eol.checkheadshook``. The
hook will lookup the expected line endings from the ``.hgeol`` file,
which means you must migrate to a ``.hgeol`` file first before using
the hook. ``eol.checkheadshook`` only checks heads, intermediate
invalid revisions will be pushed. To forbid them completely, use the
``eol.checkallhook`` hook. These hooks are best used as
``pretxnchangegroup`` hooks.

See :hg:`help patterns` for more information about the glob patterns
used.
i�(t_(tutiltconfigt
extensionstmatchterrorNtinternals	(^|[^
])
s
*
cCsd|kotj|�S(Ns
(tsinglelftsearch(tdata((s-/sys/lib/python2.7/site-packages/hgext/eol.pytinconsistenteolkscKs�tj|�r|S|jddt�r8t|�r8|S|jddt�rp|rp|ddkrp|d}ntjd|�S(sFilter to convert to LF EOLs.teolsonly-consistentsfix-trailing-newlinei�s
(Rtbinaryt
configbooltTrueR
tFalseteolretsub(tstparamstuitkwargs((s-/sys/lib/python2.7/site-packages/hgext/eol.pyttolfns!
cKs�tj|�r|S|jddt�r8t|�r8|S|jddt�rp|rp|ddkrp|d}ntjd|�S(sFilter to convert to CRLF EOLs.Rsonly-consistentsfix-trailing-newlinei�s
s
(RRR
RR
RRR(RRRR((s-/sys/lib/python2.7/site-packages/hgext/eol.pyttocrlfys!
cCs|S(s#Filter to do nothing with the file.((RR((s-/sys/lib/python2.7/site-packages/hgext/eol.pytisbinary�ssto-lfsto-crlfs	is-binarys
cleverencode:s
cleverdecode:teolfilecBs#eZd�Zd�Zd�ZRS(c
Cseidd6dd6dd6|_idd6dd6dd6|_tj�|_|jjddd�|jjd	|�|jjd
d�dk}|r�dp�d|jd<|jd
dtj�dk}|r�dp�d|jd<g}g}xU|jj	d�D]A\}}	|	j
�}
|
dkr2|j|�q�j|�q�j|dg||�|_dS(Nsto-lftLFsto-crlftCRLFs	is-binarytBINtpatternss.hg*s.hgeolt
repositorytnativetNATIVERs
t(Rs
(
t_decodet_encodeRtcfgtsettparsetgettostlineseptitemstuppertappendR(tselfRtrootR	tisrepolftiswdlftincludetexcludetpatterntstyletkey((s-/sys/lib/python2.7/site-packages/hgext/eol.pyt__init__�s"cCs�x�|jjd�D]�\}}|j�}y8|jd||j|�|jd||j|�Wqtk
r�|jtd�||jj	d|�f�qXqWx3|jjd�D]\}}|jd||�q�WdS(NRtdecodetencodes(ignoring unknown EOL style '%s' from %s
R(
R$R*R+t	setconfigR"R#tKeyErrortwarnRtsource(R-RR3R4R5tktv((s-/sys/lib/python2.7/site-packages/hgext/eol.pytcopytoui�s
%c

Cs�g}x�p|j�D]�}||kr1qnx�|jjd�D]�\}}tj|jd|g�|�swqDn|j|j�}||j�}	|dkr�d|	ks�|dkr�j	|	�r�j
t|�||f�nPqDWqW|S(NRR!sto-lfs
sto-crlf(tfilesR$R*RR.R#R+R	RRR,tstr(
R-trepotctxR@tfailedtfR3R4ttargetR	((s-/sys/lib/python2.7/site-packages/hgext/eol.pytcheckrev�s!	(t__name__t
__module__R6R?RG(((s-/sys/lib/python2.7/site-packages/hgext/eol.pyR�s		
cCs�y~xw|D]o}yO|dkr7|jd�j�}n||dj�}t||j|�SWq
ttfk
rxq
Xq
WWnAtj	k
r�}|j
td�|jd|jdf�nXdS(Ns.hgeols;warning: ignoring .hgeol file due to parse error at %s: %s
ii(
tNonetwfiletreadR	RR.tIOErrortLookupErrorRt
ParseErrorR;Rtargs(RRBtnodestnodeR	tinst((s-/sys/lib/python2.7/site-packages/hgext/eol.pytparseeol�s
 cCs�t�}t�}x�t||j�t|��D]c}|j|�|r2||}|j|j��x*|j�D]}|j|j��quWq2q2Wg}	xX|D]P}||}t	|||j
�g�}
|
r�|	j|
j|||��q�q�W|	r}idd6dd6}g}x;|	D]3\}}
}|j
td�||||
f�q!Wtjtd�dj|���ndS(NRsto-lfRsto-crlfs*  %s in %s should not have %s line endingssend-of-line check failed:
s
(R%txrangetrevtlentaddtupdateR@tparentstdiscardRTRRtextendRGR,RRtAborttjoin(RRBRRt	headsonlyR@trevsRVRCtpctxRDRteolstmsgsRFRE((s-/sys/lib/python2.7/site-packages/hgext/eol.pyt
_checkhook�s,		&



#cKst|||t�dS(s$verify that files have expected EOLsN(RdR(RRBRRthooktypeR((s-/sys/lib/python2.7/site-packages/hgext/eol.pytcheckallhook�scKst|||t�dS(s$verify that files have expected EOLsN(RdR(RRBRRReR((s-/sys/lib/python2.7/site-packages/hgext/eol.pytcheckheadshook�scCs|j|g�tS(N(tloadeolR(RRBRetparent1tparent2((s-/sys/lib/python2.7/site-packages/hgext/eol.pyt	preupdatescCs|jddt�dS(Nthookss
preupdate.eol(R9Rk(R((s-/sys/lib/python2.7/site-packages/hgext/eol.pytuisetupscCs<y$tjd�|jtd��Wntk
r7nXdS(Nt	win32texts?the eol extension is incompatible with the win32text extension
(RtfindR;RR:(R((s-/sys/lib/python2.7/site-packages/hgext/eol.pytextsetup	s


cs�t|j�|j�sdSx*tj�D]\}}|j||�q*W|jddd�d|jf�fd��Y��|_|j�dS(NtpatchRtautoteolrepocs,eZd�Zd�Ze�fd�ZRS(cSs<t|j||�}|dkr%dS|j|j�|jS(N(RTRRJR?R(R-RQR((s-/sys/lib/python2.7/site-packages/hgext/eol.pyRhs
cSsM|jddg�|_|js1tj|_dSytjj|jd��}Wnt	k
rid}nXytjj|j
d��}Wnt	k
r�d}nX||krI|jjd�d}yj|j
�}x7|jD],}|j|dkr�|jj|�q�q�W|jdd�j�|j�WqItjk
rEqIXndS(Nttips	eol.cacheis.hgeolseol: detected change in .hgeol
tntw(RhRJt_eolfileRtneverR(tpathtgetmtimeR^tOSErrortwjoinRtdebugtwlocktdirstatetnormallookuptopenertclosetreleaseRtLockUnavailable(R-t
cachemtimeteolmtimeR~RE((s-/sys/lib/python2.7/site-packages/hgext/eol.pyt_hgcleardirstate%s0	



cs�x�t|j�|j��D]�}|j|�s8qny||j�}Wntk
rbqnXtj|�rxqnt|�rtj	t
d|���qqWt�|�j||�S(Ns!inconsistent newline style in %s
(
tsortedtaddedtmodifiedRwR	RMRRR
R]Rtsupert	commitctx(R-RCRRER	(Rs(s-/sys/lib/python2.7/site-packages/hgext/eol.pyR�Ks#
(RHRIRhR�RR�((Rs(s-/sys/lib/python2.7/site-packages/hgext/eol.pyRss		&(	RmRtlocaltfilterst	iteritemst
adddatafilterR9t	__class__R�(RRBtnametfn((Rss-/sys/lib/python2.7/site-packages/hgext/eol.pyt	reposetups
@	(t__doc__tmercurial.i18nRt	mercurialRRRRRtreR(t
testedwithtcompileRRR
RRRR�tobjectRRTRdRfRgthookRkRmRpR�(((s-/sys/lib/python2.7/site-packages/hgext/eol.pyt<module>[s4(				
:								

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.