From: idl0r Date: Thu, 30 Apr 2009 21:30:51 +0000 (-0000) Subject: Added support for project-wide variables as suggested in bug 213374. Improved environ... X-Git-Tag: gentoolkit-0.3.0_rc5~31 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cc661f5099f33d2db8586680950ae883c7d7cc8d;p=gentoolkit.git Added support for project-wide variables as suggested in bug 213374. Improved environment handling. svn path=/; revision=561 --- diff --git a/trunk/src/echangelog/echangelog b/trunk/src/echangelog/echangelog index fea1af6..c267c28 100755 --- a/trunk/src/echangelog/echangelog +++ b/trunk/src/echangelog/echangelog @@ -76,6 +76,19 @@ sub version { exit 0; } +sub getenv($) { + my $key = shift; + + # Ensure our variable exist + if ( defined($ENV{$key}) ) { + # Ensure we don't get empty variables + if ( length($ENV{$key}) > 0 ) { + return $ENV{$key}; + } + } + return undef; +} + GetOptions( 'help' => \$opt_help, 'strict' => \$opt_strict, @@ -450,10 +463,8 @@ unless (@files) { if ($ARGV[0]) { $input = "@ARGV"; } else { - # Testing for defined() allows ECHANGELOG_EDITOR='' to cancel EDITOR - $editor = defined($ENV{'ECHANGELOG_EDITOR'}) ? $ENV{'ECHANGELOG_EDITOR'} : - $ENV{'EDITOR'} || undef; - + $editor = getenv('ECHANGELOG_EDITOR') ? getenv('ECHANGELOG_EDITOR') : getenv('EDITOR') || undef; + if ($editor) { system("$editor ChangeLog.new"); @@ -474,7 +485,7 @@ if ($ARGV[0]) { undef $editor; } - unlink 'ChangeLog.new'; + unlink('ChangeLog.new') if -f 'ChangeLog.new'; } } @@ -492,10 +503,25 @@ $input =~ s/^\s*(.*?)\s*\z/$1/s; # trim whitespace $input = Text::Wrap::fill(' ', ' ', $input); # Prepend the user info to the input -unless ($user = $ENV{'ECHANGELOG_USER'}) { +# Changes related to bug 213374; +# This sequence should be right: +# 1. GENTOO_COMMITTER_NAME && GENTOO_COMMITTER_EMAIL +# 2. GENTOO_AUTHOR_NAME && GENTOO_AUTHOR_EMAIL +# 3. ECHANGELOG_USER (fallback/obsolete?) +# 4. getpwuid().. +if ( getenv("GENTOO_COMMITTER_NAME") && getenv("GENTOO_COMMITTER_EMAIL") ) { + $user = sprintf("%s <%s>", getenv("GENTOO_COMMITTER_NAME"), getenv("GENTOO_COMMITTER_EMAIL")); +} +elsif ( getenv("GENTOO_AUTHOR_NAME") && getenv("GENTOO_AUTHOR_EMAIL") ) { + $user = sprintf("%s <%s>", getenv("GENTOO_AUTHOR_NAME"), getenv("GENTOO_AUTHOR_EMAIL")); +} +elsif ( getenv("ECHANGELOG_USER") ) { + $user = getenv("ECHANGELOG_USER"); +} +else { my ($fullname, $username) = (getpwuid($<))[6,0]; - $fullname =~ s/,.*//; # remove GECOS, bug 80011 - $user = sprintf "%s <%s\@gentoo.org>", $fullname, $username; + $fullname =~ s/,.*//; # remove GECOS, bug 80011 + $user = sprintf('%s <%s@gentoo.org>', $fullname, $username); } # Make sure that we didn't get "root"