#! /usr/bin/ruby

manifests = Hash.new {[]}
entries = Hash.new
duplicates = Hash.new(0)

Dir.glob("**/CVS/Entries") do |f|
  d = f.chomp("CVS/Entries")
  IO.foreach(f) do |l|
    %r"^/(.*?)/" === l or next
    $1 == ".cvsignore" and next
    entries["#{d}#$1"] = true
  end
  if File.exist?(f = "#{d}MANIFEST")
    IO.foreach(f) do |l|
      l.chomp!
      l = "#{d}#{l}"
      manifests[l] <<= f
      duplicates[l] += 1
    end
  end
end

missing = entries.keys - manifests.keys
unless missing.empty?
  puts "*** missing in MANIFEST", missing.sort
end
missing = manifests.keys - entries.keys
unless missing.empty?
  puts "*** not found in MANIFEST", missing.sort
end
duplicates.delete_if {|k, v| v == 1}
unless duplicates.empty?
  puts "*** duplicates in MANIFEST"
  duplicates.each {|f,|print "#{f}\t", manifests[f].join(" "), "\n"}
end
