1cdf0e10cSrcweir#!/usr/bin/perl -w 2*bb113e63SAndrew Rist# ************************************************************* 3*bb113e63SAndrew Rist# 4*bb113e63SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 5*bb113e63SAndrew Rist# or more contributor license agreements. See the NOTICE file 6*bb113e63SAndrew Rist# distributed with this work for additional information 7*bb113e63SAndrew Rist# regarding copyright ownership. The ASF licenses this file 8*bb113e63SAndrew Rist# to you under the Apache License, Version 2.0 (the 9*bb113e63SAndrew Rist# "License"); you may not use this file except in compliance 10*bb113e63SAndrew Rist# with the License. You may obtain a copy of the License at 11*bb113e63SAndrew Rist# 12*bb113e63SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 13*bb113e63SAndrew Rist# 14*bb113e63SAndrew Rist# Unless required by applicable law or agreed to in writing, 15*bb113e63SAndrew Rist# software distributed under the License is distributed on an 16*bb113e63SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17*bb113e63SAndrew Rist# KIND, either express or implied. See the License for the 18*bb113e63SAndrew Rist# specific language governing permissions and limitations 19*bb113e63SAndrew Rist# under the License. 20*bb113e63SAndrew Rist# 21*bb113e63SAndrew Rist# ************************************************************* 22cdf0e10cSrcweir 23cdf0e10cSrcweirmy @output_buffer = (); 24cdf0e10cSrcweirmy $fname; 25cdf0e10cSrcweirmy $detectedSomeGuff = 0; 26cdf0e10cSrcweirsub pure_guff($) 27cdf0e10cSrcweir{ 28cdf0e10cSrcweir my $array = shift; 29cdf0e10cSrcweir my @lines = @{$array}; 30cdf0e10cSrcweir my $contains_sense = ''; 31cdf0e10cSrcweir my $contains_guff = ''; 32cdf0e10cSrcweir while (scalar @lines) 33cdf0e10cSrcweir { 34cdf0e10cSrcweir my $line = pop @lines; 35cdf0e10cSrcweir if ($line =~ m/Test run started :/ || 36cdf0e10cSrcweir $line =~ m/ITEM Assertion OK/ || 37cdf0e10cSrcweir $line =~ m/Test run finished :/) { 38cdf0e10cSrcweir $contains_guff = '1'; 39cdf0e10cSrcweir } elsif ($line =~ m/^[\+\-][^\-\+]/) { 40cdf0e10cSrcweir $contains_sense = '1'; 41cdf0e10cSrcweir } 42cdf0e10cSrcweir } 43cdf0e10cSrcweir if ($contains_guff && $contains_sense) { 44cdf0e10cSrcweir print STDERR "Patch fragment with mixed good/bad changes in '$ARGV' near $line_index\n"; 45cdf0e10cSrcweir $contains_guff = ''; 46cdf0e10cSrcweir } 47cdf0e10cSrcweir elsif ( $contains_guff ) { 48cdf0e10cSrcweir $detectedSomeGuff++; 49cdf0e10cSrcweir } 50cdf0e10cSrcweir# print "contains guff: $contains_guff\n"; 51cdf0e10cSrcweir return $contains_guff; 52cdf0e10cSrcweir} 53cdf0e10cSrcweir 54cdf0e10cSrcweirsub output_lines($) 55cdf0e10cSrcweir{ 56cdf0e10cSrcweir my $array = shift; 57cdf0e10cSrcweir my @lines = @{$array}; 58cdf0e10cSrcweir 59cdf0e10cSrcweir if (pure_guff (\@lines)) { 60cdf0e10cSrcweir return; 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir while (scalar @lines) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir my $line = pop @lines; 66cdf0e10cSrcweir push @output_buffer, $line; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir} 69cdf0e10cSrcweir 70cdf0e10cSrcweirmy $header; 71cdf0e10cSrcweirmy @lines; 72cdf0e10cSrcweirmy $frag_count = 0; 73cdf0e10cSrcweir$line_index = 0; 74cdf0e10cSrcweir 75cdf0e10cSrcweirwhile (<>) { 76cdf0e10cSrcweir if (/^\@\@/ || /^[^ \-\+]/) { 77cdf0e10cSrcweir output_lines (\@lines); 78cdf0e10cSrcweir @lines = (); 79cdf0e10cSrcweir $frag_count++; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir unshift @lines, $_; 82cdf0e10cSrcweir $line_index++; 83cdf0e10cSrcweir close ARGV if eof; 84cdf0e10cSrcweir} 85cdf0e10cSrcweiroutput_lines(\@lines); 86cdf0e10cSrcweir 87cdf0e10cSrcweir# $detectedSomeGuff contains the skipped hunks that contain acceptable diff 88cdf0e10cSrcweir# e.g. a timestamp or an OK assertion that contains different content 89cdf0e10cSrcweir# like perhaps a path 90cdf0e10cSrcweir#print "frag_count = $frag_count fragstocount = $fragstocount detectedSomeGuff = $detectedSomeGuff \n"; 91cdf0e10cSrcweirif ($frag_count > $detectedSomeGuff) { 92cdf0e10cSrcweir print @output_buffer; 93cdf0e10cSrcweir} 94