release-notes.pl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/usr/bin/perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.haxx.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. ###########################################################################
  23. ###############################################
  24. #
  25. # ==== How to use this script ====
  26. #
  27. # 1. Get recent commits added to RELEASE-NOTES:
  28. #
  29. # $ ./scripts/release-notes.pl
  30. #
  31. # 2. Edit RELEASE-NOTES and remove all entries that don't belong. Unused
  32. # references below will be cleaned up in the next step. Make sure to move
  33. # "changes" up to the changes section. All entries will by default be listed
  34. # under bug-fixes as this script can't know where to put them.
  35. #
  36. # 3. Run the cleanup script and let it sort the entries and remove unused
  37. # references from lines you removed in step (2):
  38. #
  39. # $ ./script/release-notes.pl cleanup
  40. #
  41. # 4. Reload RELEASE-NOTES and verify that things look okay. The cleanup
  42. # procedure can and should be re-run when lines are removed or rephrased.
  43. #
  44. # 5. Run ./scripts/contributors.sh and update the contributor list of names
  45. # The list can also be extended or edited manually.
  46. #
  47. # 6. Run ./scripts/delta and update the contributor count at the top, and
  48. # double-check/update the other counters.
  49. #
  50. # 7. Commit the file using "RELEASE-NOTES: synced" as commit message.
  51. #
  52. ################################################
  53. my $cleanup = ($ARGV[0] eq "cleanup");
  54. my @gitlog=`git log @^{/RELEASE-NOTES:.synced}..` if(!$cleanup);
  55. my @releasenotes=`cat RELEASE-NOTES`;
  56. my @o; # the entire new RELEASE-NOTES
  57. my @refused; # [num] = [2 bits of use info]
  58. my @refs; # [number] = [URL]
  59. for my $l (@releasenotes) {
  60. if($l =~ /^ o .*\[(\d+)\]/) {
  61. # referenced, set bit 0
  62. $refused[$1]=1;
  63. }
  64. elsif($l =~ /^ \[(\d+)\] = (.*)/) {
  65. # listed in a refernce, set bit 1
  66. $refused[$1] |= 2;
  67. $refs[$1] = $2;
  68. }
  69. }
  70. # Return a new fresh reference number
  71. sub getref {
  72. for my $r (1 .. $#refs) {
  73. if(!$refused[$r] & 1) {
  74. return $r;
  75. }
  76. }
  77. # add at the end
  78. return $#refs + 1;
  79. }
  80. my $short;
  81. my $first;
  82. for my $l (@gitlog) {
  83. chomp $l;
  84. if($l =~ /^commit/) {
  85. if($first) {
  86. onecommit($short);
  87. }
  88. # starts a new commit
  89. undef @fixes;
  90. undef @closes;
  91. undef @bug;
  92. $short = "";
  93. $first = 0;
  94. }
  95. elsif(($l =~ /^ (.*)/) && !$first) {
  96. # first line
  97. $short = $1;
  98. $first = 1;
  99. push @line, $short;
  100. }
  101. elsif(($l =~ /^ (.*)/) && $first) {
  102. # not the first
  103. my $line = $1;
  104. if($line =~ /^Fixes(:|) .*[^0-9](\d+)/i) {
  105. push @fixes, $2;
  106. }
  107. elsif($line =~ /^Closes(:|) .*[^0-9](\d+)/i) {
  108. push @closes, $2;
  109. }
  110. elsif($line =~ /^Bug: (.*)/i) {
  111. push @bug, $1;
  112. }
  113. }
  114. }
  115. if($first) {
  116. onecommit($short);
  117. }
  118. # call at the end of a parsed commit
  119. sub onecommit {
  120. my ($short)=@_;
  121. my $ref;
  122. if($bug[0]) {
  123. $ref = $bug[0];
  124. }
  125. elsif($fixes[0]) {
  126. $ref = $fixes[0];
  127. }
  128. elsif($closes[0]) {
  129. $ref = $closes[0];
  130. }
  131. if($ref =~ /^(\d+)/) {
  132. $ref = "https://curl.haxx.se/bug/?i=$1"
  133. }
  134. if($ref) {
  135. my $r = getref();
  136. $refs[$r] = $ref;
  137. $moreinfo{$short}=$r;
  138. $refused[$r] |= 1;
  139. }
  140. }
  141. #### Output the new RELEASE-NOTES
  142. my @bullets;
  143. for my $l (@releasenotes) {
  144. if(($l =~ /^This release includes the following bugfixes:/) && !$cleanup) {
  145. push @o, $l;
  146. push @o, "\n";
  147. for my $f (@line) {
  148. push @o, sprintf " o $f%s\n", $moreinfo{$f}? sprintf(" [%d]", $moreinfo{$f}): "";
  149. $refused[$moreinfo{$f}]=3;
  150. }
  151. push @o, " --- new entries are listed above this ---";
  152. next;
  153. }
  154. elsif($cleanup) {
  155. if($l =~ /^ --- new entries are listed/) {
  156. # ignore this if still around
  157. next;
  158. }
  159. elsif($l =~ /^ o .*/) {
  160. push @bullets, $l;
  161. next;
  162. }
  163. elsif($bullets[0]) {
  164. # output them case insensitively
  165. for my $b (sort { "\L$a" cmp "\L$b" } @bullets) {
  166. push @o, $b;
  167. }
  168. undef @bullets;
  169. }
  170. }
  171. if($l =~ /^ \[(\d+)\] = /) {
  172. # stop now
  173. last;
  174. }
  175. else {
  176. push @o, $l;
  177. }
  178. }
  179. my @srefs;
  180. my $ln;
  181. for my $n (1 .. $#refs) {
  182. my $r = $refs[$n];
  183. if($r && ($refused[$n] & 1)) {
  184. push @o, sprintf " [%d] = %s\n", $n, $r;
  185. }
  186. }
  187. open(O, ">RELEASE-NOTES");
  188. for my $l (@o) {
  189. print O $l;
  190. }
  191. close(O);
  192. exit;
  193. # Debug: show unused references
  194. for my $r (1 .. $#refs) {
  195. if($refused[$r] != 3) {
  196. printf "$r is %d!\n", $refused[$r];
  197. }
  198. }