Update copyright for 2022
[pgsql.git] / src / tools / copyright.pl
blobcc5411673c0bc1008c312dc72290c3950f06d3c2
1 #!/usr/bin/perl
2 #################################################################
3 # copyright.pl -- update copyright notices throughout the source tree, idempotently.
5 # Copyright (c) 2011-2022, PostgreSQL Global Development Group
7 # src/tools/copyright.pl
9 # FYI, Tie adds a trailing newline on the last line if missing.
10 #################################################################
12 use strict;
13 use warnings;
15 use File::Find;
16 use File::Basename;
17 use Tie::File;
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 }, '.');
30 sub wanted
33 # prevent corruption of git indexes by ignoring any .git/
34 if (basename($_) eq '.git')
36 $File::Find::prune = 1;
37 return;
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)$/);
46 my @lines;
47 tie @lines, "Tie::File", $File::Find::name;
49 foreach my $line (@lines)
52 # We only care about lines with a copyright notice.
53 next unless $line =~ m/$cc.*$pgdg/i;
55 # Skip line if already matches the current year; if not
56 # we get $year-$year, e.g. 2012-2012
57 next if $line =~ m/$cc $year, $pgdg/i;
59 # We process all lines because some files have copyright
60 # strings embedded in them, e.g. src/bin/psql/help.c
61 $line =~ s/$cc (\d{4})-\d{4}, $pgdg/$ccliteral $1-$year, $pgdg/i;
62 $line =~ s/$cc (\d{4}), $pgdg/$ccliteral $1-$year, $pgdg/i;
64 untie @lines;
65 return;
68 print "Manually update:\n";
69 print " ./doc/src/sgml/legal.sgml in head and back branches\n";
70 print " ./COPYRIGHT in back branches\n";