#!/usr/bin/perl

use strict;
use warnings;
#use Pod::Usage;
#use Getopt::Long;
use Data::Array2ArrayMap::Hash::XSTree;

#my $help=0;
#my $limit=1;
#my $result = GetOptions (
#    "help"  => \$help,
#    "limit=i"  => \$limit,
#);
#if ($help) {
#    pod2usage();
#}

my $CONFLICT=Data::Array2ArrayMap::Hash::XSTree->new();
# TODO: with an option, output into separate file, for experimental level messages?
my $DEBUGINFO=Data::Array2ArrayMap::Hash::XSTree->new();

while (<>) {
    next if /^\s*$/;
    chomp;
    my ($pkg1,$pkg2,$file1)=split(/\t/,$_);
    # delete debuginfo <-> debuginfo confilcts (see https://bugzilla.altlinux.org/show_bug.cgi?id=28467)
    # also #30862 /usr/lib/debug/bin/mail.debug ...
    if ($pkg1 =~ /-debuginfo-[^-]+-[^-]+$/ and $pkg2 =~ /-debuginfo-[^-]+-[^-]+$/) {
	$DEBUGINFO->append([$pkg1,$pkg2],[$file1]);
    } else {
	$CONFLICT->append([$pkg1,$pkg2],[$file1]);
    }
}

foreach my $pkg1 (sort $CONFLICT->keys_at([])) {
    foreach my $pkg2 (sort $CONFLICT->keys_at([$pkg1])) {
	my @conflicts=$CONFLICT->get([$pkg1,$pkg2]);
	#print "CONFL for $pkg1,$pkg2 = @conflicts\n";
	my $msg;
	if (@conflicts==1) {
	    $msg="File $conflicts[0] conflicts with the package $pkg2.";
	} elsif (@conflicts<4) {
	    $msg='Files '.join(' ',@conflicts)." conflict with the package $pkg2.";
	} else {
	    $msg="There are file conflicts with the package $pkg2, for example, $conflicts[0] (".scalar @conflicts." file conflicts in total).";
	}
	$msg.=' Moreover, the packages have no explicit conflicts with each other. You should add explicit conflicts, or, if conflicts are avoidable, consider using alternatives.';
	print "$pkg1\t$msg\n";
    }
}





=head1	NAME

repocop-unittest-rpm-filesystem-message-helper - internal test helper, not for public use

