# 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 --git a/mercurial/hgweb.py b/mercurial/hgweb.py --- a/mercurial/hgweb.py +++ b/mercurial/hgweb.py @@ -990,7 +990,7 @@ class hgwebdir: 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 --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -43,7 +43,7 @@ class localrepository: 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 --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -15,7 +15,7 @@ class ui: 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 @@ class ui: 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 --git a/tests/test-hgrc b/tests/test-hgrc new file mode 100755 --- /dev/null +++ b/tests/test-hgrc @@ -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:"