--- loncom/build/filecompare.pl 2001/10/26 00:18:54 1.1 +++ loncom/build/filecompare.pl 2001/11/05 02:57:21 1.2 @@ -2,7 +2,7 @@ # Scott Harrison # YEAR=2001 -# 9/27, 10/24, 10/25 +# 9/27, 10/24, 10/25, 11/4 my $invocation=<( + sub { + print 'cvstime: '.@_[0]; + return; + } + ), 'age'=>( sub { print 'age: '.@_[0]; @@ -198,11 +216,20 @@ my %MEASURE=( return ($rv1,$rv2); } ), + 'cvstime'=>( + sub { + my ($file1,$file2)=@_; + my $rv1=&cvstime($file1); + my @a=stat($file2); my $gmt=gmtime($a[9]); + my $rv2=&utctime($gmt); + return ($rv1,$rv2); + } + ), 'age'=>( sub { my ($file1,$file2)=@_; - my @a=stat($file1); my $rv1=$a[10]; - @a=stat($file2); my $rv2=$a[10]; + my @a=stat($file1); my $rv1=$a[9]; + @a=stat($file2); my $rv2=$a[9]; return ($rv1,$rv2); } ), @@ -247,15 +274,18 @@ FLOP: foreach my $file (@files) { } my ($existence1,$existence2)=&{$MEASURE{'existence'}}($file1,$file2); my $existence=$existence1.':'.$existence2; - my ($md5sum,$age,$size,$lines,$diffs); + my ($cvstime,$md5sum,$age,$size,$lines,$diffs); if ($existence1 eq 'no' or $existence2 eq 'no') { $md5sum='n/a'; $age='n/a'; + $cvstime='n/a'; $size='n/a'; $lines='n/a'; $diffs='n/a'; } else { + my ($cvstime1,$cvstime2)=&{$MEASURE{'cvstime'}}($file1,$file2); + $cvstime=$cvstime1-$cvstime2; my ($age1,$age2)=&{$MEASURE{'age'}}($file1,$file2); $age=$age1-$age2; my ($md5sum1,$md5sum2)=&{$MEASURE{'md5sum'}}($file1,$file2); @@ -282,7 +312,7 @@ FLOP: foreach my $file (@files) { if ($show eq 'different') { my @ks=(keys %restrict); unless (@ks) { - @ks=('existence','md5sum','age','size','lines','diffs'); + @ks=('existence','cvstime','md5sum','age','size','lines','diffs'); } FLOP2: for my $key (@ks) { if ($key eq 'existence') { @@ -295,6 +325,11 @@ FLOP: foreach my $file (@files) { $showflag=1; } } + elsif ($key eq 'cvstime') { + if ($cvstime!=0) { + $showflag=1; + } + } elsif ($key eq 'age') { if ($age!=0) { $showflag=1; @@ -323,7 +358,7 @@ FLOP: foreach my $file (@files) { elsif ($show eq 'same') { my @ks=(keys %restrict); unless (@ks) { - @ks=('existence','md5sum','age','size','lines','diffs'); + @ks=('existence','md5sum','cvstime','age','size','lines','diffs'); } my $showcount=length(@ks); FLOP3: for my $key (@ks) { @@ -337,6 +372,11 @@ FLOP: foreach my $file (@files) { $showcount--; } } + elsif ($key eq 'cvstime') { + if ($cvstime!=0) { + $showcount--; + } + } elsif ($key eq 'age') { if ($age!=0) { $showcount--; @@ -362,11 +402,51 @@ FLOP: foreach my $file (@files) { $showflag=1; } } + if ($buildmode==1) { + if ($md5sum eq 'same') { + exit(1); + } + elsif ($cvstime<0) { + exit(2); + } + else { + exit(0); + } + } + elsif ($buildmode==2) { + if ($cvstime<0) { + exit(2); + } + else { + exit(0); + } + } + elsif ($buildmode==3) { + if ($md5sum eq 'same') { + exit(1); + } + elsif ($age<0) { + exit(2); + } + else { + exit(0); + } + } + elsif ($buildmode==4) { + if ($cvstime>0) { + exit(2); + } + else { + exit(0); + } + } print "$file"; if ($verbose==1) { print "\t"; print &{$OUTPUT{'existence'}}($existence); print "\t"; + print &{$OUTPUT{'cvstime'}}($cvstime); + print "\t"; print &{$OUTPUT{'age'}}($age); print "\t"; print &{$OUTPUT{'md5sum'}}($md5sum); @@ -380,5 +460,39 @@ FLOP: foreach my $file (@files) { print "\n"; } +sub cvstime { + my ($f)=@_; + my $path; my $file; + if ($f=~/^(.*\/)(.*?)$/) { + $f=~/^(.*\/)(.*?)$/; + ($path,$file)=($1,$2); + } + else { + $file=$f; $path=''; + } + my $cvstime; + if ($buildmode!=3) { + my $entry=`grep '^/$file/' ${path}CVS/Entries` or + die('*** ERROR *** cannot grep against '.${path}. + 'CVS/Entries for ' .$file . "\n"); + my @fields=split(/\//,$entry); + $cvstime=`date -d '$fields[3] UTC' --utc +"%s"`; + chomp $cvstime; + } + else { + $cvstime='n/a'; + } + return $cvstime; +} +sub utctime { + my ($f)=@_; + my $utctime=`date -d '$f UTC' --utc +"%s"`; + chomp $utctime; + return $utctime; +} +sub dowarn { + my ($msg)=@_; + warn($msg) unless $buildmode; +}