Mercurial > hg-stable
changeset 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 |
files | hgext/eol.py |
diffstat | 1 files changed, 20 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/eol.py Sun Mar 13 15:07:44 2011 +0100 +++ b/hgext/eol.py Sun Mar 13 15:07:44 2011 +0100 @@ -166,17 +166,23 @@ ui.warn(_("ignoring unknown EOL style '%s' from %s\n") % (style, self.cfg.source('patterns', pattern))) -def parseeol(ui, repo, node=None): +def parseeol(ui, repo, nodes): try: - if node is None: - # Cannot use workingctx.data() since it would load - # and cache the filters before we configure them. - data = repo.wfile('.hgeol').read() - else: - data = repo[node]['.hgeol'].data() - return eolfile(ui, repo.root, data) - except (IOError, LookupError): - return None + for node in nodes: + try: + if node is None: + # Cannot use workingctx.data() since it would load + # and cache the filters before we configure them. + data = repo.wfile('.hgeol').read() + else: + data = repo[node]['.hgeol'].data() + return eolfile(ui, repo.root, data) + except (IOError, LookupError): + pass + except error.ParseError, inst: + ui.warn(_("warning: ignoring .hgeol file due to parse error " + "at %s: %s\n") % (inst.args[1], inst.args[0])) + return None def hook(ui, repo, node, hooktype, **kwargs): """verify that files have expected EOLs""" @@ -202,11 +208,7 @@ def preupdate(ui, repo, hooktype, parent1, parent2): #print "preupdate for %s: %s -> %s" % (repo.root, parent1, parent2) - try: - repo.loadeol(parent1) - except error.ParseError, inst: - ui.warn(_("warning: ignoring .hgeol file due to parse error " - "at %s: %s\n") % (inst.args[1], inst.args[0])) + repo.loadeol([parent1]) return False def uisetup(ui): @@ -234,21 +236,15 @@ class eolrepo(repo.__class__): - def loadeol(self, node=None): - eol = parseeol(self.ui, self, node) + def loadeol(self, nodes): + eol = parseeol(self.ui, self, nodes) if eol is None: return None eol.setfilters(self.ui) return eol.match def _hgcleardirstate(self): - try: - self._eolfile = (self.loadeol() or self.loadeol('tip')) - except error.ParseError, inst: - ui.warn(_("warning: ignoring .hgeol file due to parse error " - "at %s: %s\n") % (inst.args[1], inst.args[0])) - self._eolfile = None - + self._eolfile = self.loadeol([None, 'tip']) if not self._eolfile: self._eolfile = util.never return