X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=tools%2Fmkheaders;h=ae59857c624b082c0e5ae65bc9ded8878bd7feec;hb=c7b938502295ddc5b2c89e0854d8c5c19ede32dc;hp=4b1f370f3eada005a79cb460f7d79de4836581a9;hpb=19cdd938610e6630d58bd5b0fd311a80f6e54647;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/tools/mkheaders b/tools/mkheaders index 4b1f370f3..ae59857c6 100755 --- a/tools/mkheaders +++ b/tools/mkheaders @@ -2,7 +2,7 @@ # # InspIRCd -- Internet Relay Chat Daemon # -# Copyright (C) 2020 Sadie Powell +# Copyright (C) 2020-2021 Sadie Powell # # This file is part of InspIRCd. InspIRCd is free software: you can # redistribute it and/or modify it under the terms of the GNU General Public @@ -18,15 +18,7 @@ # -BEGIN { - require 5.10.0; - unless (-f 'configure') { - print "Error: $0 must be run from the main source directory!\n"; - exit 1; - } -} - -use feature ':5.10'; +use v5.10.0; use strict; use warnings FATAL => qw(all); @@ -37,25 +29,28 @@ use List::Util qw(uniq); use POSIX qw(strftime); use lib dirname $RealDir; +use make::common; use make::console; my @ignored_revisions = ( '0b4285abd12323920d92fee51e199edd7527dbec', # adding copyright headers '46a39046196f55b52336e19662bb7bac85b731ac', # adding copyright headers + '4a6fedd9324d87349a806c9c1d0ae6e7d3c1fd38', # mass-updating descriptions '56375392ba94f2552bbeeeab4fd39e1e50295525', # sadie's name change 'bab14f0dd2345c9d7dcbc47c918563709e1ac094', # peavey breaking line endings 'f2acdbc3820f0f4f5ef76a0a64e73d2a320df91f', # peavey fixing line endings ); -my @paths = File::Util->new->list_dir('.' => { recurse => 1 }); +my @paths = File::Util->new->list_dir(dirname($RealDir) => { recurse => 1 }); my @updated; for my $path (@paths) { next unless -f $path; next if $path =~ /\/\./; + next if $path =~ /\/build\//; next if $path =~ /\/vendor\//; if (system "git ls-files --error-unmatch -- $path 1>/dev/null 2>/dev/null") { - print_format "Skipping <|YELLOW $path|> as it has not been committed.\n" if defined $ENV{MKHEADERS_VERBOSE}; + say STDERR console_format "Skipping <|YELLOW $path|> as it has not been committed." if defined $ENV{MKHEADERS_VERBOSE}; next; } @@ -73,32 +68,29 @@ for my $path (@paths) { close $fh; if (defined $copyright) { - print_format "Updating copyright headers in <|GREEN $path|>.\n" if defined $ENV{MKHEADERS_VERBOSE}; - my (%author, %authors); + say console_format "Updating copyright headers in <|GREEN $path|>." if defined $ENV{MKHEADERS_VERBOSE}; + my (%authors, $commit, %commits); my $ignored_args = join ' ', map { "--ignore-rev $_" } @ignored_revisions; - for my $line (split /\n+/, `git blame $ignored_args --incremental -w HEAD -- $path`) { + for my $line (split /\n+/, `git blame $ignored_args --incremental -M -w HEAD -- $path`) { if ($line =~ /^([0-9a-f]{40})(?:\s\d+){3}$/) { - $author{COMMITS} //= []; - push @{$author{COMMITS}}, $1; + $commit = $1; + $commits{$commit} //= {}; } elsif ($line =~ /^author (.+)/) { - $author{NAME} = $1; + $commits{$commit}->{NAME} = $1; } elsif ($line =~ /^author-mail <(.+)>/) { - $author{EMAIL} = $1; + $commits{$commit}->{EMAIL} = $1; } elsif ($line =~ /^author-time (.+)/) { - $author{YEAR} = strftime '%Y', gmtime $1; + $commits{$commit}->{YEAR} = strftime '%Y', gmtime $1; } elsif ($line =~ /^filename /) { - next unless scalar keys %author > 1; - my $display = sprintf "%s <%s>", $author{NAME}, $author{EMAIL}; + my $display = sprintf "%s <%s>", $commits{$commit}->{NAME}, $commits{$commit}->{EMAIL}; $authors{$display} //= []; - push $authors{$display}, $author{YEAR}; - for my $commit (uniq @{$author{COMMITS}}) { - my $details = `git rev-list --format=%B --max-count=1 $commit`; - while ($details =~ /co-authored-by: ([^<]+<[^>]+>)/gi) { - $authors{$1} //= []; - push $authors{$1}, $author{YEAR}; - } + push @{$authors{$display}}, $commits{$commit}->{YEAR}; + my $details = `git rev-list --format=%B --max-count=1 $commit`; + while ($details =~ /co-authored-by: ([^<]+<[^>]+>)/gi) { + $authors{$1} //= []; + push @{$authors{$1}}, $commits{$commit}->{YEAR}; } - undef %author; + undef $commit; } } @@ -113,7 +105,7 @@ for my $path (@paths) { $last_year = $year; } else { if ($last_year == $start_year) { - push @year_ranges, $last_year; + push @year_ranges, $last_year; } else { push @year_ranges, "$start_year-$last_year"; } @@ -122,7 +114,7 @@ for my $path (@paths) { } if (defined $last_year) { if ($last_year == $start_year) { - push @year_ranges, $last_year; + push @year_ranges, $last_year; } else { push @year_ranges, "$start_year-$last_year"; } @@ -140,11 +132,11 @@ for my $path (@paths) { close $fh; push @updated, $path; } else { - print_format "Skipping <|YELLOW $path|> as it contains no copyright headers.\n" if defined $ENV{MKHEADERS_VERBOSE}; + say STDERR console_format "Skipping <|YELLOW $path|> as it contains no copyright headers." if defined $ENV{MKHEADERS_VERBOSE}; } } -system 'git', 'commit', +execute 'git', 'commit', '--author', 'InspIRCd Robot ', '--message', 'Update copyright headers.', '--', @updated;