Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On 20/11/2014, 16:51 , Tom de Vries wrote: OK for trunk? This is fine. Thanks. Diego.
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
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 () { + 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 Peter Bergner * 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 () { + 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
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
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 () { > + 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. Segher
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On 09-05-14 16:47, Diego Novillo wrote: I would probably use git config directly here. It would work with both git and svn checkouts (if you have a global .git configuration). But testing for .git is fine with me as well. I like Peter's idea of having a ~/.mklog file to override. This would work for both svn and git checkouts. Diego, this patch implements both: - it uses the ~/.mklog file proposed by Peter - in absence of a ~/.mklog file, it uses git config, also when not in a git repository OK? Thanks, - Tom 2014-11-20 Tom de Vries Peter Bergner * 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..abbf0af 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 () { + 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
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On Mon, Apr 28, 2014 at 10:11 PM, wrote: > 2014-04-28 Trevor Saunders > > * mklog: if in a git checkout try to get name and email from git. > --- > contrib/mklog | 14 ++ > 1 file changed, 14 insertions(+) > > diff --git a/contrib/mklog b/contrib/mklog > index fb489b0..5f5d98e 100755 > --- a/contrib/mklog > +++ b/contrib/mklog > @@ -38,6 +38,20 @@ $gcc_root = $0; > $gcc_root =~ s/[^\\\/]+$/../; > chdir $gcc_root; > > +# if this is a git tree then take name and email from the git configuration > +if (-d .git) { I would probably use git config directly here. It would work with both git and svn checkouts (if you have a global .git configuration). But testing for .git is fine with me as well. I like Peter's idea of having a ~/.mklog file to override. This would work for both svn and git checkouts. Diego.
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
> > > +if (-d .git) { > > "-d .git" is, erm, not so great. > > yeah, the only reason I was willing to do it is the script already > requires being run at top level, but that annoys me too. That, but also it is equivalent to if ((-d $_)."git") { which is probably not what you wanted ;-) "use warnings" complains loudly and "use strict" plain refuses to compile this. > > How about something like > > It has the same issue that it'll activate ina svn checkout if you have > git configured, but I'm not sure that's a case worth caring about. If you have configured your name and email for git (for this repo or globally) it probably is the name/email you want to use, better than the finger output (but an override might be handy, dunno). Segher
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On Tue, 2014-04-29 at 10:39 -0500, seg...@kernel.crashing.org wrote: > > +# if this is a git tree then take name and email from the git configuration > > +if (-d .git) { > > + $gitname = `git config user.name`; > > + chomp($gitname); > > + if ($gitname) { > > + $name = $gitname; > > + } > > + > > + $gitaddr = `git config user.email`; > > + chomp($gitaddr); > > + if ($gitaddr) { > > + $addr = $gitaddr; > > + } > > +} > > "-d .git" is, erm, not so great. > > How about something like > > sub get_git_config { > my $res = `git config --get @_`; > return undef if $?; > chomp $res; > return $res; > } I've always used a hacked up version that reads a ~/.mklog config file for the name and email address to use. Ala: [bergner@otta ~]$ cat ~/.mklog NAME = Peter Bergner EMAIL = berg...@vnet.ibm.com my $conf = "$ENV{HOME}/.mklog"; if (-f "$conf") { open (CONF, "$conf") or die "Could not open file '$conf' for reading: $!\n"; while () { if (m/^\s*NAME\s*=\s*(.*)\s*$/) { $name = $1; } elsif (m/^\s*EMAIL\s*=\s*(.*)\s*$/) { $addr = $1; } } } Peter
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On Tue, Apr 29, 2014 at 10:39:00AM -0500, seg...@kernel.crashing.org wrote: > > +# if this is a git tree then take name and email from the git configuration > > +if (-d .git) { > > + $gitname = `git config user.name`; > > + chomp($gitname); > > + if ($gitname) { > > + $name = $gitname; > > + } > > + > > + $gitaddr = `git config user.email`; > > + chomp($gitaddr); > > + if ($gitaddr) { > > + $addr = $gitaddr; > > + } > > +} > > "-d .git" is, erm, not so great. yeah, the only reason I was willing to do it is the script already requires being run at top level, but that annoys me too. > How about something like It has the same issue that it'll activate ina svn checkout if you have git configured, but I'm not sure that's a case worth caring about. Trev > > sub get_git_config { > my $res = `git config --get @_`; > return undef if $?; > chomp $res; > return $res; > } > > > Segher signature.asc Description: Digital signature
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
> +# if this is a git tree then take name and email from the git configuration > +if (-d .git) { > + $gitname = `git config user.name`; > + chomp($gitname); > + if ($gitname) { > + $name = $gitname; > + } > + > + $gitaddr = `git config user.email`; > + chomp($gitaddr); > + if ($gitaddr) { > + $addr = $gitaddr; > + } > +} "-d .git" is, erm, not so great. How about something like sub get_git_config { my $res = `git config --get @_`; return undef if $?; chomp $res; return $res; } Segher
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On 04/29/2014 02:06 PM, Trevor Saunders wrote: +if (-d .git) { What about moving default name/addr (with finger, etc.) to else branch? Well, consider the case git doesn't know I wonder whether it's ok to force user to configure git before running mklog... -Y
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
On Tue, Apr 29, 2014 at 09:08:50AM +0400, Yury Gribov wrote: > Hi Trevor, > > I think this looks rather useful. sounds great! > > +if (-d .git) { > > What about moving default name/addr (with finger, etc.) to else branch? Well, consider the case git doesn't know, that said I could do if (-d .git) { // check git } if (!name) { // finger to get name } if (!email) { // finger stuff to get email } or something like that. Trev > > > + chomp($gitname); > > + chomp($gitaddr); > > Missing whites before (. > > -Y > signature.asc Description: Digital signature
Re: [PATCH 1/2] teach mklog to get name / email from git config when available
Hi Trevor, I think this looks rather useful. > +if (-d .git) { What about moving default name/addr (with finger, etc.) to else branch? > + chomp($gitname); > + chomp($gitaddr); Missing whites before (. -Y
[PATCH 1/2] teach mklog to get name / email from git config when available
From: Trevor Saunders Hi, finger gives the wrong data on my machines, and while I could fix it it seems nicer to use what's configured for the git repo we're in if any, that way you can use different defaults from the rest of the machine. Trev contrib/ChangeLog: 2014-04-28 Trevor Saunders * mklog: if in a git checkout try to get name and email from git. --- contrib/mklog | 14 ++ 1 file changed, 14 insertions(+) diff --git a/contrib/mklog b/contrib/mklog index fb489b0..5f5d98e 100755 --- a/contrib/mklog +++ b/contrib/mklog @@ -38,6 +38,20 @@ $gcc_root = $0; $gcc_root =~ s/[^\\\/]+$/../; chdir $gcc_root; +# if this is a git tree then take name and email from the git configuration +if (-d .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 -- 2.0.0.rc0