Avoid re-writing files unnecessarily in src/tools/copyright.pl.

The existing coding resulted in touching every copyright-containing
file in the tree, even if it was already up to date.  That doesn't
matter much for the annual run, but it's an annoyance if you try
to use the script for mop-up at the close of a devel cycle, as
I just did.

Discussion: https://postgr.es/m/266030.1649685473@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2022-04-11 11:20:13 -04:00
parent ad385a494f
commit dfd0f2bbc5
1 changed files with 9 additions and 4 deletions

View File

@ -46,18 +46,23 @@ sub wanted
my @lines;
tie @lines, "Tie::File", $File::Find::name;
# We process all lines because some files have copyright
# strings embedded in them, e.g. src/bin/psql/help.c
foreach my $line (@lines)
{
# We only care about lines with a copyright notice.
next unless $line =~ m/$cc.*$pgdg/i;
# Skip line if already matches the current year; if not
# we get $year-$year, e.g. 2012-2012
# Skip line if it already matches the current year; if not
# we get $year-$year, e.g. 2012-2012.
next if $line =~ m/$cc $year, $pgdg/i;
# We process all lines because some files have copyright
# strings embedded in them, e.g. src/bin/psql/help.c
# Skip already-updated lines too, to avoid unnecessary
# file updates.
next if $line =~ m/$cc \d{4}-$year, $pgdg/i;
# Apply the update, relying on Tie::File to write the file.
$line =~ s/$cc (\d{4})-\d{4}, $pgdg/$ccliteral $1-$year, $pgdg/i;
$line =~ s/$cc (\d{4}), $pgdg/$ccliteral $1-$year, $pgdg/i;
}