On 20-11-14 17:43, Segher Boessenkool wrote:
On Thu, Nov 20, 2014 at 05:22:20PM +0100, Tom de Vries wrote:+my $conf = "$ENV{HOME}/.mklog"; +if (-f "$conf") { + open (CONF, "$conf") + or die "Could not open file '$conf' for reading: $!\n"; + while (<CONF>) { + if (m/^\s*NAME\s*=\s*(.*)\s*$/) {The final \s* never matches anything since the .* gobbles up everything. Use .*? if you really want to get rid of the trailing whitespace.
Thanks for spotting that, patch updated. OK for trunk? Thanks, - Tom
Segher
2014-11-20 Tom de Vries <[email protected]> Peter Bergner <[email protected]> * mklog: Handle .mklog. Use git setting independent of presence .git directory. --- contrib/mklog | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/contrib/mklog b/contrib/mklog index 840f6f8..f7974a7 100755 --- a/contrib/mklog +++ b/contrib/mklog @@ -29,32 +29,46 @@ use File::Temp; use File::Copy qw(cp mv); -# Change these settings to reflect your profile. -$username = $ENV{'USER'}; -$name = `finger $username | grep -o 'Name: .*'`; -@n = split(/: /, $name); -$name = $n[1]; chop($name); -$addr = $username . "\@my.domain.org"; $date = `date +%Y-%m-%d`; chop ($date); +$dot_mklog_format_msg = + "The .mklog format is:\n" + . "NAME = ...\n" + . "EMAIL = ...\n"; + +# Create a .mklog to reflect your profile, if necessary. +my $conf = "$ENV{HOME}/.mklog"; +if (-f "$conf") { + open (CONF, "$conf") + or die "Could not open file '$conf' for reading: $!\n"; + while (<CONF>) { + if (m/^\s*NAME\s*=\s*(.*?)\s*$/) { + $name = $1; + } elsif (m/^\s*EMAIL\s*=\s*(.*?)\s*$/) { + $addr = $1; + } + } + if (!($name && $addr)) { + die "Could not read .mklog settings.\n" + . $dot_mklog_format_msg; + } +} else { + $name = `git config user.name`; + chomp($name); + $addr = `git config user.email`; + chomp($addr); + + if (!($name && $addr)) { + die "Could not read git user.name and user.email settings.\n" + . "Please add missing git settings, or create a .mklog file in" + . " $ENV{HOME}.\n" + . $dot_mklog_format_msg; + } +} + $gcc_root = $0; $gcc_root =~ s/[^\\\/]+$/../; -# if this is a git tree then take name and email from the git configuration -if (-d "$gcc_root/.git") { - $gitname = `git config user.name`; - chomp($gitname); - if ($gitname) { - $name = $gitname; - } - - $gitaddr = `git config user.email`; - chomp($gitaddr); - if ($gitaddr) { - $addr = $gitaddr; - } -} - #----------------------------------------------------------------------------- # Program starts here. You should not need to edit anything below this # line. -- 1.9.1
