comparison hgext/eol.py @ 13614:40d0cf79cb2c

eol: extract parsing error handling in parseeol()
author Patrick Mezard <pmezard@gmail.com>
date Sun, 13 Mar 2011 15:07:44 +0100
parents 85b80261ca10
children 686dec753b52
comparison
equal deleted inserted replaced
13613:85b80261ca10 13614:40d0cf79cb2c
164 ui.setconfig('encode', pattern, self._encode[key]) 164 ui.setconfig('encode', pattern, self._encode[key])
165 except KeyError: 165 except KeyError:
166 ui.warn(_("ignoring unknown EOL style '%s' from %s\n") 166 ui.warn(_("ignoring unknown EOL style '%s' from %s\n")
167 % (style, self.cfg.source('patterns', pattern))) 167 % (style, self.cfg.source('patterns', pattern)))
168 168
169 def parseeol(ui, repo, node=None): 169 def parseeol(ui, repo, nodes):
170 try: 170 try:
171 if node is None: 171 for node in nodes:
172 # Cannot use workingctx.data() since it would load 172 try:
173 # and cache the filters before we configure them. 173 if node is None:
174 data = repo.wfile('.hgeol').read() 174 # Cannot use workingctx.data() since it would load
175 else: 175 # and cache the filters before we configure them.
176 data = repo[node]['.hgeol'].data() 176 data = repo.wfile('.hgeol').read()
177 return eolfile(ui, repo.root, data) 177 else:
178 except (IOError, LookupError): 178 data = repo[node]['.hgeol'].data()
179 return None 179 return eolfile(ui, repo.root, data)
180 except (IOError, LookupError):
181 pass
182 except error.ParseError, inst:
183 ui.warn(_("warning: ignoring .hgeol file due to parse error "
184 "at %s: %s\n") % (inst.args[1], inst.args[0]))
185 return None
180 186
181 def hook(ui, repo, node, hooktype, **kwargs): 187 def hook(ui, repo, node, hooktype, **kwargs):
182 """verify that files have expected EOLs""" 188 """verify that files have expected EOLs"""
183 files = set() 189 files = set()
184 for rev in xrange(repo[node].rev(), len(repo)): 190 for rev in xrange(repo[node].rev(), len(repo)):
200 break 206 break
201 207
202 208
203 def preupdate(ui, repo, hooktype, parent1, parent2): 209 def preupdate(ui, repo, hooktype, parent1, parent2):
204 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) 210 #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2)
205 try: 211 repo.loadeol([parent1])
206 repo.loadeol(parent1)
207 except error.ParseError, inst:
208 ui.warn(_("warning: ignoring .hgeol file due to parse error "
209 "at %s: %s\n") % (inst.args[1], inst.args[0]))
210 return False 212 return False
211 213
212 def uisetup(ui): 214 def uisetup(ui):
213 ui.setconfig('hooks', 'preupdate.eol', preupdate) 215 ui.setconfig('hooks', 'preupdate.eol', preupdate)
214 216
232 234
233 ui.setconfig('patch', 'eol', 'auto') 235 ui.setconfig('patch', 'eol', 'auto')
234 236
235 class eolrepo(repo.__class__): 237 class eolrepo(repo.__class__):
236 238
237 def loadeol(self, node=None): 239 def loadeol(self, nodes):
238 eol = parseeol(self.ui, self, node) 240 eol = parseeol(self.ui, self, nodes)
239 if eol is None: 241 if eol is None:
240 return None 242 return None
241 eol.setfilters(self.ui) 243 eol.setfilters(self.ui)
242 return eol.match 244 return eol.match
243 245
244 def _hgcleardirstate(self): 246 def _hgcleardirstate(self):
245 try: 247 self._eolfile = self.loadeol([None, 'tip'])
246 self._eolfile = (self.loadeol() or self.loadeol('tip'))
247 except error.ParseError, inst:
248 ui.warn(_("warning: ignoring .hgeol file due to parse error "
249 "at %s: %s\n") % (inst.args[1], inst.args[0]))
250 self._eolfile = None
251
252 if not self._eolfile: 248 if not self._eolfile:
253 self._eolfile = util.never 249 self._eolfile = util.never
254 return 250 return
255 251
256 try: 252 try: