3 #################################################################
4 # add_commit_links.pl -- add commit links to the release notes
6 # Copyright (c) 2024-2025, PostgreSQL Global Development Group
8 # src/tools/add_commit_links.pl
9 #################################################################
12 # This script adds commit links to the release notes.
14 # Usage: cd to top of source tree and issue
15 # src/tools/add_commit_links.pl release_notes_file
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:
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
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.
35 use warnings FATAL
=> 'all';
42 my $prev_line_ended_with_paren = 0;
43 my $prev_leading_space = '';
48 my $tmpfile = $file . '.tmp';
50 # Get major version number from the file name.
52 my $major_version = $1;
54 open(my $fh, '<', $file) || die "could not open file $file: $!\n";
55 open(my $tfh, '>', $tmpfile) || die "could not open file $tmpfile: $!\n";
61 $in_comment = 1 if (m/^<!--/);
63 # skip over commit links because we will add them below
66 m{^\s*<ulink url="&commit_baseurl;[[:xdigit:]]+">§</ulink>\s*$});
68 if ($in_comment && m/\[([[:xdigit:]]+)\]/)
73 (!m/^Branch:/) && push(@hashes, $hash);
77 defined($major_version) &&
78 m/_${major_version}_/ &&
82 if (!$in_comment && m{</para>})
86 if ($prev_line_ended_with_paren)
88 for my $hash (@hashes)
91 "$prev_leading_space<ulink url=\"&commit_baseurl;$hash\">§</ulink>\n";
98 "hashes found but no matching text found for placement on line $lineno\n";
106 $prev_line_ended_with_paren = m/\)\s*$/;
109 $prev_leading_space = $1;
111 $in_comment = 0 if (m/^-->/);
117 rename($tmpfile, $file) || die "could not rename %s to %s: $!\n",
126 printf(STDERR
"Usage: %s release_notes_file [...]\n", $0);