Avoid re-writing files unnecessarily in src/tools/copyright.pl.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 Apr 2022 15:20:13 +0000 (11:20 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 Apr 2022 15:20:20 +0000 (11:20 -0400)
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

src/tools/copyright.pl

index cc5411673c0bc1008c312dc72290c3950f06d3c2..182177e9b6b44410caf504b7cbba2c513bbcb466 100755 (executable)
@@ -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;
    }