#!/usr/bin/perl
# This is a helper to inspect gcc-x.y package's patches,
# looking for those applicable to gcc-x.y-doc.
# 
# Usage:
# $ cd gcc-x.y/debian/patches
# $ perl $PATH_TO_ME/check_gcc_patches *.diff
use strict;
use warnings;

my $interest =
    qr{ 
        \.7$
        | \.texi$
        | texi2pod\.pl$
        | (xgnatugn.adb|ug_words)$
    }x;

my %inspect = ();
for my $patch (@ARGV) {
    print "Parsing $patch\n";
    open my $fh, "-|", qw(diffstat -l), $patch;
    while (<$fh>) {
        chomp;
        if (m/$interest/) {
            print "Match: $_\n";
            $inspect{$patch} = 1;
        }
    }
}

print "\n";
print "# Interesting patches:\n";
for my $patch (sort keys %inspect) {
    print "# grepping for $patch in rules.patch\n";
    my $base = $patch;
    $base =~ s/\.diff//;
    system "grep", "-n", "-B", "5", "$base", "../rules.patch";
    print "\n";
}

print "# you can add notes with this template\n";
for my $patch (sort keys %inspect) {
    print "# $patch\n";
}
