changeset 11225:d6dbd5e4ee72

ui.username(): expand environment variables in username configuration value. note: expansion of config variables must be handled on a case-by-case basis because they can contain arbitrary data that may not be desirable to expand.
author Chad Dombrova <chadrik@gmail.com>
date Wed, 26 May 2010 14:03:29 -0700
parents f23f87462c18
children b9e89fc5c7f1
files mercurial/ui.py tests/test-hgrc tests/test-hgrc.out
diffstat 3 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Wed May 26 14:03:29 2010 -0700
+++ b/mercurial/ui.py	Wed May 26 14:03:29 2010 -0700
@@ -266,6 +266,8 @@
         user = os.environ.get("HGUSER")
         if user is None:
             user = self.config("ui", "username")
+            if user is not None:
+                user = os.path.expandvars(user)
         if user is None:
             user = os.environ.get("EMAIL")
         if user is None and self.configbool("ui", "askusername"):
--- a/tests/test-hgrc	Wed May 26 14:03:29 2010 -0700
+++ b/tests/test-hgrc	Wed May 26 14:03:29 2010 -0700
@@ -29,6 +29,28 @@
 hg version 2>&1 | sed -e "s|$HGRCPATH|\$HGRCPATH|"
 unset FAKEPATH
 
+echo "% username expansion"
+olduser=$HGUSER
+unset HGUSER
+
+FAKEUSER='John Doe'
+export FAKEUSER
+echo '[ui]' > $HGRCPATH
+echo 'username = $FAKEUSER' >> $HGRCPATH
+
+hg init usertest
+cd usertest
+touch bar
+hg commit --addremove --quiet -m "added bar"
+hg log --template "{author}\n"
+cd ..
+
+hg showconfig | sed -e "s:$p:...:"
+
+unset FAKEUSER
+HGUSER=$olduser
+export HGUSER
+
 # HGPLAIN
 cd ..
 p=`pwd`
--- a/tests/test-hgrc.out	Wed May 26 14:03:29 2010 -0700
+++ b/tests/test-hgrc.out	Wed May 26 14:03:29 2010 -0700
@@ -10,6 +10,9 @@
 foo.bar=a\nb\nc\nde\nfg
 foo.baz=bif cb
 hg: config error at $HGRCPATH:1: cannot include /path/to/nowhere/no-such-file (No such file or directory)
+% username expansion
+John Doe
+ui.username=$FAKEUSER
 % customized hgrc
 read config from: .../.hgrc
 .../.hgrc:13: alias.log=log -g