[PATCH] ui: add HGPLAIN environment variable for easier scripting
Brodie Rao
dackze at gmail.com
Sat Feb 13 23:35:13 CST 2010
# HG changeset patch
# User Brodie Rao <me+hg at dackz.net>
# Date 1265550978 -3600
# Node ID 2e441e9c4287e3fd8721c4f53be94f68a124743e
# Parent 6e5a47398fc5a56de732b31fdc7d8b5a7cd6ee11
ui: add HGPLAIN environment variable for easier scripting
If HGPLAIN is set, the following settings are ignored when read from
hgrc files:
- ui.debug
- ui.fallbackencoding
- ui.quiet
- ui.traceback
- ui.verbose
- defaults.*
Localization is also disabled.
Equivalent options set via command line are honored.
diff --git a/mercurial/help/environment.txt b/mercurial/help/environment.txt
--- a/mercurial/help/environment.txt
+++ b/mercurial/help/environment.txt
@@ -42,6 +42,16 @@ HGRCPATH
- if it's a directory, all files ending with .rc are added
- otherwise, the file itself will be added
+HGPLAIN
+ When set, this disables any options in .hgrc that might change
+ Mercurial's default output. This includes encoding, defaults,
+ verbose mode, debug mode, quiet mode, tracebacks, and
+ localization. This can be useful when scripting against Mercurial
+ in the face of existing user configuration.
+
+ Equivalent options set via command line flags or environment
+ variables are not overridden.
+
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
@@ -48,5 +48,8 @@ def gettext(message):
# An unknown encoding results in a LookupError.
return message
-_ = gettext
+if 'HGPLAIN' in os.environ:
+ _ = lambda message: message
+else:
+ _ = gettext
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -79,6 +79,14 @@ class ui(object):
raise
self.warn(_("Ignored: %s\n") % str(inst))
+ if self.plain():
+ for k in ('debug', 'fallbackencoding', 'quiet', 'traceback',
+ 'verbose'):
+ if k in cfg['ui']:
+ del cfg['ui'][k]
+ for k, v in cfg.items('defaults'):
+ del cfg['defaults'][k]
+
if trusted:
self._tcfg.update(cfg)
self._tcfg.update(self._ocfg)
@@ -169,6 +177,9 @@ class ui(object):
for name, value in self.configitems(section, untrusted):
yield section, name, str(value).replace('\n', '\\n')
+ def plain(self):
+ return 'HGPLAIN' in os.environ
+
def username(self):
"""Return default username to be used in commits.
diff --git a/tests/test-hgrc b/tests/test-hgrc
--- a/tests/test-hgrc
+++ b/tests/test-hgrc
@@ -25,3 +25,22 @@ hg showconfig foo
echo '%include /no-such-file' > $HGRCPATH
hg version 2>&1 | sed -e "s|$HGRCPATH|\$HGRCPATH|"
+
+# HGPLAIN
+cd ..
+p=`pwd`
+echo "[ui]" > $HGRCPATH
+echo "debug=true" >> $HGRCPATH
+echo "fallbackencoding=ASCII" >> $HGRCPATH
+echo "quiet=true" >> $HGRCPATH
+echo "traceback=true" >> $HGRCPATH
+echo "verbose=true" >> $HGRCPATH
+echo "[defaults]" >> $HGRCPATH
+echo "identify=-n" >> $HGRCPATH
+
+echo '% customized hgrc'
+hg showconfig | sed -e "s:$p:...:"
+
+echo '% plain hgrc'
+HGPLAIN=; export HGPLAIN
+hg showconfig --config ui.traceback=True --debug | sed -e "s:$p:...:"
diff --git a/tests/test-hgrc.out b/tests/test-hgrc.out
--- a/tests/test-hgrc.out
+++ b/tests/test-hgrc.out
@@ -10,3 +10,15 @@ hg: config error at $HGRCPATH:2: ' x =
foo.bar=a\nb\nc\nde\nfg
foo.baz=bif cb
hg: config error at $HGRCPATH:1: cannot include /no-such-file (No such file or directory)
+% customized hgrc
+.../.hgrc:8: defaults.identify=-n
+.../.hgrc:2: ui.debug=true
+.../.hgrc:3: ui.fallbackencoding=ASCII
+.../.hgrc:4: ui.quiet=true
+.../.hgrc:5: ui.traceback=true
+.../.hgrc:6: ui.verbose=true
+% plain hgrc
+none: ui.traceback=True
+none: ui.verbose=False
+none: ui.debug=True
+none: ui.quiet=False
More information about the Mercurial-devel
mailing list