100 config, |
100 config, |
101 error as errormod, |
101 error as errormod, |
102 extensions, |
102 extensions, |
103 match, |
103 match, |
104 pycompat, |
104 pycompat, |
|
105 registrar, |
105 util, |
106 util, |
106 ) |
107 ) |
107 |
108 |
108 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
109 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
109 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
110 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
110 # be specifying the version(s) of Mercurial they are tested with, or |
111 # be specifying the version(s) of Mercurial they are tested with, or |
111 # leave the attribute unspecified. |
112 # leave the attribute unspecified. |
112 testedwith = 'ships-with-hg-core' |
113 testedwith = 'ships-with-hg-core' |
|
114 |
|
115 configtable = {} |
|
116 configitem = registrar.configitem(configtable) |
|
117 |
|
118 configitem('eol', 'fix-trailing-newline', |
|
119 default=False, |
|
120 ) |
113 |
121 |
114 # Matches a lone LF, i.e., one that is not part of CRLF. |
122 # Matches a lone LF, i.e., one that is not part of CRLF. |
115 singlelf = re.compile('(^|[^\r])\n') |
123 singlelf = re.compile('(^|[^\r])\n') |
116 |
124 |
117 def inconsistenteol(data): |
125 def inconsistenteol(data): |
121 """Filter to convert to LF EOLs.""" |
129 """Filter to convert to LF EOLs.""" |
122 if util.binary(s): |
130 if util.binary(s): |
123 return s |
131 return s |
124 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): |
132 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): |
125 return s |
133 return s |
126 if (ui.configbool('eol', 'fix-trailing-newline', False) |
134 if (ui.configbool('eol', 'fix-trailing-newline') |
127 and s and s[-1] != '\n'): |
135 and s and s[-1] != '\n'): |
128 s = s + '\n' |
136 s = s + '\n' |
129 return util.tolf(s) |
137 return util.tolf(s) |
130 |
138 |
131 def tocrlf(s, params, ui, **kwargs): |
139 def tocrlf(s, params, ui, **kwargs): |
132 """Filter to convert to CRLF EOLs.""" |
140 """Filter to convert to CRLF EOLs.""" |
133 if util.binary(s): |
141 if util.binary(s): |
134 return s |
142 return s |
135 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): |
143 if ui.configbool('eol', 'only-consistent', True) and inconsistenteol(s): |
136 return s |
144 return s |
137 if (ui.configbool('eol', 'fix-trailing-newline', False) |
145 if (ui.configbool('eol', 'fix-trailing-newline') |
138 and s and s[-1] != '\n'): |
146 and s and s[-1] != '\n'): |
139 s = s + '\n' |
147 s = s + '\n' |
140 return util.tocrlf(s) |
148 return util.tocrlf(s) |
141 |
149 |
142 def isbinary(s, params): |
150 def isbinary(s, params): |