2013-01-21 07:56:26 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
use File::stat;
|
|
|
|
sub update_maybe($%);
|
|
|
|
|
|
|
|
my $year = (split ' ', ~~localtime)[4];
|
|
|
|
my %dates = ();
|
|
|
|
my %files = ();
|
|
|
|
my $cvs;
|
|
|
|
open $cvs, '-|', '/usr/bin/cvs', 'update', @ARGV or die "cvs update failed - $!\n";
|
|
|
|
while (<$cvs>) {
|
|
|
|
/^M (.*)$/o and $files{$1}{$year} = 1;
|
|
|
|
}
|
|
|
|
close $cvs;
|
|
|
|
|
|
|
|
open $cvs, '-|', '/usr/bin/cvs', 'log', '-N', '-b', @ARGV or die "cvs log failed - $!\n";
|
|
|
|
my $file;
|
|
|
|
while (<$cvs>) {
|
|
|
|
if (/^Working file: (.*)$/o) {
|
|
|
|
$file = $1;
|
|
|
|
} elsif (/^date: (\d+)/o) {
|
|
|
|
$files{$file}{$1} = 1;
|
|
|
|
} elsif (/^=+$/o) {
|
2013-01-21 11:55:55 +08:00
|
|
|
my $rec = delete $files{$file};
|
|
|
|
update_maybe($file, %{$rec}) if -e $file;
|
2013-01-21 07:56:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close $cvs;
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
sub addwrap($$) {
|
|
|
|
my $indent = shift;
|
2013-01-21 11:55:55 +08:00
|
|
|
my $copyright = shift;
|
|
|
|
$copyright =~ s/Red Hat\n/Red Hat, Inc.\n/so;
|
2013-01-21 07:56:26 +08:00
|
|
|
return $copyright if length($copyright) <= 80;
|
|
|
|
my @lines;
|
|
|
|
while (length($copyright) > 80) {
|
|
|
|
my $i = index($copyright, ' ', 80 - 6);
|
|
|
|
push @lines, substr($copyright, 0, $i) . "\n";
|
|
|
|
substr($copyright, 0, $i + 1) = $indent;
|
|
|
|
}
|
|
|
|
push @lines, $copyright unless $copyright =~ /^\s*$/o;
|
2013-01-21 11:55:55 +08:00
|
|
|
return join('', @lines);
|
2013-01-21 07:56:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sub update_maybe($%) {
|
|
|
|
my $f = shift;
|
|
|
|
local @ARGV = $f;
|
|
|
|
my %dates = @_;
|
|
|
|
my @file = ();
|
|
|
|
my $copyright = '';
|
2013-01-21 11:55:55 +08:00
|
|
|
my $modified = 0;
|
2013-01-21 07:56:26 +08:00
|
|
|
while (<>) {
|
|
|
|
if ($copyright) {
|
|
|
|
push @file, $_;
|
2013-01-22 00:20:23 +08:00
|
|
|
} elsif (/^(?:dnl\s|[#\s]*)Copyright/o) {
|
2013-01-21 07:56:26 +08:00
|
|
|
$copyright = $_;
|
|
|
|
$copyright .= scalar <> while $copyright =~ /,\s*$/o;
|
2013-01-21 11:55:55 +08:00
|
|
|
if ($copyright !~ /Red Hat, Inc\.\n/o) {
|
|
|
|
push @file, $copyright;
|
|
|
|
next;
|
|
|
|
}
|
2013-01-21 07:56:26 +08:00
|
|
|
for my $date ($copyright =~ /(\d+)/g) {
|
|
|
|
$dates{$date} = 1;
|
|
|
|
}
|
2013-01-22 00:20:23 +08:00
|
|
|
my $indent = ($copyright =~ /\A(dnl\s+|[#\s]*)/o)[0];
|
2013-01-21 11:55:55 +08:00
|
|
|
my $newcopyright = addwrap $indent,
|
|
|
|
$indent . 'Copyright ' .
|
|
|
|
(join ', ', sort {$a <=> $b} sort keys %dates) .
|
|
|
|
" Red Hat, Inc.\n";
|
|
|
|
push @file, $newcopyright;
|
|
|
|
$modified = $newcopyright ne $copyright;
|
2013-01-21 07:56:26 +08:00
|
|
|
} else {
|
|
|
|
push @file, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($modified) {
|
2013-01-21 11:55:55 +08:00
|
|
|
print "updating $f\n";
|
2013-01-21 07:56:26 +08:00
|
|
|
my $fcopy = "$f.copyright";
|
|
|
|
rename $f, $fcopy or die "$0: couldn't rename $f -> $fcopy - $!\n";
|
|
|
|
my $st = stat($fcopy);
|
|
|
|
open my $fd, '>', $f;
|
|
|
|
chmod $st->mode & 07777, $f;
|
|
|
|
print $fd @file;
|
|
|
|
close $fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|