comparison hgext/eol.py @ 20790:49f2d5644f04

config: set a 'source' in most cases where config don't come from file but code Some extensions set configuration settings that showed up in 'hg showconfig --debug' with 'none' as source. That was confusing. Instead, they will now tell which extension they come from. This change tries to be consistent and specify a source everywhere - also where it perhaps is less relevant.
author Mads Kiilerich <madski@unity3d.com>
date Wed, 19 Mar 2014 02:45:14 +0100
parents de16c673455b
children 6500a2eebee8
comparison
equal deleted inserted replaced
20789:d19c9bdbbf35 20790:49f2d5644f04
149 self._encode = {'LF': 'to-lf', 'CRLF': 'to-crlf', 'BIN': 'is-binary'} 149 self._encode = {'LF': 'to-lf', 'CRLF': 'to-crlf', 'BIN': 'is-binary'}
150 150
151 self.cfg = config.config() 151 self.cfg = config.config()
152 # Our files should not be touched. The pattern must be 152 # Our files should not be touched. The pattern must be
153 # inserted first override a '** = native' pattern. 153 # inserted first override a '** = native' pattern.
154 self.cfg.set('patterns', '.hg*', 'BIN') 154 self.cfg.set('patterns', '.hg*', 'BIN', 'eol')
155 # We can then parse the user's patterns. 155 # We can then parse the user's patterns.
156 self.cfg.parse('.hgeol', data) 156 self.cfg.parse('.hgeol', data)
157 157
158 isrepolf = self.cfg.get('repository', 'native') != 'CRLF' 158 isrepolf = self.cfg.get('repository', 'native') != 'CRLF'
159 self._encode['NATIVE'] = isrepolf and 'to-lf' or 'to-crlf' 159 self._encode['NATIVE'] = isrepolf and 'to-lf' or 'to-crlf'
174 174
175 def copytoui(self, ui): 175 def copytoui(self, ui):
176 for pattern, style in self.cfg.items('patterns'): 176 for pattern, style in self.cfg.items('patterns'):
177 key = style.upper() 177 key = style.upper()
178 try: 178 try:
179 ui.setconfig('decode', pattern, self._decode[key]) 179 ui.setconfig('decode', pattern, self._decode[key], 'eol')
180 ui.setconfig('encode', pattern, self._encode[key]) 180 ui.setconfig('encode', pattern, self._encode[key], 'eol')
181 except KeyError: 181 except KeyError:
182 ui.warn(_("ignoring unknown EOL style '%s' from %s\n") 182 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
183 % (style, self.cfg.source('patterns', pattern))) 183 % (style, self.cfg.source('patterns', pattern)))
184 # eol.only-consistent can be specified in ~/.hgrc or .hgeol 184 # eol.only-consistent can be specified in ~/.hgrc or .hgeol
185 for k, v in self.cfg.items('eol'): 185 for k, v in self.cfg.items('eol'):
186 ui.setconfig('eol', k, v) 186 ui.setconfig('eol', k, v, 'eol')
187 187
188 def checkrev(self, repo, ctx, files): 188 def checkrev(self, repo, ctx, files):
189 failed = [] 189 failed = []
190 for f in (files or ctx.files()): 190 for f in (files or ctx.files()):
191 if f not in ctx: 191 if f not in ctx:
259 def preupdate(ui, repo, hooktype, parent1, parent2): 259 def preupdate(ui, repo, hooktype, parent1, parent2):
260 repo.loadeol([parent1]) 260 repo.loadeol([parent1])
261 return False 261 return False
262 262
263 def uisetup(ui): 263 def uisetup(ui):
264 ui.setconfig('hooks', 'preupdate.eol', preupdate) 264 ui.setconfig('hooks', 'preupdate.eol', preupdate, 'eol')
265 265
266 def extsetup(ui): 266 def extsetup(ui):
267 try: 267 try:
268 extensions.find('win32text') 268 extensions.find('win32text')
269 ui.warn(_("the eol extension is incompatible with the " 269 ui.warn(_("the eol extension is incompatible with the "
278 if not repo.local(): 278 if not repo.local():
279 return 279 return
280 for name, fn in filters.iteritems(): 280 for name, fn in filters.iteritems():
281 repo.adddatafilter(name, fn) 281 repo.adddatafilter(name, fn)
282 282
283 ui.setconfig('patch', 'eol', 'auto') 283 ui.setconfig('patch', 'eol', 'auto', 'eol')
284 284
285 class eolrepo(repo.__class__): 285 class eolrepo(repo.__class__):
286 286
287 def loadeol(self, nodes): 287 def loadeol(self, nodes):
288 eol = parseeol(self.ui, self, nodes) 288 eol = parseeol(self.ui, self, nodes)