hgext/eol.py
changeset 37084 f0b6fbea00cf
parent 36667 bcfc4e3b6548
child 37507 9b16a67cef56
equal deleted inserted replaced
37083:f99d64e8a4e4 37084:f0b6fbea00cf
   103     match,
   103     match,
   104     pycompat,
   104     pycompat,
   105     registrar,
   105     registrar,
   106     util,
   106     util,
   107 )
   107 )
       
   108 from mercurial.utils import (
       
   109     stringutil,
       
   110 )
   108 
   111 
   109 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
   112 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
   110 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
   113 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
   111 # be specifying the version(s) of Mercurial they are tested with, or
   114 # be specifying the version(s) of Mercurial they are tested with, or
   112 # leave the attribute unspecified.
   115 # leave the attribute unspecified.
   131 def inconsistenteol(data):
   134 def inconsistenteol(data):
   132     return '\r\n' in data and singlelf.search(data)
   135     return '\r\n' in data and singlelf.search(data)
   133 
   136 
   134 def tolf(s, params, ui, **kwargs):
   137 def tolf(s, params, ui, **kwargs):
   135     """Filter to convert to LF EOLs."""
   138     """Filter to convert to LF EOLs."""
   136     if util.binary(s):
   139     if stringutil.binary(s):
   137         return s
   140         return s
   138     if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
   141     if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
   139         return s
   142         return s
   140     if (ui.configbool('eol', 'fix-trailing-newline')
   143     if (ui.configbool('eol', 'fix-trailing-newline')
   141         and s and s[-1] != '\n'):
   144         and s and s[-1] != '\n'):
   142         s = s + '\n'
   145         s = s + '\n'
   143     return util.tolf(s)
   146     return util.tolf(s)
   144 
   147 
   145 def tocrlf(s, params, ui, **kwargs):
   148 def tocrlf(s, params, ui, **kwargs):
   146     """Filter to convert to CRLF EOLs."""
   149     """Filter to convert to CRLF EOLs."""
   147     if util.binary(s):
   150     if stringutil.binary(s):
   148         return s
   151         return s
   149     if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
   152     if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
   150         return s
   153         return s
   151     if (ui.configbool('eol', 'fix-trailing-newline')
   154     if (ui.configbool('eol', 'fix-trailing-newline')
   152         and s and s[-1] != '\n'):
   155         and s and s[-1] != '\n'):
   401                     continue
   404                     continue
   402                 fctx = ctx[f]
   405                 fctx = ctx[f]
   403                 if fctx is None:
   406                 if fctx is None:
   404                     continue
   407                     continue
   405                 data = fctx.data()
   408                 data = fctx.data()
   406                 if util.binary(data):
   409                 if stringutil.binary(data):
   407                     # We should not abort here, since the user should
   410                     # We should not abort here, since the user should
   408                     # be able to say "** = native" to automatically
   411                     # be able to say "** = native" to automatically
   409                     # have all non-binary files taken care of.
   412                     # have all non-binary files taken care of.
   410                     continue
   413                     continue
   411                 if inconsistenteol(data):
   414                 if inconsistenteol(data):