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