#!/usr/bin/perl -w
#
# manidiff.pl
#
# Check the contents of the MANIFEST file against a second
# tree
# most^Wall but 4 lines stolen from manicheck.pl

use strict;

# assuming we are in root of current CVS tree
my $other_tree = '../parrot';

# CVS built-in patterns
my @base_patterns = qw(^CVS$ ^\.cvsignore$ ^core$ ^.*\.o$);

use ExtUtils::Manifest;

my $manifest = ExtUtils::Manifest::maniread();
my $filelist = ExtUtils::Manifest::manifind();

my @ignore_dirs = grep { m#(^|/)\.cvsignore$#; } keys %$filelist;

@ignore_dirs = map { s#(^|/)\.cvsignore$##; $_ } @ignore_dirs;

my %ignore_dirs;

foreach my $dir (@ignore_dirs) {
  my $cvsignore = $dir ne '' ? "$dir/.cvsignore" : '.cvsignore';

  open CVSIGNORE, "<$cvsignore" or die "Could not open $cvsignore.\n";
  my @patterns = <CVSIGNORE>;
  close CVSIGNORE;
  @patterns = map { chomp; s/\*/.*/g; "^$_\$"; } @patterns;

  $ignore_dirs{$dir} = [ @patterns, @base_patterns ];
}


foreach (keys %$manifest) {
    my $other = "$other_tree/$_";
    print `diff -bBq $_ $other`;
}

