[Reproducible-commits] [strip-nondeterminism] 01/05: javadoc: normalize the <META NAME="date"> header
Andrew Ayer
agwa at andrewayer.name
Thu Feb 5 18:22:23 UTC 2015
This is an automated email from the git hooks/post-receive script.
agwa-guest pushed a commit to branch master
in repository strip-nondeterminism.
commit 4ae56f5d44dfd0443443eaacb5f3d5ef7733af7b
Author: Andrew Ayer <agwa at andrewayer.name>
Date: Thu Feb 5 10:01:19 2015 -0800
javadoc: normalize the <META NAME="date"> header
Thanks: Peter De Wachter
Closes: #775870
---
lib/File/StripNondeterminism/handlers/javadoc.pm | 49 ++++++++++++++++--------
1 file changed, 32 insertions(+), 17 deletions(-)
diff --git a/lib/File/StripNondeterminism/handlers/javadoc.pm b/lib/File/StripNondeterminism/handlers/javadoc.pm
index 095e98e..59f2519 100644
--- a/lib/File/StripNondeterminism/handlers/javadoc.pm
+++ b/lib/File/StripNondeterminism/handlers/javadoc.pm
@@ -23,6 +23,7 @@ use warnings;
use File::Temp;
use File::Basename;
+use POSIX qw(strftime);
sub is_javadoc_file {
my ($filename) = @_;
@@ -40,30 +41,44 @@ sub normalize {
my $tempfile = File::Temp->new(DIR => dirname($filename));
# Strip the javadoc comment, which contains a timestamp.
- # It should appear within first 10 lines.
- while (defined(my $line = <$fh>) && $. <= 10) {
+ # It should appear before a line containing </head>, which should be within first 15 lines.
+ my $modified = 0;
+ while (defined(my $line = <$fh>)) {
if ($line =~ /\<!-- Generated by javadoc .* --\>/) {
$line =~ s/\<!-- Generated by javadoc .* --\>//g;
print $tempfile $line unless $line =~ /^\s*$/; # elide lines that are now whitespace-only
-
- # Copy through rest of file
- my $bytes_read;
- my $buf;
- while ($bytes_read = read($fh, $buf, 4096)) {
- print $tempfile $buf;
+ $modified = 1;
+ } elsif ($line =~ /\<META NAME="date" CONTENT="[^"]*"\>/i) {
+ if (defined $File::StripNondeterminism::canonical_time) {
+ my $date = strftime('%Y-%m-%d', localtime($File::StripNondeterminism::canonical_time));
+ $line =~ s/\<META NAME="date" CONTENT="[^"]*"\>/<META NAME="date" CONTENT="$date">/gi;
+ } else {
+ $line =~ s/\<META NAME="date" CONTENT="[^"]*"\>//gi;
}
- defined($bytes_read) or die "$filename: read failed: $!";
-
- # Rename temporary file over the file
- chmod((stat($fh))[2] & 07777, $tempfile->filename);
- rename($tempfile->filename, $filename) or die "$filename: unable to overwrite: rename: $!";
- $tempfile->unlink_on_destroy(0);
- return 1;
+ print $tempfile $line unless $line =~ /^\s*$/; # elide lines that are now whitespace-only
+ $modified = 1;
+ } else {
+ print $tempfile $line;
}
- print $tempfile $line;
+ last if $. == 15 or $line =~ /\<\/head\>/i;
}
- return 0;
+ return 0 if not $modified;
+
+ # Copy through rest of file
+ my $bytes_read;
+ my $buf;
+ while ($bytes_read = read($fh, $buf, 4096)) {
+ print $tempfile $buf;
+ }
+ defined($bytes_read) or die "$filename: read failed: $!";
+
+ # Rename temporary file over the file
+ chmod((stat($fh))[2] & 07777, $tempfile->filename);
+ rename($tempfile->filename, $filename) or die "$filename: unable to overwrite: rename: $!";
+ $tempfile->unlink_on_destroy(0);
+
+ return 1;
}
1;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/strip-nondeterminism.git
More information about the Reproducible-commits
mailing list