# HG changeset patch # User "Yann E. MORIN" # Date 2011-05-16 22:08:51 # 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 --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -330,7 +330,7 @@ class ui(object): 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 @@ class ui(object): 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 --git a/tests/test-hgrc.t b/tests/test-hgrc.t --- a/tests/test-hgrc.t +++ b/tests/test-hgrc.t @@ -144,7 +144,7 @@ plain mode with exceptions $ 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 @@ plain mode with exceptions 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 @@ plain mode with exceptions 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