|
| 1 | +#! /usr/bin/perl |
| 2 | + |
| 3 | +################################################################# |
| 4 | +# add_commit_links.pl -- add commit links to the release notes |
| 5 | +# |
| 6 | +# Copyright (c) 2024, PostgreSQL Global Development Group |
| 7 | +# |
| 8 | +# src/tools/add_commit_links.pl |
| 9 | +################################################################# |
| 10 | + |
| 11 | +# |
| 12 | +# This script adds commit links to the release notes. |
| 13 | +# |
| 14 | +# Usage: cd to top of source tree and issue |
| 15 | +#src/tools/add_commit_links.pl release_notes_file |
| 16 | +# |
| 17 | +# The script can add links for release note items that lack them, and update |
| 18 | +# those that have them. The script is sensitive to the release note file being |
| 19 | +# in a specific format: |
| 20 | +# |
| 21 | +# * File name contains the major version number preceded by a dash |
| 22 | +# and followed by a period |
| 23 | +# * Commit text is generated by src/tools/git_changelog |
| 24 | +# * SGML comments around commit text start in the first column |
| 25 | +# * The commit item title ends with an attribution that ends with |
| 26 | +# a closing parentheses |
| 27 | +# * previously added URL link text is unmodified |
| 28 | +# * a "<para>" follows the commit item title |
| 29 | +# |
| 30 | +# The major version number is used to select the commit hash for minor |
| 31 | +# releases. An error will be generated if valid commits are found but |
| 32 | +# no proper location for the commit links is found. |
| 33 | + |
| 34 | +use strict; |
| 35 | +use warningsFATAL=>'all'; |
| 36 | + |
| 37 | +subprocess_file |
| 38 | +{ |
| 39 | +my$file =shift; |
| 40 | + |
| 41 | +my$in_comment = 0; |
| 42 | +my$prev_line_ended_with_paren = 0; |
| 43 | +my$prev_leading_space =''; |
| 44 | +my$lineno = 0; |
| 45 | + |
| 46 | +my@hashes = (); |
| 47 | + |
| 48 | +my$tmpfile =$file .'.tmp'; |
| 49 | + |
| 50 | +# Get major version number from the file name. |
| 51 | +$file =~m/-(\d+)\./; |
| 52 | +my$major_version =$1; |
| 53 | + |
| 54 | +open(my$fh,'<',$file) ||die"could not open file%s:$!\n",$file; |
| 55 | +open(my$tfh,'>',$tmpfile) ||die"could not open file%s:$!\n", |
| 56 | +$tmpfile; |
| 57 | + |
| 58 | +while (<$fh>) |
| 59 | +{ |
| 60 | +$lineno++; |
| 61 | + |
| 62 | +$in_comment = 1if (m/^<!--/); |
| 63 | + |
| 64 | +# skip over commit links because we will add them below |
| 65 | +next |
| 66 | +if (!$in_comment && |
| 67 | +m{^\s*<ulink url="&commit_baseurl;[\da-f]+">§</ulink>\s*$}); |
| 68 | + |
| 69 | +if ($in_comment &&m/\[([\da-f]+)\]/) |
| 70 | +{ |
| 71 | +my$hash =$1; |
| 72 | + |
| 73 | +# major release item |
| 74 | +(!m/^Branch:/) &&push(@hashes,$hash); |
| 75 | + |
| 76 | +# minor release item |
| 77 | +m/^Branch:/ && |
| 78 | +defined($major_version) && |
| 79 | +m/_${major_version}_/ && |
| 80 | +push(@hashes,$hash); |
| 81 | +} |
| 82 | + |
| 83 | +if (!$in_comment &&m{</para>}) |
| 84 | +{ |
| 85 | +if (@hashes) |
| 86 | +{ |
| 87 | +if ($prev_line_ended_with_paren) |
| 88 | +{ |
| 89 | +formy$hash (@hashes) |
| 90 | +{ |
| 91 | +print({$tfh} |
| 92 | +"$prev_leading_space<ulink url=\"&commit_baseurl;$hash\">§</ulink>\n" |
| 93 | +); |
| 94 | +} |
| 95 | +@hashes = (); |
| 96 | +} |
| 97 | +else |
| 98 | +{ |
| 99 | +printf( |
| 100 | +"hashes found but no matching text found for placement on line%s\n", |
| 101 | +$lineno); |
| 102 | +exit(1); |
| 103 | +} |
| 104 | +} |
| 105 | +} |
| 106 | + |
| 107 | +print({$tfh}$_); |
| 108 | + |
| 109 | +$prev_line_ended_with_paren =m/\)\s*$/; |
| 110 | + |
| 111 | +m/^(\s*)/; |
| 112 | +$prev_leading_space =$1; |
| 113 | + |
| 114 | +$in_comment = 0if (m/^-->/); |
| 115 | +} |
| 116 | + |
| 117 | +close($fh); |
| 118 | +close($tfh); |
| 119 | + |
| 120 | +rename($tmpfile,$file) ||die"could not rename%s to%s:$!\n", |
| 121 | +$tmpfile, |
| 122 | +$file; |
| 123 | + |
| 124 | +return; |
| 125 | +} |
| 126 | + |
| 127 | +if (@ARGV == 0) |
| 128 | +{ |
| 129 | +printf(STDERR"Usage:%s release_notes_file [...]\n",$0); |
| 130 | +exit(1); |
| 131 | +} |
| 132 | + |
| 133 | +formy$file (@ARGV) |
| 134 | +{ |
| 135 | +process_file($file); |
| 136 | +} |