From 67d873c012d18d93c7af88408c31b0406e043ccd Mon Sep 17 00:00:00 2001 From: Francesco Salvestrini Date: Mon, 15 Sep 2008 22:58:26 +0200 Subject: [PATCH] Added gitlog-to-committers script --- .gitignore | 2 + configure.ac.in | 3 +- tools/maint/Makefile.am | 15 ++-- tools/maint/gitlog-to-committers.in | 135 ++++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 12 deletions(-) create mode 100644 tools/maint/gitlog-to-committers.in diff --git a/.gitignore b/.gitignore index 5b27599..199f65d 100644 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,7 @@ docs/design/*.html tools/autotools/install-sh tools/autotools/missing tools/autotools/depcomp + tools/maint/fetch +tools/maint/gitlog-to-committers tools/scripts/whitespace-detect diff --git a/configure.ac.in b/configure.ac.in index d07369d..7aadd2a 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -96,6 +96,7 @@ AC_CONFIG_FILES([ tests/Makefile ]) -AC_CONFIG_FILES([tools/maint/fetch],[chmod +x tools/maint/fetch]) +AC_CONFIG_FILES([tools/maint/fetch], [chmod +x tools/maint/fetch]) +AC_CONFIG_FILES([tools/maint/gitlog-to-committers],[chmod +x tools/maint/gitlog-to-committers]) AC_OUTPUT diff --git a/tools/maint/Makefile.am b/tools/maint/Makefile.am index 6e93f8d..db310c4 100644 --- a/tools/maint/Makefile.am +++ b/tools/maint/Makefile.am @@ -24,19 +24,12 @@ include $(top_srcdir)/Makefile.maint ## Maintainer related targets ## -scripts = \ - fetch \ - git-version-gen \ - gitlog-to-changelog \ - announce-gen - -noinst_SCRIPTS = $(scripts) - -CLEANFILES = EXTRA_DIST = \ fetch.in \ - git-version-gen \ - gitlog-to-changelog \ + gitlog-to-committers.in \ + \ + git-version-gen \ + gitlog-to-changelog \ announce-gen HOST_GNULIB="http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;hb=HEAD;f=" diff --git a/tools/maint/gitlog-to-committers.in b/tools/maint/gitlog-to-committers.in new file mode 100644 index 0000000..b95319c --- /dev/null +++ b/tools/maint/gitlog-to-committers.in @@ -0,0 +1,135 @@ +#! @PERL@ + +# +# gitlog-to-AUTHORS.in +# +# Copyright (C) 2008 Francesco Salvestrini +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# This program is based on gitlog-to-changelog by Jim Meyering +# + +use strict; +use warnings; +use Getopt::Long; +use POSIX qw(strftime); + +(my $ME = $0) =~ s|.*/||; +my $VERSION = "0.1"; + +END { + defined fileno STDOUT or return; + close STDOUT and return; + warn "$ME: failed to close standard output: $!\n"; + $? ||= 1; +} + +sub usage ($) +{ + my ($exit_code) = @_; + my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); + if ($exit_code != 0) { + print $STREAM "Try `$ME --help' for more information.\n"; + } else { + print $STREAM < AUTHORS + +EOF + } + exit $exit_code; +} + +# If the string $S is a well-behaved file name, simply return it. +# If it contains white space, quotes, etc., quote it, and return the new string. +sub shell_quote($) +{ + my ($s) = @_; + if ($s =~ m![^\w+/.,-]!) { + # Convert each single quote to '\'' + $s =~ s/\'/\'\\\'\'/g; + # Then single quote the string. + $s = "'$s'"; + } + return $s; +} + +sub quoted_cmd(@) +{ + return join (' ', map {shell_quote $_} @_); +} + +{ + my $since_date = '1970-01-01 UTC'; + GetOptions( + help => sub { usage 0 }, + version => sub { print "$ME version $VERSION\n"; exit }, + 'since=s' => \$since_date, + ) or usage 1; + + @ARGV + and (warn "$ME: too many arguments\n"), usage 1; + + my @cmd = (qw (git shortlog --summary), "--since=$since_date"); + open PIPE, '-|', @cmd + or die ("$ME: failed to run `". quoted_cmd (@cmd) ."': $!\n" . + "(Is your Git too old? Version 1.5.1 or later required.)\n"); + + my %committers; + while () { + my $line = $_; + + defined($line) or last; + chomp($line); + + if ($line =~ /^\s*(\d+)\s+([\w\s]+)\s*$/) { + defined($1) or die "$ME: Wrong commits count"; + defined($2) or die "$ME: Wrong committer name"; + + my $commits = int($1); + my $name = $2; + + if (defined($committers{$name})) { + die "$ME: Duplicated name found, fix your .mailmap"; + } + $committers{$name} = $commits; + } else { + die "$ME: Unhandled line found ('$line')"; + } + } + + my @keys = sort { $committers{$a} < $committers{$b} } keys %committers; + foreach my $name (@keys) { + print "$name\n"; + } + + close PIPE + or die "$ME: error closing pipe from " . quoted_cmd (@cmd) . "\n"; + # FIXME-someday: include $PROCESS_STATUS in the diagnostic +} -- 2.11.4.GIT