2 #################################################################
3 # copyright.pl -- update copyright notices throughout the source tree, idempotently.
5 # Copyright (c) 2011-2023, PostgreSQL Global Development Group
7 # src/tools/copyright.pl
9 # FYI, Tie adds a trailing newline on the last line if missing.
10 #################################################################
19 my $pgdg = 'PostgreSQL Global Development Group';
20 my $cc = 'Copyright \(c\)';
21 my $ccliteral = 'Copyright (c)';
23 # year-1900 is what localtime(time) puts in element 5
24 my $year = 1900 + ${ [ localtime(time) ] }[5];
26 print "Using current year: $year\n";
28 find
({ wanted
=> \
&wanted
, no_chdir
=> 1 }, '.');
33 # prevent corruption of git indexes by ignoring any .git/
34 if (basename
($_) eq '.git')
36 $File::Find
::prune
= 1;
40 return if !-f
$File::Find
::name
|| -l
$File::Find
::name
;
42 # skip file names with binary extensions
43 # How are these updated? bjm 2012-01-02
44 return if ($_ =~ m/\.(ico|bin|po|key)$/);
47 tie
@lines, "Tie::File", $File::Find
::name
;
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)
54 # We only care about lines with a copyright notice.
55 next unless $line =~ m/$cc.*$pgdg/i;
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;
61 # Skip already-updated lines too, to avoid unnecessary
63 next if $line =~ m/$cc \d{4}-$year, $pgdg/i;
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;
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";