#!/usr/bin/perl -w use strict; my %ihdr = (); my %idir = (); my @sall = (); my @sinc = (); open(my $fh, "-|", "git grep '^[ \t]*#[ \t]*include[ \t]'") or die "can't run git grep: $!"; while (<$fh>) { m,^([^:/]*)/?[^:/]*:[ \t]*#[ \t]*include[ \t]*(["<])([^">]*),; my $dir = $1 // "."; my $delim = $2; my $h = $3; $ihdr{$h} |= 1 << ($delim eq "<"); if (exists $idir{$h}) { my $aref = $idir{$h}; push @$aref, $dir unless grep($_ eq $dir, @$aref); } else { $idir{$h} = [$dir]; } } close ($fh); open($fh, "-|", "git ls-tree -r --name-only HEAD") or die "can't run git ls-tree: $!"; while (<$fh>) { chomp; push @sall, $_; } close ($fh); @sinc = grep(/^include\//, @sall); sub pr { my ($h, $fn, $src) = @_; print "$h -> $fn"; if ($ihdr{$h} == 3) { print " (included inconsistently)"; } elsif ($src) { print " (included with <>)" if ($ihdr{$h} != 1); } else { print " (included with \"\")" if ($ihdr{$h} != 2); } print "\n"; } for my $h (keys %ihdr) { $h =~ m,^(\.\./)*(include/)?(.*), or die; my $hh = $3; my @fn = grep(/^include\/\Q$hh\E$/, @sinc); if (@fn) { pr($h, $fn[0], 1); next; } @fn = grep(/^\Q$hh\E$/, @sall); if (@fn) { pr($h, $fn[0], 1); next; } for my $dir (@{$idir{$h}}) { next if $dir eq "."; @fn = grep(/^\Q$dir\/$hh\E$/, @sall); if (@fn) { pr($h, $fn[0], 1); } else { pr($h, "? (in $dir)", 0); } } }