general_assembly.pl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/env perl
  2. use warnings;
  3. use strict;
  4. use POSIX qw(strftime);
  5. use Encode qw(decode);
  6. use Data::Dumper;
  7. use Getopt::Long;
  8. use Digest::SHA;
  9. use utf8;
  10. use DateTime;
  11. use DateTime::Format::ISO8601;
  12. my @extra_members = (
  13. # entries should be of the format
  14. # [ <name>, <email>, <date elected> ],
  15. # ['Foo Bar', 'foo@bar', DateTime->new(year => 8613, month => 5, day => 22)],
  16. ['Ronald Bultje', 'rsbultje@gmail.com', DateTime->new(year => 2023, month => 11, day => 28)],
  17. ['Hendrik Leppkes', 'h.leppkes@gmail.com', DateTime->new(year => 2023, month => 11, day => 28)],
  18. ['Reimar Döffinger', 'Reimar.Doeffinger@gmx.de', DateTime->new(year => 2023, month => 11, day => 28)],
  19. ['Alexander Strasser', 'eclipse7@gmx.net', DateTime->new(year => 2023, month => 11, day => 28)],
  20. ['Baptiste Coudurier', 'baptiste.coudurier@gmail.com', DateTime->new(year => 2023, month => 11, day => 28)],
  21. ['Shiyou Yin', 'yinshiyou-hf@loongson.cn', DateTime->new(year => 2023, month => 11, day => 28)],
  22. );
  23. sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
  24. sub print_help {
  25. print "Usage: $0 [options]\n";
  26. print "Options:\n";
  27. print " --names Print only the names\n";
  28. print " --emails Print only the email addresses\n";
  29. print " --full Print both names and email addresses (default)\n";
  30. print " --date YY-MM-DD Generate the GA for a given date, defaults to current system time\n";
  31. print " -h, --help Show this help message\n";
  32. exit;
  33. }
  34. my $print_full = 1;
  35. my $print_names = 0;
  36. my $print_emails = 0;
  37. my $date_str = DateTime->now()->iso8601;
  38. my $help = 0;
  39. GetOptions(
  40. "full" => \$print_full,
  41. "names" => \$print_names,
  42. "emails" => \$print_emails,
  43. "help" => \$help,
  44. "date=s" => \$date_str,
  45. "h" => \$help,
  46. );
  47. print_help() if $help;
  48. if ($print_names || $print_emails) {
  49. $print_full = 0;
  50. }
  51. sub get_date_range {
  52. my ($now) = @_;
  53. # date on which the GA update rule was established, and the voter list
  54. # was extraordinarily updated; cf.:
  55. # * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-October/316054.html
  56. # Message-Id <169818211998.11195.16532637803201641594@lain.khirnov.net>
  57. # * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2023-November/316618.html
  58. # Message-Id <5efcab06-8510-4226-bf18-68820c7c69ba@betaapp.fastmail.com>
  59. my $date_ga_rule = DateTime->new(year => 2023, month => 11, day => 06);
  60. # date when the regular update rule is first applied
  61. my $date_first_regular = DateTime->new(year => 2024);
  62. if ($now > $date_ga_rule && $now < $date_first_regular) {
  63. return ($date_ga_rule->clone()->set_year($date_ga_rule->year - 3), $date_ga_rule);
  64. }
  65. if ($now < $date_ga_rule) {
  66. print STDERR "GA before $date_ga_rule is not well-defined, be very careful with the output\n";
  67. }
  68. my $cur_year_jan = $now->clone()->truncate(to => "year");
  69. my $cur_year_jul = $cur_year_jan->clone()->set_month(7);
  70. my $date_until = $now > $cur_year_jul ? $cur_year_jul : $cur_year_jan;
  71. my $date_since = $date_until->clone()->set_year($date_until->year - 3);
  72. return ($date_since, $date_until);
  73. }
  74. my $date = DateTime::Format::ISO8601->parse_datetime($date_str);
  75. my ($since, $until) = get_date_range($date);
  76. my @shortlog = split /\n/, decode('UTF-8',
  77. `git log --pretty=format:"%aN <%aE>" --since="$since" --until="$until" | sort | uniq -c | sort -r`,
  78. Encode::FB_CROAK);
  79. my %assembly = ();
  80. foreach my $line (@shortlog) {
  81. my ($count, $name, $email) = $line =~ m/^ *(\d+) *(.*?) <(.*?)>/;
  82. if ($count < 20) {
  83. next;
  84. }
  85. $name = trim $name;
  86. if ($count < 50) {
  87. my $true = 0;
  88. my @commits = split /(^|\n)commit [a-z0-9]{40}(\n|$)/,
  89. decode('UTF-8',
  90. `git log --name-only --use-mailmap --author="$email" --since="$since" --until="$until"`,
  91. Encode::FB_CROAK);
  92. foreach my $commit (@commits) {
  93. $true++; # if ($commit =~ /\n[\w\/]+\.(c|h|S|asm|texi)/);
  94. }
  95. if ($true < 20) {
  96. next;
  97. }
  98. }
  99. $assembly{$name} = $email;
  100. }
  101. foreach my $entry (@extra_members) {
  102. my $elected = $entry->[2];
  103. if ($date > $elected && $date < $elected->clone()->set_year($elected->year + 2)) {
  104. $assembly{$entry->[0]} = $entry->[1];
  105. }
  106. }
  107. # generate the output string
  108. my @out_lines;
  109. foreach my $name (sort keys %assembly) {
  110. my $email = $assembly{$name};
  111. my $val;
  112. if ($print_full) {
  113. $val = sprintf("%s <%s>", $name, $email);
  114. } elsif ($print_names) {
  115. $val = $name;
  116. } elsif ($print_emails) {
  117. $val = $email;
  118. }
  119. push(@out_lines, ($val));
  120. }
  121. my $out_str = join("\n", @out_lines) . "\n";
  122. utf8::encode($out_str);
  123. printf("# GA for $since/$until; %d people; SHA256:%s; HEAD:%s%s",
  124. scalar @out_lines, Digest::SHA::sha256_hex($out_str),
  125. decode('UTF-8', `git rev-parse HEAD`, Encode::FB_CROAK),
  126. $out_str);