summaryrefslogtreecommitdiff
path: root/src/tools/copyright.pl
blob: 8b92c2f0749262ae14807d476ddff06b3c16b90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
#################################################################
# copyright.pl -- update copyright notices throughout the source tree, idempotently.
#
# Copyright (c) 2011-2014, PostgreSQL Global Development Group
#
# src/tools/copyright.pl
#################################################################

use strict;
use warnings;

use File::Find;
use File::Basename;
use Tie::File;

my $pgdg = 'PostgreSQL Global Development Group';
my $cc   = 'Copyright \(c\) ';

# year-1900 is what localtime(time) puts in element 5
my $year = 1900 + ${ [ localtime(time) ] }[5];

print "Using current year:  $year\n";

find({ wanted => \&wanted, no_chdir => 1 }, '.');

sub wanted
{

	# prevent corruption of git indexes by ignoring any .git/
	if (basename($_) eq '.git')
	{
		$File::Find::prune = 1;
		return;
	}

	return if !-f $File::Find::name || -l $File::Find::name;

	# skip file names with binary extensions
	# How are these updated?  bjm 2012-01-02
	return if ($_ =~ m/\.(ico|bin)$/);

	my @lines;
	tie @lines, "Tie::File", $File::Find::name;

	foreach my $line (@lines)
	{

		# We only care about lines with a copyright notice.
		next unless $line =~ m/$cc.*$pgdg/;

		# Skip line if already matches the current year; if not
		# we get $year-$year, e.g. 2012-2012
		next if $line =~ m/$cc$year, $pgdg/;

		# We process all lines because some files have copyright
		# strings embedded in them, e.g. src/bin/psql/help.c
		$line =~ s/($cc\d{4})(, $pgdg)/$1-$year$2/;
		$line =~ s/($cc\d{4})-\d{4}(, $pgdg)/$1-$year$2/;
	}
	untie @lines;
}

print
"Manually update doc/src/sgml/legal.sgml and src/interfaces/libpq/libpq.rc.in too.\n";
print
"Also update ./COPYRIGHT and doc/src/sgml/legal.sgml in all back branches.\n";