[PATCH] ui: make readsections() abort when configuration cannot be read

Alexis S. L. Carvalho alexis at cecm.usp.br
Sun Jun 3 12:32:33 CDT 2007


Thus spake Patrick Mezard:
> # HG changeset patch
> # User Patrick Mezard <pmezard at gmail.com>
> # Date 1180887381 -7200
> # Node ID fdd57d2516715df4ab5d83a9a0b70d4dd0339b70
> # Parent  41fb67578b36137e4025b011e9ae8814509fbf37
> ui: make readsections() abort when configuration cannot be read.
> 
> diff -r 41fb67578b36 -r fdd57d251671 mercurial/ui.py
> --- a/mercurial/ui.py	Thu May 24 16:32:38 2007 +0200
> +++ b/mercurial/ui.py	Sun Jun 03 18:16:21 2007 +0200
> @@ -170,7 +170,9 @@ class ui(object):
>  
>          cdata = util.configparser()
>          try:
> -            cdata.read(filename)
> +            read = cdata.read(filename)
> +            if not read:
> +                raise util.Abort(_("failed to open %s") % filename)
>          except ConfigParser.ParsingError, inst:
>              raise util.Abort(_("failed to parse %s\n%s") % (filename,
>                                                              inst))

This won't work on python 2.3 (ConfigParser.read always returns None).
You can manually open the file (aborting if something bad happens) and
pass it to readfp.  This also allows us to print a nicer error message.

(And there was no great reason for ignoring errors here - it was just
the ConfigParser default.)

> diff -r 41fb67578b36 -r fdd57d251671 tests/test-notify
> --- a/tests/test-notify	Thu May 24 16:32:38 2007 +0200
> +++ b/tests/test-notify	Sun Jun 03 18:16:21 2007 +0200
> @@ -48,6 +48,8 @@ baseurl = http://test/
>  baseurl = http://test/
>  EOF
>  
> +touch $HGTMP/.notify.conf
> +
>  echo % pull
>  hg --cwd b rollback
>  hg --traceback --cwd b pull ../a 2>&1 | sed -e 's/\(Message-Id:\).*/\1/' \

Can you move the rollback and add a pull before creating the file?  This
way we have a test that the abort actually happens.  And it'd be good to
add quotes around $HGTMP, just in case.

Alexis


More information about the Mercurial-devel mailing list