diff --git a/mercurial/help/environment.txt b/mercurial/help/environment.txt --- a/mercurial/help/environment.txt +++ b/mercurial/help/environment.txt @@ -59,6 +59,14 @@ HGPLAIN Equivalent options set via command line flags or environment variables are not overridden. +HGPLAINEXCEPT + This is a comma-separated list of features to preserve when + HGPLAIN is enabled. Currently the only value supported is "i18n", + which preserves internationalization in plain mode. + + Setting HGPLAINEXCEPT to anything (even an empty string) will + enable plain mode. + HGUSER This is the string used as the author of a commit. If not set, available values will be considered in this order: diff --git a/mercurial/i18n.py b/mercurial/i18n.py --- a/mercurial/i18n.py +++ b/mercurial/i18n.py @@ -51,7 +51,13 @@ def gettext(message): # An unknown encoding results in a LookupError. return message -if 'HGPLAIN' in os.environ: +def _plain(): + if 'HGPLAIN' not in os.environ and 'HGPLAINEXCEPT' not in os.environ: + return False + exceptions = os.environ.get('HGPLAINEXCEPT', '').strip().split(',') + return 'i18n' not in exceptions + +if _plain(): _ = lambda message: message else: _ = gettext diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -278,15 +278,22 @@ class ui(object): def plain(self): '''is plain mode active? - Plain mode means that all configuration variables which affect the - behavior and output of Mercurial should be ignored. Additionally, the - output should be stable, reproducible and suitable for use in scripts or - applications. + Plain mode means that all configuration variables which affect + the behavior and output of Mercurial should be + ignored. Additionally, the output should be stable, + reproducible and suitable for use in scripts or applications. + + The only way to trigger plain mode is by setting either the + `HGPLAIN' or `HGPLAINEXCEPT' environment variables. - The only way to trigger plain mode is by setting the `HGPLAIN' - environment variable. + 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). ''' - return 'HGPLAIN' in os.environ + 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 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 @@ -133,3 +133,39 @@ plain hgrc none: ui.verbose=False none: ui.debug=True none: ui.quiet=False + +plain mode with exceptions + + $ cat > plain.py < def uisetup(ui): + > ui.write('plain: %r\n' % ui.plain()) + > EOF + $ echo "[extensions]" >> $HGRCPATH + $ echo "plain=./plain.py" >> $HGRCPATH + $ HGPLAINEXCEPT=; export HGPLAINEXCEPT + $ hg showconfig --config ui.traceback=True --debug + plain: [''] + read config from: $TESTTMP/hgrc + $TESTTMP/hgrc:15: extensions.plain=./plain.py + none: ui.traceback=True + none: ui.verbose=False + none: ui.debug=True + none: ui.quiet=False + $ unset HGPLAIN + $ hg showconfig --config ui.traceback=True --debug + plain: [''] + read config from: $TESTTMP/hgrc + $TESTTMP/hgrc:15: extensions.plain=./plain.py + none: ui.traceback=True + none: ui.verbose=False + none: ui.debug=True + none: ui.quiet=False + $ HGPLAINEXCEPT=i18n; export HGPLAINEXCEPT + $ hg showconfig --config ui.traceback=True --debug + plain: ['i18n'] + read config from: $TESTTMP/hgrc + $TESTTMP/hgrc:15: extensions.plain=./plain.py + none: ui.traceback=True + none: ui.verbose=False + none: ui.debug=True + none: ui.quiet=False