]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - tools/mkheaders
Only check for a join time if a user is actually in the channel.
[user/henk/code/inspircd.git] / tools / mkheaders
index 0ca59358474903e209288b5f598b58fcbd3d1aa0..ae59857c624b082c0e5ae65bc9ded8878bd7feec 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # InspIRCd -- Internet Relay Chat Daemon
 #
-#   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
+#   Copyright (C) 2020-2021 Sadie Powell <sadie@witchery.services>
 #
 # 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
@@ -50,7 +50,7 @@ for my $path (@paths) {
        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;
        }
 
@@ -68,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;
                        }
                }
 
@@ -135,7 +132,7 @@ 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};
        }
 }