diff options
author | Yves Orton <demerphq@gmail.com> | 2022-08-18 11:22:09 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-08-21 12:09:05 +0200 |
commit | cbb3466bfe83203399f124dc2814a0597a44bd17 (patch) | |
tree | 5aaf5ec7a9d5e9f16c0ce3050ee2b5b4f41b7050 | |
parent | 94f97703e1943dd7f717b7d6960b4f5ecdc69902 (diff) | |
download | perl-cbb3466bfe83203399f124dc2814a0597a44bd17.tar.gz |
updateAUTHORS.pl - add support for a commit range
checkAUTHORS.pl supports specifying a commit range, and we actually
need it even more as we do not support piping from git log (as our
git log format is ungainly) so this allows us to be feature compatible.
-rwxr-xr-x | Porting/updateAUTHORS.pl | 23 | ||||
-rw-r--r-- | Porting/updateAUTHORS.pm | 19 |
2 files changed, 39 insertions, 3 deletions
diff --git a/Porting/updateAUTHORS.pl b/Porting/updateAUTHORS.pl index 5c10f31bec..83b03c0d5c 100755 --- a/Porting/updateAUTHORS.pl +++ b/Porting/updateAUTHORS.pl @@ -22,6 +22,9 @@ my @OPTSPEC= qw( mailmap_file=s verbose+ + + from_commit|from=s + to_commit|to=s ); sub main { @@ -29,6 +32,8 @@ sub main { my %opts= ( authors_file => "AUTHORS", mailmap_file => ".mailmap", + from => "", + to => "", ); ## Parse options and print usage if there is a syntax error, @@ -42,6 +47,14 @@ sub main { s/\b([a-z]+)_([a-z]+)\b/${1}_${2}|${1}-${2}/gr } @OPTSPEC ) or pod2usage(2); + $opts{commit_range}= join " ", @ARGV; + if (!$opts{commit_range}) { + if ($opts{from_commit}) { + $opts{to_commit} ||= "HEAD"; + $opts{$_} =~ s/\.+\z// for qw(from_commit to_commit); + $opts{commit_range}= "$opts{from_commit}..$opts{to_commit}"; + } + } pod2usage(1) if $opts{help}; pod2usage(-verbose => 2) if $opts{man}; @@ -64,13 +77,21 @@ based on commit data. =head1 SYNOPSIS -Porting/updateAUTHORS.pl +Porting/updateAUTHORS.pl [OPTIONS] [GIT_REF_RANGE] + +By default scans the commit history specified (or the entire history from the +current commit) and then updates F<AUTHORS> and F<.mailmap> so all contributors +are properly listed. Options: --help brief help message --man full documentation --verbose be verbose + Commit Range: + --from=GIT_REF Select commits to use + --to=GIT_REF Select commits to use, defaults to HEAD + File Locations: --authors-file=FILE override default of 'AUTHORS' --mailmap-file=FILE override default of '.mailmap' diff --git a/Porting/updateAUTHORS.pm b/Porting/updateAUTHORS.pm index 8fa3e8c5ec..1575e63bef 100644 --- a/Porting/updateAUTHORS.pm +++ b/Porting/updateAUTHORS.pm @@ -70,10 +70,15 @@ sub read_commit_log { my $author_info= $self->{author_info} ||= {}; my $mailmap_info= $self->{mailmap_info} ||= {}; - open my $fh, qq(git log --pretty='tformat:$tformat' |); + my $commit_range= $self->{commit_range}; + my $commits_read= 0; + + my $cmd= qq(git log --pretty='format:$tformat' $commit_range); + open my $fh, "$cmd |"; while (defined(my $line= <$fh>)) { chomp $line; $line= decode_utf8($line); + $commits_read++; my $commit_info= {}; @{$commit_info}{@field_names}= split /\0/, $line, 0 + @field_names; @@ -98,6 +103,14 @@ sub read_commit_log { $author_info->{"lines"}{$author_name_mm}++; $author_info->{"lines"}{$committer_name_mm}++; } + if (!$commits_read) { + if ($self->{commit_range}) { + die "No commits in range '$self->{commit_range}'\n"; + } + else { + die "Panic! There are no commits!\n"; + } + } return $author_info; } @@ -638,6 +651,7 @@ Create a new object. Required parameters are Other supported parameters are as follows: verbose + commit_range this list is not exhaustive. See the code implementing the main() function in F<Porting/updateAUTHORS.pl> for an exhaustive list. @@ -668,7 +682,8 @@ or the .mailmap file. Requires that both files are editable. =item read_commit_log() -Read the commit log and find any new names it contains. +Read the commit log specified by the property "commit_range" and find +any new names it contains. Normally used via C<read_and_update> and not called directly. |