o ]Lb@@s8dZddlmZddlZddlZddlmZddlmZm Z m Z m Z m Z mZmZmZddlmZdZiZeeZedd d d edd e jd edd dd edZddZddZddZddZeeeeedZGdddeZddZ ddZ!dd Z"d!d"Z#d#d$Z$e$Z%d%d&Z&d'd(Z'd)d*Z(d+d,Z)dS)-a6automatically 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 directory. 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 directory 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 behavior; 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 directory, 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. )absolute_importN)_)configerror extensionsmatchpycompat registrarscmutilutil) stringutilsships-with-hg-coreeolfix-trailing-newlineF)defaultnativeonly-consistentTs (^|[^ ]) cCsd|vot|S)N )singlelfsearch)datar+/usr/lib/python3/dist-packages/hgext/eol.pyinconsistenteolsrcKRt|r|S|ddrt|r|S|ddr$|r$|ds$|d}t|S)zFilter to convert to LF EOLs.r rr )r binary configboolrendswithr tolfsparamsuikwargsrrrr   rcKr)zFilter to convert to CRLF EOLs.r rrr)r rrrrr tocrlfrrrrr%r$r%cKs|S)z#Filter to do nothing with the file.rrrrrisbinarysr&)to-lfto-crlf is-binarys cleverencode:s cleverdecode:c@s$eZdZddZddZddZdS)eolfilec Csdddd|_dddd|_t|_|jdddd|jd ||jd d d k}|r0dp1d|jd <|dd dv}|rAdpBd|jd <g}g}g|_|jdD](\}} | } | dkre| |n| |t |d|g} |j || | fqSt |dg|||_ dS)Nr'r(r))LFCRLFBINpatternss.hg*r-r .hgeols repositoryrr,sNATIVE)r+r) _decode_encodercfgsetparsegetpatternsitemsupperappendr) selfr"rootrisrepolfiswdlfincludeexcludepatternstylekeymrrr__init__s4   zeolfile.__init__c Csdd|jD}dD] }||D]\}}||vr)|||dkr)|||ddqq |jD]6\}}}z|d||j|d|d||j|dWq.tyd|td||j d |fYq.w|j dD] \} } |d| | dqkdS) NcSsh|]\}}}|qSrr).0rArCrDrrr sz#eolfile.copytoui..)decodeencoder !rHrIs(ignoring unknown EOL style '%s' from %s r.) r7 configitems configsource setconfigr1r2KeyErrorwarnrr3sourcer8) r;r" newpatternssection oldpattern_filterrArCrDkvrrrcopytouis, zeolfile.copytouic Csg}|p|D];}||vrq|jD]0\}}}||sq|j|} ||} | dkr/d| vs8| dkrBt| rB||| t|fq|S)Nr'rr()filesr7r2rrrr:bytes) r;repoctxrXfailedfrArCrDtargetrrrrcheckrevs$  zeolfile.checkrevN)__name__ __module__ __qualname__rErWr_rrrrr*s' r*c Csz2|D],}z|dur|d}n||d}t||j|WWSttfy/YqwWdStjyS}z| t d|j |j fWYd}~dSd}~ww)Nr/s;warning: ignoring .hgeol file due to parse error at %s: %s ) wvfsreadrr*r<IOError LookupErrorerrormod ConfigErrorrOrlocationmessage)r"rZnodesnoderinstrrrparseeols. rncCs2d|jvrdS|jdddddt|dgdS)a/make sure the extension is enabled when used as hook When eol is used through hooks, the extension is never formally loaded and enabled. This has some side effect, for example the config declaration is never loaded. This function ensure the extension is enabled when running hooks. r Ns extensionsr0sinternal)rP) _knownconfigrMrloadallr"rrr ensureenabled&s rrcCst|t}t}t||t|D]"}|||r8||}||| D] }| |q.qg} |D]}||}t ||| g} | rX| | |||q=| rddd} g} t| D]\} }}| td| || |fqfttdd| dS)Nr,r+)r'r(s* %s in %s should not have %s line endingssend-of-line check failed: r)rrr4rxrangerevlenaddupdaterXparentsdiscardrnrlextendr_sortedr:rrgAbortjoin)r"rZrl headsonlyrXrevsrtr[pctxr\eoleolsmsgsr]r^rrr _checkhook4s>    rcKt|||ddS)$verify that files have expected EOLsFNrr"rZrlhooktyper#rrr checkallhookTrcKr)rTNrrrrrcheckheadshookYrrcCst||}||gdS)NF)r resolvehexnodeidprefixloadeol)r"rZrparent1parent2p1noderrr preupdatebs  rcCs|ddtddS)Nshookss preupdate.eolr )rMrrqrrruisetuphsrcCs4ztd|tdWdStyYdSw)Ns win32texts?the eol extension is incompatible with the win32text extension )rfindrOrrNrqrrrextsetupls  rcsnt|j|s dSttD] \}}|||q|ddddGfddd|j|_| dS)Nspatchr sautocs0eZdZddZddZd fdd ZZS) zreposetup..eolrepocSs,t|j||}|dur dS||j|jS)N)rnr"rWr)r;rkrrrrrs  z"reposetup..eolrepo.loadeolcSs|dg|_|jstj|_dSd}z tj|jd}Wn t y)d}Ynw|j d}|r:t |j |j |}z tj|d}Wn t yPd}Ynw||kr|dkr|j d|j d}t |j |j |}d}zzo|}|jD]J}|j|jsqz|dur||s||sqzd} |jD] \} } } | |r| } nqd} |jD] \} } } | |r| } nq| | krqz|j|qz|dd }||Wdn1swYWn tjyYnwW|dur|dSdS|dur|wwdSdS)Ns eol.cacherr/seol: detected change in .hgeol w)r _eolmatchr neverospathgetmtimevfsr}OSErrorrdr*r"r<wjoindebugrcwlockdirstate get_entry maybe_cleanrr7set_possibly_dirtywritergLockUnavailablerelease)r;oldeol cachemtimeolddataeolmtime hgeoldataneweolrr]oldkeyrArCrDnewkeyrrr_hgcleardirstatesx         z+reposetup..eolrepo._hgcleardirstateFNcszt||D](}||sq ||}|durq |}t|r%q t|r2t t d|q t | |||S)Ns!inconsistent newline style in %s ) r{addedmodifiedrrr rrrgr|rsuper commitctx)r;r[rorigctxr]fctxr) __class__eolreporrrs   z$reposetup..eolrepo.commitctx)FN)r`rarbrrr __classcell__rr)rrrsAr) rr"localr iteritemsfilters adddatafilterrMrr)r"rZnamefnrrr reposetupys \ r)*__doc__ __future__rrremercurial.i18nr mercurialrrrgrrrr r r mercurial.utilsr testedwith configtable configitem oslinesepcompilerrrr%r&robjectr*rnrrrrrhookrrrrrrrrs^ ] (    Q