[PATCH] ui.username(): expand environment variables in username configuration value

Chad Dombrova chadrik at gmail.com
Wed May 26 16:06:13 CDT 2010


# HG changeset patch
# User Chad Dombrova <chadrik at gmail.com>
# Date 1274907809 25200
# Branch stable
# Node ID ebf02a667205db330bda984d832c5799f6a29c9f
# Parent  23b20efd76df212a8d1ac4b07e1493dfc576f9bf
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.

diff -r 23b20efd76df -r ebf02a667205 mercurial/ui.py
--- a/mercurial/ui.py	Wed May 26 14:03:29 2010 -0700
+++ b/mercurial/ui.py	Wed May 26 14:03:29 2010 -0700
@@ -194,6 +194,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"):
diff -r 23b20efd76df -r ebf02a667205 tests/test-hgrc
--- 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"
+FAKEUSER='John Doe'
+export FAKEUSER
+echo "[ui]" > $HGRCPATH
+echo "username=\$FAKEUSER" >> $HGRCPATH
+unset FAKEPATH
+
+user=$HGUSER
+unset HGUSER
+hg init usertest
+cd usertest
+touch bar
+hg add bar --quiet
+hg commit --quiet -m "added bar"
+hg log -r0 --template "{author}\n"
+cd ..
+
+hg showconfig | sed -e "s:$p:...:"
+
+unset FAKEUSER
+HGUSER=$user;export HGUSER
+
 # HGPLAIN
 cd ..
 p=`pwd`
diff -r 23b20efd76df -r ebf02a667205 tests/test-hgrc.out
--- 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
 .../.hgrc:13: alias.log=log -g
 .../.hgrc:11: defaults.identify=-n


More information about the Mercurial-devel mailing list