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