Message ID | 1398737468-6981-2-git-send-email-tsaunders@mozilla.com |
---|---|
State | New |
Headers | show |
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
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 >
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
> +# 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
On Tue, Apr 29, 2014 at 10:39:00AM -0500, segher@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
On Tue, 2014-04-29 at 10:39 -0500, segher@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 = bergner@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 (<CONF>) { if (m/^\s*NAME\s*=\s*(.*)\s*$/) { $name = $1; } elsif (m/^\s*EMAIL\s*=\s*(.*)\s*$/) { $addr = $1; } } } Peter
> > > +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
On Mon, Apr 28, 2014 at 10:11 PM, <tsaunders@mozilla.com> wrote: > 2014-04-28 Trevor Saunders <tbsaunde@mozilla.com> > > * 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.
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
From: Trevor Saunders <tbsaunde@mozilla.com> 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 <tbsaunde@mozilla.com> * mklog: if in a git checkout try to get name and email from git. --- contrib/mklog | 14 ++++++++++++++ 1 file changed, 14 insertions(+)