Skip to content
Snippets Groups Projects
Commit 9f97de15 authored by Brodie Rao's avatar Brodie Rao
Browse files

HGPLAIN: allow exceptions to plain mode, like i18n, via HGPLAINEXCEPT

This makes it possible to gain the benefits of HGPLAIN for scripting
while preserving different behaviors like internationalization.
parent b2798c1d
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,14 @@
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:
......
......@@ -51,7 +51,13 @@
# 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
......
......@@ -278,8 +278,11 @@
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.
......@@ -285,4 +288,5 @@
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).
'''
......@@ -288,5 +292,8 @@
'''
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.
......
......@@ -133,3 +133,39 @@
none: ui.verbose=False
none: ui.debug=True
none: ui.quiet=False
plain mode with exceptions
$ cat > plain.py <<EOF
> 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment