Mercurial > hg
comparison hgext/eol.py @ 34119:d4a5193332b3
configitems: register the 'eol.only-consistent' config
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 30 Jun 2017 03:39:32 +0200 |
parents | 4a6ef3a5b282 |
children | 60802bba1090 |
comparison
equal
deleted
inserted
replaced
34118:4a6ef3a5b282 | 34119:d4a5193332b3 |
---|---|
119 default=False, | 119 default=False, |
120 ) | 120 ) |
121 configitem('eol', 'native', | 121 configitem('eol', 'native', |
122 default=pycompat.oslinesep, | 122 default=pycompat.oslinesep, |
123 ) | 123 ) |
124 configitem('eol', 'only-consistent', | |
125 default=True, | |
126 ) | |
124 | 127 |
125 # Matches a lone LF, i.e., one that is not part of CRLF. | 128 # Matches a lone LF, i.e., one that is not part of CRLF. |
126 singlelf = re.compile('(^|[^\r])\n') | 129 singlelf = re.compile('(^|[^\r])\n') |
127 | 130 |
128 def inconsistenteol(data): | 131 def inconsistenteol(data): |
130 | 133 |
131 def tolf(s, params, ui, **kwargs): | 134 def tolf(s, params, ui, **kwargs): |
132 """Filter to convert to LF EOLs.""" | 135 """Filter to convert to LF EOLs.""" |
133 if util.binary(s): | 136 if util.binary(s): |
134 return s | 137 return s |
135 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): | 138 if ui.configbool('eol', 'only-consistent') and inconsistenteol(s): |
136 return s | 139 return s |
137 if (ui.configbool('eol', 'fix-trailing-newline') | 140 if (ui.configbool('eol', 'fix-trailing-newline') |
138 and s and s[-1] != '\n'): | 141 and s and s[-1] != '\n'): |
139 s = s + '\n' | 142 s = s + '\n' |
140 return util.tolf(s) | 143 return util.tolf(s) |
141 | 144 |
142 def tocrlf(s, params, ui, **kwargs): | 145 def tocrlf(s, params, ui, **kwargs): |
143 """Filter to convert to CRLF EOLs.""" | 146 """Filter to convert to CRLF EOLs.""" |
144 if util.binary(s): | 147 if util.binary(s): |
145 return s | 148 return s |
146 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): | 149 if ui.configbool('eol', 'only-consistent') and inconsistenteol(s): |
147 return s | 150 return s |
148 if (ui.configbool('eol', 'fix-trailing-newline') | 151 if (ui.configbool('eol', 'fix-trailing-newline') |
149 and s and s[-1] != '\n'): | 152 and s and s[-1] != '\n'): |
150 s = s + '\n' | 153 s = s + '\n' |
151 return util.tocrlf(s) | 154 return util.tocrlf(s) |