2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

Merged 'rt28345': new git-based merge_copyrights

This commit is contained in:
Evan Hunt
2012-03-09 15:57:35 -08:00
parent b0c3e518e4
commit af9dbf1ccd
4 changed files with 58 additions and 37 deletions

View File

@@ -3236,6 +3236,7 @@
./util/check-pullups.pl PERL 2001,2002,2003,2004,2007 ./util/check-pullups.pl PERL 2001,2002,2003,2004,2007
./util/check-sources.pl PERL 2000,2001,2004,2007 ./util/check-sources.pl PERL 2000,2001,2004,2007
./util/copyrights X 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012 ./util/copyrights X 1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012
./util/file_year.sh SH 2012
./util/kit.sh SH 2000,2001,2002,2003,2004,2007,2008,2009,2010,2012 ./util/kit.sh SH 2000,2001,2002,2003,2004,2007,2008,2009,2010,2012
./util/mandoc2docbook.pl PERL 2001,2004,2007 ./util/mandoc2docbook.pl PERL 2001,2004,2007
./util/mdnbuildtest.sh SH 2000,2001,2004,2007 ./util/mdnbuildtest.sh SH 2000,2001,2004,2007
@@ -3246,6 +3247,7 @@
./util/nanny.pl PERL 2000,2001,2004,2007 ./util/nanny.pl PERL 2000,2001,2004,2007
./util/new-func PERL 2005,2007 ./util/new-func PERL 2005,2007
./util/nt-kit SH 1999,2000,2001,2004,2007 ./util/nt-kit SH 1999,2000,2001,2004,2007
./util/recent_changes.sh SH 2012
./util/spacewhack.pl PERL 2000,2001,2004,2007 ./util/spacewhack.pl PERL 2000,2001,2004,2007
./util/tabify-changes SH 2004,2007 ./util/tabify-changes SH 2004,2007
./util/update-drafts.pl PERL 2000,2001,2004,2007 ./util/update-drafts.pl PERL 2000,2001,2004,2007

7
util/file_year.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
# Given a file in the currently checked-out branch of the Git
# repository, find out in what year it was most recently committed.
# Used by merge_copyrights.
rev=`git rev-list HEAD -- "$1" | head -n 1`
git show --pretty=format:%ai $rev | head -n 1 | sed 's;-.*;;'

View File

