X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FPackages.pm;h=2cdef213fce3b89abec6349e5e909d1166fb97a7;hb=cd0b9752cb6b5cec796baf1c07951cee5971b42e;hp=6762d9aba4cbc2f9544331d9580b87c32e1a23dc;hpb=f94c6b9f4e4abdbe2d95c55edaaf8c81b0652c7b;p=debbugs.git diff --git a/Debbugs/Packages.pm b/Debbugs/Packages.pm index 6762d9a..2cdef21 100644 --- a/Debbugs/Packages.pm +++ b/Debbugs/Packages.pm @@ -39,7 +39,7 @@ use MLDBM qw(DB_File Storable); use Storable qw(dclone); use Params::Validate qw(validate_with :types); use Debbugs::Common qw(make_list globify_scalar sort_versions); - +use DateTime::Format::Pg; use List::AllUtils qw(min max uniq); use IO::File; @@ -221,6 +221,15 @@ sub binary_to_source{ my @archs = grep {defined $_} make_list(exists $param{arch}?$param{arch}:[]); return () unless @binaries; + my $cache_key = join("\1", + join("\0",@binaries), + join("\0",@versions), + join("\0",@archs), + join("\0",@param{qw(source_only scalar_only)})); + if (exists $param{cache}{$cache_key}) { + return $param{scalar_only} ? $param{cache}{$cache_key}[0]: + @{$param{cache}{$cache_key}}; + } # any src:foo is source package foo with unspecified version @source = map {/^src:(.+)$/? [$1,'']:()} @binaries; @@ -245,10 +254,10 @@ sub binary_to_source{ push @source, map {$_->{pkg}} $src_rs->all; if ($param{scalar_only}) { - return join(',',@source); + @source = join(',',@source); } - return @source; - + $param{cache}{$cache_key} = \@source; + return $param{scalar_only}?$source[0]:@source; } my $src_rs = $param{schema}->resultset('SrcVer')-> search_rs({'bin_pkg.pkg' => [@binaries], @@ -281,16 +290,8 @@ sub binary_to_source{ $_->{src_vers}{ver}, ]} $src_rs->all; } - return @source; - } - my $cache_key = join("\1", - join("\0",@binaries), - join("\0",@versions), - join("\0",@archs), - join("\0",@param{qw(source_only scalar_only)})); - if (exists $param{cache}{$cache_key}) { - return $param{scalar_only} ? $param{cache}{$cache_key}[0]: - @{$param{cache}{$cache_key}}; + $param{cache}{$cache_key} = \@source; + return $param{scalar_only}?$source[0]:@source; } for my $binary (@binaries) { _tie_binarytosource; @@ -404,8 +405,8 @@ empty list in list context. =item version -- binary package version(s) as a SCALAR or ARRAYREF; optional, defaults to all versions. -=item arch -- binary package architecture(s) as a SCALAR or ARRAYREF; -optional, defaults to all architectures. +=item dist -- list of distributions to return corresponding binary packages for +as a SCALAR or ARRAYREF. =item binary_only -- return only the source name (forced on if in SCALAR context), defaults to false. [If in LIST context, returns a list of binary @@ -430,6 +431,9 @@ sub source_to_binary{ version => {type => SCALAR|ARRAYREF, optional => 1, }, + dist => {type => SCALAR|ARRAYREF, + optional => 1, + }, binary_only => {default => 0, }, scalar_only => {default => 0, @@ -477,6 +481,18 @@ sub source_to_binary{ distinct => 1, }, ); + if (exists $param{dist}) { + $bin_rs = $bin_rs-> + search({-or => + {'suite.codename' => [make_list($param{dist})], + 'suite.suite_name' => [make_list($param{dist})], + }}, + {join => {'bin_vers' => + {'bin_associations' => + 'suite' + }}, + }); + } push @binaries, map {$_->{pkg}} $bin_rs->all; if ($param{scalar_only}) { @@ -721,8 +737,129 @@ sub get_versions{ largest_source_version_only => {type => BOOLEAN, default => 1, }, + schema => {type => OBJECT, + optional => 1, + }, }, - ); + ); + if (defined $param{schema}) { + my @src_packages; + my @bin_packages; + for my $pkg (make_list($param{package})) { + if ($pkg =~ /^src:(.+)/) { + push @src_packages, + $1; + } else { + push @bin_packages,$pkg; + } + } + + my $s = $param{schema}; + use Data::Printer; + p @src_packages; + my %return; + if (@src_packages) { + my $src_rs = $s->resultset('SrcVer')-> + search({'src_pkg.pkg'=>[@src_packages], + -or => {'suite.codename' => [make_list($param{dist})], + 'suite.suite_name' => [make_list($param{dist})], + } + }, + {join => ['src_pkg', + { + src_associations=>'suite'}, + ], + '+select' => [qw(src_pkg.pkg), + qw(suite.codename), + qw(src_associations.modified), + q(CONCAT(src_pkg.pkg,'/',me.ver))], + '+as' => ['src_pkg_name','codename', + 'modified_time', + qw(src_pkg_ver)], + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + order_by => {-desc => 'me.ver'}, + }, + ); + my %completed_dists; + for my $src ($src_rs->all()) { + my $val = 'source'; + if ($param{time}) { + $val = DateTime::Format::Pg-> + parse_datetime($src->{modified_time})-> + epoch(); + } + if ($param{largest_source_version_only}) { + next if $completed_dists{$src->{codename}}; + $completed_dists{$src->{codename}} = 1; + } + if ($param{source}) { + $return{$src->{src_pkg_ver}} = $val; + } else { + $return{$src->{ver}} = $val; + } + } + } + if (@bin_packages) { + my $bin_rs = $s->resultset('BinVer')-> + search({'bin_pkg.pkg' => [@bin_packages], + -or => {'suite.codename' => [make_list($param{dist})], + 'suite.suite_name' => [make_list($param{dist})], + }, + }, + {join => ['bin_pkg', + { + 'src_ver'=>'src_pkg'}, + { + bin_associations => 'suite'}, + 'arch', + ], + '+select' => [qw(bin_pkg.pkg arch.arch suite.codename), + qw(bin_associations.modified), + qw(src_pkg.pkg),q(CONCAT(src_pkg.pkg,'/',me.ver)), + ], + '+as' => ['bin_pkg','arch','codename', + 'modified_time', + 'src_pkg_name','src_pkg_ver'], + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + order_by => {-desc => 'src_ver.ver'}, + }); + if (exists $param{arch}) { + $bin_rs = + $bin_rs->search({'arch.arch' => [make_list($param{arch})]}, + { + join => 'arch'} + ); + } + my %completed_dists; + for my $bin ($bin_rs->all()) { + my $key = $bin->{ver}; + if ($param{source}) { + $key = $bin->{src_pkg_ver}; + } + my $val = $bin->{arch}; + if ($param{time}) { + $val = DateTime::Format::Pg-> + parse_datetime($bin->{modified_time})-> + epoch(); + } + if ($param{largest_source_version_only}) { + if ($completed_dists{$bin->{codename}} and not + exists $return{$key}) { + next; + } + $completed_dists{$bin->{codename}} = 1; + } + push @{$return{$key}}, + $val; + } + } + if ($param{return_archs}) { + if ($param{time} or $param{return_archs}) { + return wantarray?%return :\%return; + } + return wantarray?keys %return :[keys %return]; + } + } my $versions; if ($param{time}) { return () if not defined $gVersionTimeIndex; @@ -856,6 +993,9 @@ sub make_source_versions { warnings => {type => SCALARREF|HANDLE, optional => 1, }, + schema => {type => OBJECT, + optional => 1, + }, }, ); my ($warnings) = globify_scalar(exists $param{warnings}?$param{warnings}:undef);