Mercurial > hg-stable
changeset 1473:7d66ce9895fa
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
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Thu, 27 Oct 2005 13:40:56 -0700 |
parents | 3c909a747d7f |
children | 1e47f6fc0fdc |
files | mercurial/hgweb.py mercurial/localrepo.py mercurial/ui.py tests/test-hgrc |
diffstat | 4 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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):
--- 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