# HG changeset patch # User Boris Feld # Date 2017-06-30 01:39:21 # Node ID 0f685a229a81bfd81490cce8c64941603943e140 # Parent aeb956e7729f0830f7cf23f48c51d2bfa59418b6 configitems: register the 'eol.fix-trailing-newline' config diff --git a/hgext/eol.py b/hgext/eol.py --- a/hgext/eol.py +++ b/hgext/eol.py @@ -102,6 +102,7 @@ from mercurial import ( extensions, match, pycompat, + registrar, util, ) @@ -111,6 +112,13 @@ from mercurial import ( # leave the attribute unspecified. testedwith = 'ships-with-hg-core' +configtable = {} +configitem = registrar.configitem(configtable) + +configitem('eol', 'fix-trailing-newline', + default=False, +) + # Matches a lone LF, i.e., one that is not part of CRLF. singlelf = re.compile('(^|[^\r])\n') @@ -123,7 +131,7 @@ def tolf(s, params, ui, **kwargs): return s if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): return s - if (ui.configbool('eol', 'fix-trailing-newline', False) + if (ui.configbool('eol', 'fix-trailing-newline') and s and s[-1] != '\n'): s = s + '\n' return util.tolf(s) @@ -134,7 +142,7 @@ def tocrlf(s, params, ui, **kwargs): return s if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): return s - if (ui.configbool('eol', 'fix-trailing-newline', False) + if (ui.configbool('eol', 'fix-trailing-newline') and s and s[-1] != '\n'): s = s + '\n' return util.tocrlf(s)