Improve Perl script which adds commit links to release notes

Reported-by: Andrew Dunstan

Discussion: https://postgr.es/m/b2465837-56df-4794-a0b5-5e6ed44ed870@dunslane.net

Author: Andrew Dunstan

Backpatch-through: 12
This commit is contained in:
Bruce Momjian 2024-09-19 08:45:32 -04:00
parent 772164777c
commit 967316eebb

View File

@ -51,9 +51,8 @@ sub process_file
$file =~ m/-(\d+)\./; $file =~ m/-(\d+)\./;
my $major_version = $1; my $major_version = $1;
open(my $fh, '<', $file) || die "could not open file %s: $!\n", $file; open(my $fh, '<', $file) || die "could not open file $file: $!\n";
open(my $tfh, '>', $tmpfile) || die "could not open file %s: $!\n", open(my $tfh, '>', $tmpfile) || die "could not open file $tmpfile: $!\n";
$tmpfile;
while (<$fh>) while (<$fh>)
{ {
@ -64,9 +63,9 @@ sub process_file
# skip over commit links because we will add them below # skip over commit links because we will add them below
next next
if (!$in_comment && if (!$in_comment &&
m{^\s*<ulink url="&commit_baseurl;[\da-f]+">&sect;</ulink>\s*$}); m{^\s*<ulink url="&commit_baseurl;[[:xdigit:]]+">&sect;</ulink>\s*$});
if ($in_comment && m/\[([\da-f]+)\]/) if ($in_comment && m/\[([[:xdigit:]]+)\]/)
{ {
my $hash = $1; my $hash = $1;
@ -88,23 +87,21 @@ sub process_file
{ {
for my $hash (@hashes) for my $hash (@hashes)
{ {
print({$tfh} print $tfh
"$prev_leading_space<ulink url=\"&commit_baseurl;$hash\">&sect;</ulink>\n" "$prev_leading_space<ulink url=\"&commit_baseurl;$hash\">&sect;</ulink>\n";
);
} }
@hashes = (); @hashes = ();
} }
else else
{ {
printf( print
"hashes found but no matching text found for placement on line %s\n", "hashes found but no matching text found for placement on line $lineno\n";
$lineno);
exit(1); exit(1);
} }
} }
} }
print({$tfh} $_); print $tfh $_;
$prev_line_ended_with_paren = m/\)\s*$/; $prev_line_ended_with_paren = m/\)\s*$/;