------------------------------------------------------------ revno: 907 committer: Debian BTS <debb...@rietz> branch nick: mainline timestamp: Thu 2009-09-10 20:58:41 +0000 message: merge changes from dla source ------------------------------------------------------------ revno: 738.3.187 committer: Don Armstrong <d...@donarmstrong.com> branch nick: source timestamp: Thu 2009-09-10 08:53:41 -0700 message: Ditch \r and \n in status fields (closes: #545895) ------------------------------------------------------------ revno: 738.3.186 committer: Don Armstrong <d...@donarmstrong.com> branch nick: source timestamp: Thu 2009-09-10 08:53:10 -0700 message: * set the date to zero in cases where the date is empty ------------------------------------------------------------ revno: 738.3.185 committer: Don Armstrong <d...@donarmstrong.com> branch nick: source timestamp: Wed 2009-09-09 18:54:21 -0700 message: * Rewrite binary_to_source to be more complete and understandable * Update Debbugs::SOAP to use binary_to_source; increment compatibility version * Change all usages of binarytosource to use binary_to_source
=== modified file 'Debbugs/Packages.pm' --- Debbugs/Packages.pm 2009-09-01 01:07:54 +0000 +++ Debbugs/Packages.pm 2009-09-10 20:58:39 +0000 @@ -25,7 +25,7 @@ @EXPORT = (); %EXPORT_TAGS = (versions => [qw(getversions get_versions make_source_versions)], mapping => [qw(getpkgsrc getpkgcomponent getsrcpkgs), - qw(binarytosource sourcetobinary makesourceversions) + qw(binary_to_source sourcetobinary makesourceversions) ], ); @EXPORT_OK = (); @@ -121,83 +121,160 @@ return @{$_srcpkg->{$src}}; } -=head2 binarytosource - -Returns a reference to the source package name and version pair -corresponding to a given binary package name, version, and architecture. - -If undef is passed as the architecture, returns a list of references -to all possible pairs of source package names and versions for all -architectures, with any duplicates removed. - -If the binary version is not passed either, returns a list of possible -source package names for all architectures at all versions, with any -duplicates removed. +=head2 binary_to_source + + binary_to_source(package => 'foo', + version => '1.2.3', + arch => 'i386'); + + +Turn a binary package (at optional version in optional architecture) +into a single (or set) of source packages (optionally) with associated +versions. + +By default, in LIST context, returns a LIST of array refs of source +package, source version pairs corresponding to the binary package(s), +arch(s), and verion(s) passed. + +In SCALAR context, only the corresponding source packages are +returned, concatenated with ', ' if necessary. + +=over + +=item binary -- binary package name(s) as a SCALAR or ARRAYREF + +=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 source_only -- return only the source name (forced on if in +SCALAR context), defaults to false. + +=item scalar_only -- return a scalar only (forced true if in SCALAR +context, also causes source_only to be true), defaults to false. + +=item cache -- optional HASHREF to be used to cache results of +binary_to_source. + +=back =cut our %_binarytosource; -sub binarytosource { - my ($binname, $binver, $binarch) = @_; +sub binary_to_source{ + my %param = validate_with(params => \...@_, + spec => {binary => {type => SCALAR|ARRAYREF, + }, + version => {type => SCALAR|ARRAYREF, + optional => 1, + }, + arch => {type => SCALAR|ARRAYREF, + optional => 1, + }, + source_only => {default => 0, + }, + scalar_only => {default => 0, + }, + cache => {type => HASHREF, + default => {}, + }, + }, + ); # TODO: This gets hit a lot, especially from buggyversion() - probably # need an extra cache for speed here. return () unless defined $gBinarySourceMap; - if ($binname =~ m/^src:(.+)$/) { - return $1; - } - if (not tied %_binarytosource) { - tie %_binarytosource, MLDBM => $gBinarySourceMap, O_RDONLY or - die "Unable to open $gBinarySourceMap for reading"; - } - - # avoid autovivification - my $binary = $_binarytosource{$binname}; - return () unless defined $binary; - my %binary = %{$binary}; - if (not defined $binver) { - my %uniq; - for my $ver (keys %binary) { - for my $ar (keys %{$binary{$ver}}) { - my $src = $binary{$ver}{$ar}; - next unless defined $src; - $uniq{$src->[0]} = 1; - } - } - return keys %uniq; - } - elsif (exists $binary{$binver}) { - if (defined $binarch and length $binarch) { - my $src = $binary{$binver}{$binarch}; - if (not defined $src and exists $binary{$binver}{all}) { - $src = $binary{$binver}{all}; - } - return () unless defined $src; # not on this arch - # Copy the data to avoid tiedness problems. - return dclone($src); - } else { - # Get (srcname, srcver) pairs for all architectures and - # remove any duplicates. This involves some slightly tricky - # multidimensional hashing; sorry. Fortunately there'll - # usually only be one pair returned. - my %uniq; - for my $ar (keys %{$binary{$binver}}) { - my $src = $binary{$binver}{$ar}; - next unless defined $src; - $uniq{$src->[0]}{$src->[1]} = 1; - } - my @uniq; - for my $sn (sort keys %uniq) { - push @uniq, [$sn, $_] for sort keys %{$uniq{$sn}}; - } - return @uniq; - } + if ($param{scalar_only} or not wantarray) { + $param{source_only} = 1; + $param{scalar_only} = 1; + } + + my @source; + my @packages = grep {defined $_} make_list(exists $param{package}?$param{package}:[]); + my @versions = grep {defined $_} make_list(exists $param{version}?$param{version}:[]); + my @archs = grep {defined $_} make_list(exists $param{arch}?$param{arch}:[]); + return () unless @packages; + my $cache_key = join("\1", + join("\0",@packages), + 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}}; + } + for my $package (make_list($param{package})) { + if ($package =~ m/^src:(.+)$/) { + push @source,[$1,'']; + next; + } + if (not tied %_binarytosource) { + tie %_binarytosource, MLDBM => $config{binary_source_map}, O_RDONLY or + die "Unable to open $config{binary_source_map} for reading"; + } + # avoid autovivification + my $binary = $_binarytosource{$package}; + if (not @versions) { + next unless defined $binary; + for my $ver (keys %{$binary}) { + for my $ar (keys %{$binary->{$ver}}) { + my $src = $binary->{$ver}{$ar}; + next unless defined $src; + push @source,[$src->[0],$src->[1]]; + } + } + } + else { + my $found_one_version = 0; + for my $version (@versions) { + next unless exists $binary->{$version}; + if (exists $binary->{$version}{all}) { + push @source,dclone($binary->{$version}{all}); + next; + } + my @t_archs; + if (@archs) { + @t_archs = @archs; + } + else { + @t_archs = keys %{$binary->{$version}}; + } + for my $arch (@t_archs) { + push @source,dclone($binary->{$version}{$arch}) if + exists $binary->{$version}{$arch}; + } + } + } + } + my @result; + + if ($param{source_only}) { + my %uniq; + for my $s (@source) { + $uniq{$s->[0]} = 1; + } + @result = sort keys %uniq; + if ($param{scalar_only}) { + @result = join(', ',@result); + } + } + else { + my %uniq; + for my $s (@source) { + $uniq{$s->[0]}{$s->[1]} = 1; + } + for my $sn (sort keys %uniq) { + push @result, [$sn, $_] for sort keys %{$uniq{$sn}}; + } } # No $gBinarySourceMap, or it didn't have an entry for this name and # version. - return (); + $param{cache}{$cache_key} = \...@result; + return $param{scalar_only} ? $result[0] : @result; } =head2 sourcetobinary @@ -504,7 +581,9 @@ } next; } - my @srcinfo = binarytosource($pkg, $version, $arch); + my @srcinfo = binary_to_source(binary => $pkg, + version => $version, + arch => $arch); if (not @srcinfo) { # We don't have explicit information about the # binary-to-source mapping for this version
=== modified file 'Debbugs/Recipients.pm' --- Debbugs/Recipients.pm 2009-08-28 23:23:07 +0000 +++ Debbugs/Recipients.pm 2009-09-10 20:58:39 +0000 @@ -46,7 +46,7 @@ use Debbugs::Common qw(:misc :util); use Debbugs::Status qw(splitpackages isstrongseverity); -use Debbugs::Packages qw(binarytosource); +use Debbugs::Packages qw(binary_to_source); use Debbugs::Mail qw(get_addresses); @@ -114,7 +114,9 @@ for my $p (splitpackages($param{data}{package})) { $p = lc($p); if (defined $config{subscription_domain}) { - my @source_packages = binarytosource($p); + my @source_packages = binary_to_source(binary => $p, + source_only => 1, + ); if (@source_packages) { for my $source (@source_packages) { _add_address(recipients => $param{recipients}, === modified file 'Debbugs/SOAP.pm' --- Debbugs/SOAP.pm 2008-06-19 00:06:42 +0000 +++ Debbugs/SOAP.pm 2009-09-10 20:58:39 +0000 @@ -47,7 +47,7 @@ use Scalar::Util qw(looks_like_number); -our $CURRENT_VERSION = 1; +our $CURRENT_VERSION = 2; =head2 get_usertag @@ -262,7 +262,12 @@ of references to all possible pairs of source package names and versions for all architectures, with any duplicates removed. -(This function corresponds to L<Debbugs::Packages::binarytosource>) +As of comaptibility version 2, this has changed to use the more +powerful binary_to_source routine, which allows returning source only, +concatenated scalars, and other useful features. + +See the documentation of L<Debbugs::Packages::binary_to_source> for +details. =cut @@ -270,7 +275,15 @@ my $VERSION = __populate_version(pop); my ($self,@params) = @_; - return [Debbugs::Packages::binarytosource(@params)]; + if ($VERSION <= 1) { + return [Debbugs::Packages::binary_to_source(binary => $params[0], + (@params > 1)?(version => $params[1]):(), + (@params > 2)?(arch => $params[2]):(), + )]; + } + else { + return [Debbugs::Packages::binary_to_source(@params)]; + } } =head2 source_to_binary === modified file 'Debbugs/Status.pm' --- Debbugs/Status.pm 2009-09-03 03:07:52 +0000 +++ Debbugs/Status.pm 2009-09-10 20:58:39 +0000 @@ -40,7 +40,7 @@ use Debbugs::Common qw(:util :lock :quit :misc); use Debbugs::Config qw(:config); use Debbugs::MIME qw(decode_rfc1522 encode_rfc1522); -use Debbugs::Packages qw(makesourceversions make_source_versions getversions get_versions binarytosource); +use Debbugs::Packages qw(makesourceversions make_source_versions getversions get_versions binary_to_source); use Debbugs::Versions; use Debbugs::Versions::Dpkg; use POSIX qw(ceil); @@ -232,7 +232,11 @@ for my $line (@lines) { if ($line =~ /(\S+?): (.*)/) { my ($name, $value) = (lc $1, $2); - $data{$namemap{$name}} = $value if exists $namemap{$name}; + # this is a bit of a hack; we should never, ever have \r + # or \n in the fields of status. Kill them off here. + # [Eventually, this should be superfluous.] + $value =~ s/[\r\n]//g; + $data{$namemap{$name}} = $value if exists $namemap{$name}; } } for my $field (keys %fields) { @@ -522,6 +526,13 @@ } } + # this is a bit of a hack; we should never, ever have \r or \n in + # the fields of status. Kill them off here. [Eventually, this + # should be superfluous.] + for my $field (keys %newdata) { + $newdata{$field} =~ s/[\r\n]//g if defined $newdata{$field}; + } + if ($version == 1) { for my $field (@v1fieldorder) { if (exists $newdata{$field} and defined $newdata{$field}) { @@ -623,7 +634,8 @@ my $source = $package; if (defined $package and $isbinary) { - my @srcinfo = binarytosource($package, $version, undef); + my @srcinfo = binary_to_source(binary => $package, + version => $version); if (@srcinfo) { # We know the source package(s). Use a fully-qualified version. addfoundversions($data, $_->[0], $_->[1], '') foreach @srcinfo; @@ -697,7 +709,8 @@ my $source = $package; if (defined $package and $isbinary) { - my @srcinfo = binarytosource($package, $version, undef); + my @srcinfo = binary_to_source(binary => $package, + version => $version); if (@srcinfo) { # We know the source package(s). Use a fully-qualified version. addfixedversions($data, $_->[0], $_->[1], '') foreach @srcinfo; @@ -1059,25 +1072,10 @@ $status{package} = '' if not defined $status{package}; $status{"package"} =~ s/\s*$//; - # if we aren't supposed to indicate the source, we'll return - # unknown here. - $status{source} = 'unknown'; - if ($param{indicatesource}) { - my @packages = split /\s*,\s*/, $status{package}; - my @source; - for my $package (@packages) { - next if $package eq ''; - if ($package =~ /^src\:(.+)$/) { - push @source,$1; - } - else { - push @source, binarytosource($package); - } - } - if (@source) { - $status{source} = join(', ',@source); - } - } + + $status{source} = binary_to_source(binary=>[split /\s*,\s*/, $status{package}], + source_only => 1, + ); $status{"package"} = 'unknown' if ($status{"package"} eq ''); $status{"severity"} = 'normal' if (not defined $status{severity} or $status{"severity"} eq ''); === modified file 'debian/changelog' --- debian/changelog 2009-08-28 23:24:06 +0000 +++ debian/changelog 2009-09-10 20:58:39 +0000 @@ -3,6 +3,7 @@ * Allow (almost) exactly what RFC2822 allows in comments (closes: #497144) * Fix problem with non-existant /etc/debbugs/config + * Ditch \r and \n in status fields (closes: #545895) -- Don Armstrong <d...@debian.org> Wed, 26 Aug 2009 21:32:53 -0700 === modified file 'examples/debian/postpa/22oldbugs' --- examples/debian/postpa/22oldbugs 2007-05-20 07:10:12 +0000 +++ examples/debian/postpa/22oldbugs 2009-09-10 20:58:39 +0000 @@ -45,7 +45,9 @@ return () if @merged and $merged[0] < $d{bug}; # 3600*24*30 (30 days) - my $cmonths = int(($startdate - $status->{date}) / 2592000); + my $cmonths = int(($startdate - + length($status->{date})?$status->{date}:0) / + 2592000); if ($cmonths >= 24 && !length($status->{forwarded}) && !$excludepackage{$d{pkg}}) { $oldpackage{$d{bug}} = $d{pkg}; === modified file 'scripts/process' --- scripts/process 2009-08-24 04:09:26 +0000 +++ scripts/process 2009-09-10 20:58:39 +0000 @@ -14,7 +14,7 @@ use MIME::Parser; use Debbugs::MIME qw(decode_rfc1522 create_mime_message getmailbody); use Debbugs::Mail qw(send_mail_message encode_headers get_addresses); -use Debbugs::Packages qw(getpkgsrc binarytosource); +use Debbugs::Packages qw(getpkgsrc binary_to_source); use Debbugs::User qw(read_usertags write_usertags); use Debbugs::Common qw(:lock get_hashname package_maintainer); use Debbugs::Status qw(writebug isstrongseverity lockreadbugmerge lockreadbug read_bug splitpackages :versions); @@ -1078,7 +1078,9 @@ $p = $1; next unless defined $p; if (defined $gSubscriptionDomain) { - my @source = binarytosource($p); + my @source = binary_to_source(binary => $p, + source_only => 1, + ); if (@source) { push @addsrcaddrs, map {"$...@$gsubscriptiondomain"} @source;