# HG changeset patch # User Benoit Boissinot # Date 1130445656 25200 # Node ID 7d66ce9895fae9fd318f478015acb4ec64735ab8 # Parent 3c909a747d7f0417dec30b7507814401b6862405 make readconfig take a filename instead of a file pointer as argument catch parse error while reading a config file add a testcase for parse error diff -r 3c909a747d7f -r 7d66ce9895fa mercurial/hgweb.py --- a/mercurial/hgweb.py Thu Oct 27 13:31:12 2005 -0700 +++ b/mercurial/hgweb.py Thu Oct 27 13:40:56 2005 -0700 @@ -990,7 +990,7 @@ for name, path in self.repos: u = ui.ui() try: - u.readconfig(file(os.path.join(path, '.hg', 'hgrc'))) + u.readconfig(os.path.join(path, '.hg', 'hgrc')) except IOError: pass get = u.config diff -r 3c909a747d7f -r 7d66ce9895fa mercurial/localrepo.py --- a/mercurial/localrepo.py Thu Oct 27 13:31:12 2005 -0700 +++ b/mercurial/localrepo.py Thu Oct 27 13:40:56 2005 -0700 @@ -43,7 +43,7 @@ self.dirstate = dirstate.dirstate(self.opener, ui, self.root) try: - self.ui.readconfig(self.opener("hgrc")) + self.ui.readconfig(os.path.join(self.path, "hgrc")) except IOError: pass def hook(self, name, **args): diff -r 3c909a747d7f -r 7d66ce9895fa mercurial/ui.py --- a/mercurial/ui.py Thu Oct 27 13:31:12 2005 -0700 +++ b/mercurial/ui.py Thu Oct 27 13:40:56 2005 -0700 @@ -15,7 +15,7 @@ interactive=True): self.overlay = {} self.cdata = ConfigParser.SafeConfigParser() - self.cdata.read(util.rcpath) + self.readconfig(util.rcpath) self.quiet = self.configbool("ui", "quiet") self.verbose = self.configbool("ui", "verbose") @@ -31,8 +31,11 @@ self.debugflag = (self.debugflag or debug) self.interactive = (self.interactive and interactive) - def readconfig(self, fp): - self.cdata.readfp(fp) + def readconfig(self, fn): + try: + self.cdata.read(fn) + except ConfigParser.ParsingError, inst: + raise util.Abort(_("Failed to parse %s\n%s") % (fn, inst)) def setconfig(self, section, name, val): self.overlay[(section, name)] = val diff -r 3c909a747d7f -r 7d66ce9895fa tests/test-hgrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-hgrc Thu Oct 27 13:40:56 2005 -0700 @@ -0,0 +1,7 @@ +#!/bin/sh + +mkdir t +cd t +hg init +echo "invalid" > .hg/hgrc +hg status 2>&1 |sed -e "s:/.*\(/t/.*\):...\1:"