1#!/usr/bin/perl -w 2 3my @output_buffer = (); 4my $fname; 5my $detectedSomeGuff = 0; 6sub pure_guff($) 7{ 8 my $array = shift; 9 my @lines = @{$array}; 10 my $contains_sense = ''; 11 my $contains_guff = ''; 12 while (scalar @lines) 13 { 14 my $line = pop @lines; 15 if ($line =~ m/Test run started :/ || 16 $line =~ m/ITEM Assertion OK/ || 17 $line =~ m/Test run finished :/) { 18 $contains_guff = '1'; 19 } elsif ($line =~ m/^[\+\-][^\-\+]/) { 20 $contains_sense = '1'; 21 } 22 } 23 if ($contains_guff && $contains_sense) { 24 print STDERR "Patch fragment with mixed good/bad changes in '$ARGV' near $line_index\n"; 25 $contains_guff = ''; 26 } 27 elsif ( $contains_guff ) { 28 $detectedSomeGuff++; 29 } 30# print "contains guff: $contains_guff\n"; 31 return $contains_guff; 32} 33 34sub output_lines($) 35{ 36 my $array = shift; 37 my @lines = @{$array}; 38 39 if (pure_guff (\@lines)) { 40 return; 41 } 42 43 while (scalar @lines) 44 { 45 my $line = pop @lines; 46 push @output_buffer, $line; 47 } 48} 49 50my $header; 51my @lines; 52my $frag_count = 0; 53$line_index = 0; 54 55while (<>) { 56 if (/^\@\@/ || /^[^ \-\+]/) { 57 output_lines (\@lines); 58 @lines = (); 59 $frag_count++; 60 } 61 unshift @lines, $_; 62 $line_index++; 63 close ARGV if eof; 64} 65output_lines(\@lines); 66 67# $detectedSomeGuff contains the skipped hunks that contain acceptable diff 68# e.g. a timestamp or an OK assertion that contains different content 69# like perhaps a path 70#print "frag_count = $frag_count fragstocount = $fragstocount detectedSomeGuff = $detectedSomeGuff \n"; 71if ($frag_count > $detectedSomeGuff) { 72 print @output_buffer; 73} 74