@@ -17,29 +17,42 @@
# $Id$ # $Id$
%file_types = (); use strict;
%file_years = ();
my %file_types = ();
my %file_years = ();
my %exists = ();
open(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!"; open(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
while (<COPYRIGHTS>) { while (<COPYRIGHTS>) {
chomp; chomp;
($file, $type, $years) = split; my ($file, $type, $years) = split;
$file_types{$file} = $type; $file_types{$file} = $type;
$file_years{$file} = $years; $file_years{$file} = $years;
} }
close(COPYRIGHTS); close(COPYRIGHTS);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time()); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time());
$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
$year += 1900; $year += 1900;
$find = "find . -type f -print"; open(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
open(FILES, "$find | sort |") || die "can't start \"$find\": $!";
while (<FILES>) { while (<FILES>) {
chomp; chomp;
$exists{$_} = 1;
}
close(FILES);
open(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
while (<CHANGES>) {
chomp;
# this file isn't in the repository now
next unless ($exists{$_});
next if (m%/\.\# | # CVS old conflict file next if (m%/\.\# | # CVS old conflict file
/CVS/ | # CVS directory /CVS/ | # CVS directory
/.git/ | # git directory
util/newcopyrights | # our output util/newcopyrights | # our output
\.bak$ | # created by update_copyrights \.bak$ | # created by update_copyrights
/(dnssafe|openssl)/.*\.[ch]$ | # imported /(dnssafe|openssl)/.*\.[ch]$ | # imported
@@ -49,6 +62,7 @@ while (<FILES>) {
if (!$file_types{$_}) { if (!$file_types{$_}) {
# Strip any .in extension to find out the file's real type. # Strip any .in extension to find out the file's real type.
# .in files are processed by configure to produce the target file. # .in files are processed by configure to produce the target file.
my $base;
($base = $_) =~ s/\.in$//; ($base = $_) =~ s/\.in$//;
# Contributed code should maintain its own copyright. # Contributed code should maintain its own copyright.
@@ -95,24 +109,13 @@ while (<FILES>) {
} else { } else {
$file_types{$_} = "?"; $file_types{$_} = "?";
} }
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, my $m_year = int(`sh util/file_year.sh $_`);
$blksize,$blocks) if ($m_year != $year) {
= stat($_);
($sec,$min,$hour,$mday,$mon,$c_year,$wday,$yday,$isdst) =
localtime($ctime);
($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
localtime($mtime);
$c_year += 1900;
$m_year += 1900;
if ($m_year != $year || $c_year != $year) {
print "$_: must set copyright year(s) manually\n"; print "$_: must set copyright year(s) manually\n";
$file_years{$_} = "????"; $file_years{$_} = "????";
} else { } else {
$file_years{$_} = "$year"; $file_years{$_} = "$year";
} }
# keep perl from issuing warnings about "used only once"
$dev = $ino = $mode = $nlink = $uid = $gid = $rdev = $size = 0;
$atime = $blksize = $blocks = 0;
} else { } else {
if (! defined($file_years{$_}) || $file_years{$_} eq "????") { if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
print "$_: must set copyright year(s) manually\n"; print "$_: must set copyright year(s) manually\n";
@@ -126,45 +129,42 @@ while (<FILES>) {
next if ($file_years{$_} =~ /^PARENT:/); next if ($file_years{$_} =~ /^PARENT:/);
next if ($file_years{$_} eq "DOCBOOK"); next if ($file_years{$_} eq "DOCBOOK");
@years = split(/,/, $file_years{$_}); my @years = split(/,/, $file_years{$_});
$has_current = 0; my $has_current = 0;
foreach $fyear (@years) { foreach my $fyear (@years) {
if ($fyear == $year) { if ($fyear == $year) {
$has_current = 1; $has_current = 1;
} }
} }
if (!$has_current) { if (!$has_current) {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
$blksize,$blocks)
= stat($_);
($sec,$min,$hour,$mday,$mon,$m_year,$wday,$yday,$isdst) =
localtime($mtime);
$m_year += 1900;
if ($m_year == $year) {
$file_years{$_} .= ",$year"; $file_years{$_} .= ",$year";
} }
} }
} }
} close(CHANGES);
close(FILES);
open(NEWCOPYRIGHTS, ">util/newcopyrights") || open(NEWCOPYRIGHTS, ">util/newcopyrights") ||
die "can't open newcopyrights: $!"; die "can't open newcopyrights: $!";
foreach $file (sort(keys(%file_types))) { foreach my $file (sort(keys(%file_types))) {
print NEWCOPYRIGHTS "$file"; print NEWCOPYRIGHTS "$file";
$len = length($file); my $len = length($file);
my $tabs = 0;
if ($len >= 48) { if ($len >= 48) {
$tabs = 1; $tabs = 1;
} else { } else {
$needed = int (48 - $len); my $needed = int (48 - $len);
$tabs = int ($needed / 8); $tabs = int ($needed / 8);
if ($needed % 8 != 0) { if ($needed % 8 != 0) {
$tabs++; $tabs++;
} }
} }
for ($i = 0; $i < $tabs; $i++) { for (my $i = 0; $i < $tabs; $i++) {
printf NEWCOPYRIGHTS "\t"; printf NEWCOPYRIGHTS "\t";
} }
printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file}; printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
print "Unknown file type or year: $file\n";
}
} }
close(NEWCOPYRIGHTS); close(NEWCOPYRIGHTS);

12
util/recent_changes.sh Normal file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
# Find the list of files that have been touched in the Git repository
# during the current calendar year. This is done by walking backwards
# through the output of "git whatchanged" until a year other than the
# current one is seen. Used by merge_copyrights.
thisyear=`date +%Y`
git whatchanged --pretty="date %ai" --date=iso8601 | awk -vre="${thisyear}-" '
$1 == "date" && $2 !~ re { exit(0); }
$1 == "date" { next; }
NF == 0 { next; }
$(NF-1) ~ /[AM]/ { print "./" $NF }' | sort | uniq