Fix a compiler warning in initStringInfo().
[pgsql.git] / src / tools / add_commit_links.pl
blob34c4d7ad8983b63d5865683aaad05bf2035e7275
1 #! /usr/bin/perl
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.
34 use strict;
35 use warnings FATAL => 'all';
37 sub process_file
39 my $file = shift;
41 my $in_comment = 0;
42 my $prev_line_ended_with_paren = 0;
43 my $prev_leading_space = '';
44 my $lineno = 0;
46 my @hashes = ();
48 my $tmpfile = $file . '.tmp';
50 # Get major version number from the file name.
51 $file =~ m/-(\d+)\./;
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";
57 while (<$fh>)
59 $lineno++;
61 $in_comment = 1 if (m/^<!--/);
63 # skip over commit links because we will add them below
64 next
65 if (!$in_comment &&
66 m{^\s*<ulink url="&commit_baseurl;[[:xdigit:]]+">&sect;</ulink>\s*$});
68 if ($in_comment && m/\[([[:xdigit:]]+)\]/)
70 my $hash = $1;
72 # major release item
73 (!m/^Branch:/) && push(@hashes, $hash);
75 # minor release item
76 m/^Branch:/ &&
77 defined($major_version) &&
78 m/_${major_version}_/ &&
79 push(@hashes, $hash);
82 if (!$in_comment && m{</para>})
84 if (@hashes)
86 if ($prev_line_ended_with_paren)
88 for my $hash (@hashes)
90 print $tfh
91 "$prev_leading_space<ulink url=\"&commit_baseurl;$hash\">&sect;</ulink>\n";
93 @hashes = ();
95 else
97 print
98 "hashes found but no matching text found for placement on line $lineno\n";
99 exit(1);
104 print $tfh $_;
106 $prev_line_ended_with_paren = m/\)\s*$/;
108 m/^(\s*)/;
109 $prev_leading_space = $1;
111 $in_comment = 0 if (m/^-->/);
114 close($fh);
115 close($tfh);
117 rename($tmpfile, $file) || die "could not rename %s to %s: $!\n",
118 $tmpfile,
119 $file;
121 return;
124 if (@ARGV == 0)
126 printf(STDERR "Usage: %s release_notes_file [...]\n", $0);
127 exit(1);
130 for my $file (@ARGV)
132 process_file($file);