diff options
author | Trent Piepho <xyzzy@speakeasy.org> | 2007-03-07 13:19:51 -0800 |
---|---|---|
committer | Trent Piepho <xyzzy@speakeasy.org> | 2007-03-07 13:19:51 -0800 |
commit | d0e1872ec50712d3deb16c479eda10b0c059ce35 (patch) | |
tree | 0aaa306251833631dcd4f832e6631cd3d510ab37 /v4l/scripts/prep_commit_msg.pl | |
parent | c4fc47ecf8b8c24cba992960b9e663107951385f (diff) | |
download | mediapointer-dvb-s2-d0e1872ec50712d3deb16c479eda10b0c059ce35.tar.gz mediapointer-dvb-s2-d0e1872ec50712d3deb16c479eda10b0c059ce35.tar.bz2 |
build: do a better job at parsing hgrc files
From: Trent Piepho <xyzzy@speakeasy.org>
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 <xyzzy@speakeasy.org>
Diffstat (limited to 'v4l/scripts/prep_commit_msg.pl')
-rwxr-xr-x | v4l/scripts/prep_commit_msg.pl | 27 |
1 files changed, 21 insertions, 6 deletions
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 (<IN>) { - 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 |