#!/usr/bin/perl -w

use strict;
use warnings;
use Test::Repocop::Log;
use Test::Repocop::PkgId;
use Test::Repocop::Metadata;
use Test::Repocop::CLI::Base;
our @ISA=qw/Test::Repocop::CLI/;
our @LONGOPT_POD2USAGE=qw/-verbose 1 -exitval 1/;
my $column=1;
our @LONGOPT=(
    "column=i"  => \$column,
);
__PACKAGE__->get_and_process_cli_options();
&Test::Repocop::Workdir::die_if_nothing_to_report();

my $metadata=Test::Repocop::Metadata->new();
# in perl, column counting is from 0.
$column--;
while (<>) {
    my @line=split(/\s+/,$_);
    my $patch=$line[$column];
    next unless $patch; # empty line ?
    my $id=&Test::Repocop::PkgId::patchname2srcid($patch);
    my $name=$metadata->name($id);
    if (not $name) {
	warn "$patch: name not found\n";
	next;
    }
    &repocop_note("name=$name patch: $patch");
    print $name."\t$_";
}

__END__

=head1	NAME

repocop-filter-list-diff-prepend-name - prepend src.rpm name to the list of repocop patches.

=head1	SYNOPSIS

B<repocop-filter-list-diff-prepend-name>
[B<-c|--column> I<N>]
[B<-h|--help>]
[B<-v|--verbose>]
[B<-q|--quiet>]
[B<--workdir> I<workdir>]

=head1	DESCRIPTION

B<repocop-filter-list-diff-prepend-name> prepends a column <name><tab>
to a batch file with the list of repocop patches

=head1	OPTIONS

=over

=item	B<-c, --column> I<N>

The column containing source rpm patch (counting from 1).

=item	B<--workdir> I<dir>

Provides alternative location for the Repocop workdir. Repocop workdir
is a place where test results and packages metadata information are stored.
Default is I<~/.repocop>.

=item	B<-h, --help>

Display this help and exit.

=item	B<-v, --verbose>, B<-q, --quiet>

Verbosity level. Multiple -v increase the verbosity level, -q sets it to 0.


=back

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	ACKNOWLEGEMENTS

To Alexey Torbin <at@altlinux.org>, whose qa-robot package
had a strong influence on repocop.

=head1	COPYING

Copyright (c) 2008-2022 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

=cut
