* update-copyright: Silently skip nonexistent files. Display filename on
update. Don't update non-Red Hat copyrights.
This commit is contained in:
		| @@ -1,3 +1,8 @@ | |||||||
|  | 2013-01-20  Christopher Faylor  <me.cygwin2013@cgf.cx> | ||||||
|  |  | ||||||
|  | 	* update-copyright: Silently skip nonexistent files.  Display filename | ||||||
|  | 	on update.  Don't update non-Red Hat copyrights. | ||||||
|  |  | ||||||
| 2013-01-20  Christopher Faylor  <me.cygwin2013@cgf.cx> | 2013-01-20  Christopher Faylor  <me.cygwin2013@cgf.cx> | ||||||
|  |  | ||||||
| 	* update-copyright: Update standard copyright information based on cvs | 	* update-copyright: Update standard copyright information based on cvs | ||||||
|   | |||||||
| @@ -21,7 +21,8 @@ while (<$cvs>) { | |||||||
|     } elsif (/^date: (\d+)/o) { |     } elsif (/^date: (\d+)/o) { | ||||||
| 	$files{$file}{$1} = 1; | 	$files{$file}{$1} = 1; | ||||||
|     } elsif (/^=+$/o) { |     } elsif (/^=+$/o) { | ||||||
| 	update_maybe($file, %{delete $files{$file}}); | 	my $rec = delete $files{$file}; | ||||||
|  | 	update_maybe($file, %{$rec}) if -e $file; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| close $cvs; | close $cvs; | ||||||
| @@ -29,8 +30,9 @@ close $cvs; | |||||||
| exit 0; | exit 0; | ||||||
|  |  | ||||||
| sub addwrap($$) { | sub addwrap($$) { | ||||||
|     my $copyright = shift; |  | ||||||
|     my $indent = shift; |     my $indent = shift; | ||||||
|  |     my $copyright = shift; | ||||||
|  |     $copyright =~ s/Red Hat\n/Red Hat, Inc.\n/so; | ||||||
|     return $copyright if length($copyright) <= 80; |     return $copyright if length($copyright) <= 80; | ||||||
|     my @lines; |     my @lines; | ||||||
|     while (length($copyright) > 80) { |     while (length($copyright) > 80) { | ||||||
| @@ -39,7 +41,7 @@ sub addwrap($$) { | |||||||
| 	substr($copyright, 0, $i + 1) = $indent; | 	substr($copyright, 0, $i + 1) = $indent; | ||||||
|     } |     } | ||||||
|     push @lines, $copyright unless $copyright =~ /^\s*$/o; |     push @lines, $copyright unless $copyright =~ /^\s*$/o; | ||||||
|     return @lines; |     return join('', @lines); | ||||||
| } | } | ||||||
|  |  | ||||||
| sub update_maybe($%) { | sub update_maybe($%) { | ||||||
| @@ -48,26 +50,33 @@ sub update_maybe($%) { | |||||||
|     my %dates = @_; |     my %dates = @_; | ||||||
|     my @file = (); |     my @file = (); | ||||||
|     my $copyright = ''; |     my $copyright = ''; | ||||||
|     my $modified = 1; |     my $modified = 0; | ||||||
|     while (<>) { |     while (<>) { | ||||||
| 	if ($copyright) { | 	if ($copyright) { | ||||||
| 	    push @file, $_; | 	    push @file, $_; | ||||||
| 	} elsif (/^\s*Copyright/o) { | 	} elsif (/^\s*Copyright/o) { | ||||||
| 	    $copyright = $_; | 	    $copyright = $_; | ||||||
| 	    $copyright .= scalar <> while $copyright =~ /,\s*$/o; | 	    $copyright .= scalar <> while $copyright =~ /,\s*$/o; | ||||||
|  | 	    if ($copyright !~ /Red Hat, Inc\.\n/o) { | ||||||
|  | 		push @file, $copyright; | ||||||
|  | 		next; | ||||||
|  | 	    } | ||||||
| 	    for my $date ($copyright =~ /(\d+)/g) { | 	    for my $date ($copyright =~ /(\d+)/g) { | ||||||
| 		$dates{$date} = 1; | 		$dates{$date} = 1; | ||||||
| 	    } | 	    } | ||||||
| 	    my $indent = ($copyright =~ /\A(\s*)/o)[0]; | 	    my $indent = ($copyright =~ /\A(\s*)/o)[0]; | ||||||
| 	    $copyright = $indent . 'Copyright ' . | 	    my $newcopyright = addwrap $indent, | ||||||
| 			(join ', ', sort {$a <=> $b} sort keys %dates) . | 				       $indent . 'Copyright ' . | ||||||
| 			" Red Hat\n"; | 				       (join ', ', sort {$a <=> $b} sort keys %dates) . | ||||||
| 	    push @file, addwrap($copyright, $indent); | 				       " Red Hat, Inc.\n"; | ||||||
|  | 	    push @file, $newcopyright; | ||||||
|  | 	    $modified = $newcopyright ne $copyright; | ||||||
| 	} else { | 	} else { | ||||||
| 	    push @file, $_; | 	    push @file, $_; | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|     if ($modified) { |     if ($modified) { | ||||||
|  | 	print "updating $f\n"; | ||||||
| 	my $fcopy = "$f.copyright"; | 	my $fcopy = "$f.copyright"; | ||||||
| 	rename $f, $fcopy or die "$0: couldn't rename $f -> $fcopy - $!\n"; | 	rename $f, $fcopy or die "$0: couldn't rename $f -> $fcopy - $!\n"; | ||||||
| 	my $st = stat($fcopy); | 	my $st = stat($fcopy); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user