# HG changeset patch # User "Yann E. MORIN" # Date 1305583731 -7200 # Node ID be0daa0eeb3ebc553f2bab6deb1f92697a451eb2 # Parent ec2aae8b375dd6a89bbf72a387965b689dd24bd8 ui: test plain mode against exceptions Let ui.plain() accept an optional parameter in the form of a feature name (as a string) to exclude from plain mode. The result of ui.plain is now: - False if HGPLAIN is not set or the requested feature is in HGPLAINEXCEPT - True otherwise Signed-off-by: "Yann E. MORIN" diff -r ec2aae8b375d -r be0daa0eeb3e mercurial/ui.py --- a/mercurial/ui.py Wed May 18 17:05:30 2011 -0500 +++ b/mercurial/ui.py Tue May 17 00:08:51 2011 +0200 @@ -330,7 +330,7 @@ for name, value in self.configitems(section, untrusted): yield section, name, value - def plain(self): + def plain(self, feature=None): '''is plain mode active? Plain mode means that all configuration variables which affect @@ -341,14 +341,16 @@ The only way to trigger plain mode is by setting either the `HGPLAIN' or `HGPLAINEXCEPT' environment variables. - The return value can either be False, True, or a list of - features that plain mode should not apply to (e.g., i18n, - progress, etc). + The return value can either be + - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT + - True otherwise ''' if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in os.environ: return False exceptions = os.environ.get('HGPLAINEXCEPT', '').strip().split(',') - return exceptions or True + if feature and exceptions: + return feature not in exceptions + return True def username(self): """Return default username to be used in commits. diff -r ec2aae8b375d -r be0daa0eeb3e tests/test-hgrc.t --- a/tests/test-hgrc.t Wed May 18 17:05:30 2011 -0500 +++ b/tests/test-hgrc.t Tue May 17 00:08:51 2011 +0200 @@ -144,7 +144,7 @@ $ echo "plain=./plain.py" >> $HGRCPATH $ HGPLAINEXCEPT=; export HGPLAINEXCEPT $ hg showconfig --config ui.traceback=True --debug - plain: [''] + plain: True read config from: $TESTTMP/hgrc $TESTTMP/hgrc:15: extensions.plain=./plain.py none: ui.traceback=True @@ -153,7 +153,7 @@ none: ui.quiet=False $ unset HGPLAIN $ hg showconfig --config ui.traceback=True --debug - plain: [''] + plain: True read config from: $TESTTMP/hgrc $TESTTMP/hgrc:15: extensions.plain=./plain.py none: ui.traceback=True @@ -162,7 +162,7 @@ none: ui.quiet=False $ HGPLAINEXCEPT=i18n; export HGPLAINEXCEPT $ hg showconfig --config ui.traceback=True --debug - plain: ['i18n'] + plain: True read config from: $TESTTMP/hgrc $TESTTMP/hgrc:15: extensions.plain=./plain.py none: ui.traceback=True