From d0e1872ec50712d3deb16c479eda10b0c059ce35 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Wed, 7 Mar 2007 13:19:51 -0800 Subject: build: do a better job at parsing hgrc files From: Trent Piepho When parsing hgrc files, don't get confused by 'username' appearing in other sections, like [smtp]. Check the repo's hgrc file first, then ~/.hgrc Signed-off-by: Trent Piepho --- v4l/scripts/prep_commit_msg.pl | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'v4l') diff --git a/v4l/scripts/prep_commit_msg.pl b/v4l/scripts/prep_commit_msg.pl index a4594c7f9..f4047c6ba 100755 --- a/v4l/scripts/prep_commit_msg.pl +++ b/v4l/scripts/prep_commit_msg.pl @@ -5,16 +5,31 @@ my $autopatch = shift; # Get Hg username from environment my $user = $ENV{HGUSER}; -# Didn't work? Try the .hgrc file -if ($user eq "") { - open IN, "<$ENV{HOME}/.hgrc"; +sub hgrcuser($) +{ + my $file = shift; + my $ui = 0; + open IN, '<', $file; while () { - if(/^\s*username\s*=\s*(\S.*)$/) { - $user = $1; - last; + $ui = 1 if (/^\s*\[ui\]/); + if ($ui && /^\s*username\s*=\s*(\S.*?)\s*$/) { + close IN; + return($1); } } close IN; + return(""); +} + +# Didn't work? Try the repo's .hgrc file +if ($user eq "") { + my $hgroot = `hg root`; + chomp($hgroot); + $user = hgrcuser("$hgroot/.hg/hgrc"); +} +# Ok, try ~/.hgrc next +if ($user eq "") { + $user = hgrcuser("$ENV{HOME}/.hgrc"); } # Still no luck? Try some other environment variables -- cgit v1.2.3