| 1 |
#!/usr/bin/perl |
| 2 |
################################################################# |
| 3 |
# copyright.pl -- update copyright notices throughout the source tree, idempotently. |
| 4 |
# |
| 5 |
# Copyright (c) 2011-2025, PostgreSQL Global Development Group |
| 6 |
# |
| 7 |
# src/tools/copyright.pl |
| 8 |
# |
| 9 |
# FYI, Tie adds a trailing newline on the last line if missing. |
| 10 |
################################################################# |
| 11 |
|
| 12 |
use strict; |
| 13 |
use warnings FATAL => 'all'; |
| 14 |
|
| 15 |
use File::Find; |
| 16 |
use File::Basename; |
| 17 |
use Tie::File; |
| 18 |
|
| 19 |
my $pgdg = 'PostgreSQL Global Development Group'; |
| 20 |
my $cc = 'Copyright \(c\)'; |
| 21 |
my $ccliteral = 'Copyright (c)'; |
| 22 |
|
| 23 |
# year-1900 is what localtime(time) puts in element 5 |
| 24 |
my $year = 1900 + ${ [ localtime(time) ] }[5]; |
| 25 |
|
| 26 |
print "Using current year: $year\n"; |
| 27 |
|
| 28 |
find({ wanted => \&wanted, no_chdir => 1 }, '.'); |
| 29 |
|
| 30 |
sub wanted |
| 31 |
{ |
| 32 |
|
| 33 |
# prevent corruption of git indexes by ignoring any .git/ |
| 34 |
if (basename($_) eq '.git') |
| 35 |
{ |
| 36 |
$File::Find::prune = 1; |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
return if !-f $File::Find::name || -l $File::Find::name; |
| 41 |
|
| 42 |
# skip file names with binary extensions |
| 43 |
# How are these updated? bjm 2012-01-02 |
| 44 |
return if ($_ =~ m/\.(ico|bin|po|key)$/); |
| 45 |
|
| 46 |
my @lines; |
| 47 |
tie @lines, "Tie::File", $File::Find::name; |
| 48 |
|
| 49 |
# We process all lines because some files have copyright |
| 50 |
# strings embedded in them, e.g. src/bin/psql/help.c |
| 51 |
foreach my $line (@lines) |
| 52 |
{ |
| 53 |
|
| 54 |
# We only care about lines with a copyright notice. |
| 55 |
next unless $line =~ m/$cc.*$pgdg/i; |
| 56 |
|
| 57 |
# Skip line if it already matches the current year; if not |
| 58 |
# we get $year-$year, e.g. 2012-2012. |
| 59 |
next if $line =~ m/$cc $year, $pgdg/i; |
| 60 |
|
| 61 |
# Skip already-updated lines too, to avoid unnecessary |
| 62 |
# file updates. |
| 63 |
next if $line =~ m/$cc \d{4}-$year, $pgdg/i; |
| 64 |
|
| 65 |
# Apply the update, relying on Tie::File to write the file. |
| 66 |
$line =~ s/$cc (\d{4})-\d{4}, $pgdg/$ccliteral $1-$year, $pgdg/i; |
| 67 |
$line =~ s/$cc (\d{4}), $pgdg/$ccliteral $1-$year, $pgdg/i; |
| 68 |
} |
| 69 |
untie @lines; |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
print "Manually update:\n"; |
| 74 |
print " ./doc/src/sgml/legal.sgml in head and back branches\n"; |
| 75 |
print " ./COPYRIGHT in back branches\n"; |