]> granicus.if.org Git - postgresql/blob - src/tools/copyright.pl
705edaf3ee135759950e23e2b59ff3dad972b1e3
[postgresql] / src / tools / copyright.pl
1 #!/usr/bin/perl 
2 #################################################################
3 # copyright.pl -- update copyright notices throughout the source tree, idempotently.
4 #
5 # Copyright (c) 2011-2012, PostgreSQL Global Development Group
6 #
7 # src/tools/copyright.pl
8 #################################################################
9
10 use strict;
11 use warnings;
12
13 use File::Find;
14 use Tie::File;
15
16 my $pgdg = 'PostgreSQL Global Development Group';
17 my $cc = 'Copyright \(c\) ';
18 # year-1900 is what localtime(time) puts in element 5
19 my $year = 1900 + ${[localtime(time)]}[5];
20
21 print "Using current year:  $year\n";
22
23 find({wanted => \&wanted, no_chdir => 1}, '.');
24
25 sub wanted {
26     # prevent corruption of git indexes, ./.git
27     if ($File::Find::name =~ m{^\./\.git$})
28     {
29         $File::Find::prune = 1;
30         return;
31     }
32
33     return if ! -f $File::Find::name || -l $File::Find::name;
34
35     my @lines;
36     tie @lines, "Tie::File", $File::Find::name;
37
38     foreach my $line (@lines) {
39         # We only care about lines with a copyright notice.
40         next unless $line =~ m/$cc.*$pgdg/;
41         # We stop when we've done one substitution.  This is both for
42         # efficiency and, at least in the case of this program, for
43         # correctness.
44         last if $line =~ m/$cc.*$year.*$pgdg/;
45         last if $line =~ s/($cc\d{4})(, $pgdg)/$1-$year$2/;
46         last if $line =~ s/($cc\d{4})-\d{4}(, $pgdg)/$1-$year$2/;
47     }
48     untie @lines;
49 }
50
51 print "Manually update doc/src/sgml/legal.sgml and src/interfaces/libpq/libpq.rc.in too\n";
52