ui.username(): expand environment variables in username configuration value.
authorChad Dombrova <chadrik@gmail.com>
Wed, 26 May 2010 14:03:29 -0700
changeset 11225 d6dbd5e4ee72
parent 11224 f23f87462c18
child 11226 b9e89fc5c7f1
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.
mercurial/ui.py
tests/test-hgrc
tests/test-hgrc.out
--- 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