comparison hgext/eol.py @ 14855:f33579435378

eol: fix missing trailing newlines in comitted files Some text editors (Eclipse, for example) do not add trailing newlines, so diffs often contain annoying "\ No newline at the end of file". This patch to eol extension simply adds trailing newline on commit.
author Stepan Koltsov <stepancheg@yandex-team.ru>
date Fri, 01 Jul 2011 23:12:52 +0400
parents 23c2d7d25329
children 9f5cd6b6d758
comparison
equal deleted inserted replaced
14854:23c2d7d25329 14855:f33579435378
104 """Filter to convert to LF EOLs.""" 104 """Filter to convert to LF EOLs."""
105 if util.binary(s): 105 if util.binary(s):
106 return s 106 return s
107 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): 107 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s):
108 return s 108 return s
109 if ui.configbool('eol', 'fix-trailing-newline', False) and s and s[-1] != '\n':
110 s = s + '\n'
109 return eolre.sub('\n', s) 111 return eolre.sub('\n', s)
110 112
111 def tocrlf(s, params, ui, **kwargs): 113 def tocrlf(s, params, ui, **kwargs):
112 """Filter to convert to CRLF EOLs.""" 114 """Filter to convert to CRLF EOLs."""
113 if util.binary(s): 115 if util.binary(s):
114 return s 116 return s
115 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): 117 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s):
116 return s 118 return s
119 if ui.configbool('eol', 'fix-trailing-newline', False) and s and s[-1] != '\n':
120 s = s + '\n'
117 return eolre.sub('\r\n', s) 121 return eolre.sub('\r\n', s)
118 122
119 def isbinary(s, params): 123 def isbinary(s, params):
120 """Filter to do nothing with the file.""" 124 """Filter to do nothing with the file."""
121 return s 125 return s