From 49f6fa5b401d8bba7abc2bafde675841a8729a15 Mon Sep 17 00:00:00 2001 From: Jeroen van Wolffelaar Date: Thu, 23 Feb 2006 02:28:15 +0000 Subject: [PATCH] Change _small.db layout a bit, to include virtual packages consisely at the top, and the newest of the concrete packages as the first item, significantly simplifying read_entry_small --- BACKEND | 14 +++++----- bin/parse-packages | 47 +++++++++++++++++++++++++--------- lib/Packages/DoSearch.pm | 6 ++--- lib/Packages/HTML.pm | 16 +++++------- lib/Packages/Search.pm | 55 +++++++++++++++++++--------------------- 5 files changed, 77 insertions(+), 61 deletions(-) diff --git a/BACKEND b/BACKEND index f3a5753..445a45d 100644 --- a/BACKEND +++ b/BACKEND @@ -20,14 +20,14 @@ Generated by means of Packages.gz files: | value: \0 separated tuples of "archive suite arch component section priority version shortdescription" | (so you can split on spaces in 8 pieces, but need to not split further | because shortdescription can have spaces) -| arch can also be 'virtual', with c/s/p/v being undefined then, and -| shortdescription being a space-separated list of packages providing -| the package that is the key Notes: - maybe add did right before shortdescription? - - TODO: make sure for each (archive,suite), newest package is shown - first, and all newest versions for each such section is first, so - that one can efficiently lookup just the newest entry for a given - (archive,suite) + - for each suite, newest package is shown first, and (suite, + architecture) is unique, the newest one is choosen. Once you find + the right suite, you know you've got the newest, once you found + your (suite,arch), you know you've found the only unique such entry + - The very first element is different (TODO: maybe should be + different DB then?), a \01 separated hash of suite -> provided-by, + like "suite1\01prov1 prov2\01suite2\01prov1" | package_postfixes.db: | key: a postfix string of a package name diff --git a/bin/parse-packages b/bin/parse-packages index 399a62c..b3aab25 100755 --- a/bin/parse-packages +++ b/bin/parse-packages @@ -30,9 +30,11 @@ my $MAX_PACKAGE_POSTFIXES = 100; use DB_File; use Storable; +use Deb::Versions; use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES ); &Packages::Config::init( './' ); my %packages_small = (); +my %virtual_packages = (); my %package_names = (); my %package_postfixes = (); my %sources_packages = (); @@ -50,7 +52,6 @@ $/ = ""; for my $archive (@ARCHIVES) { for my $suite (@SUITES) { - my %virtual_packages = (); print "Reading $archive/$suite...\n"; my %packages_all_db; tie %packages_all_db, "DB_File", "$DBDIR/packages_all_$suite.db.new", @@ -74,7 +75,7 @@ for my $archive (@ARCHIVES) { if ($data{'provides'}) { foreach (split /\s*,\s*/, $data{'provides'}) { - $virtual_packages{$_}{$data{'package'}}++; + $virtual_packages{$_}{$suite}{$data{'package'}}++; } } $package_names{$data{'package'}} = 1; @@ -114,8 +115,16 @@ for my $archive (@ARCHIVES) { $sections{$suite}{$archive}{$section}++; $subsections{$suite}{$archive}{$subsection}++; $priorities{$suite}{$archive}{$data{priority}}++; - $packages_small{$data{'package'}} .= "$archive $suite $data{'architecture'} ". - "$section $subsection $data{'priority'} $data{'version'} $sdescr\000"; + my $pkgitem = "$archive $suite $data{'architecture'} ". + "$section $subsection $data{'priority'} $data{'version'} $sdescr\0"; + my $previtem = $packages_small{$data{'package'}}{$suite}{$data{'architecture'}} + || $pkgitem; + $packages_small{$data{'package'}}{$suite}{$data{'architecture'}} = $pkgitem + if version_cmp($data{'version'}, (split /\s/o, $previtem)[6]) >= 0; + $previtem = $packages_small{$data{'package'}}{$suite}{'any'} + || $pkgitem; + $packages_small{$data{'package'}}{$suite}{'any'} = $pkgitem + if version_cmp($data{'version'}, (split /\s/o, $previtem)[6]) >= 0; $sources_packages{$src} .= "$archive $suite $data{'package'} $data{'version'} $data{'architecture'}\000"; $data{archive} = $archive; @@ -130,11 +139,6 @@ for my $archive (@ARCHIVES) { = $data; } - foreach (keys %virtual_packages) { - my @provided_by = keys %{$virtual_packages{$_}}; - $packages_small{$_} .= "$archive $suite virtual v v v v @provided_by\000"; - } - untie %packages_all_db; } } @@ -144,9 +148,28 @@ my %packages_small_db; tie %packages_small_db, "DB_File", "$DBDIR/packages_small.db.new", O_RDWR|O_CREAT, 0666, $DB_BTREE or die "Error creating DB: $!"; -while (my ($k, $v) = each(%packages_small)) { - $v =~ s/.$//s; - $packages_small_db{$k} = $v; +while (my ($pkg, $v) = each(%packages_small)) { + my ($res1, $res2, $res3) = ("", "", ""); + while (my ($suite, $v2) = each %$v) { + $res2 .= $v2->{'any'}; + while (my ($arch, $v3) = each %$v2) { + next if $arch eq 'any' or $v3 eq $v2->{'any'}; + $res3 .= $v3; + } + } + + if (exists $virtual_packages{$pkg}) { + while (my ($suite, $v2) = each %{$virtual_packages{$pkg}}) { + $res1 .= "$suite\01".(join ' ', keys %$v2)."\01"; + } + } else { + $res1 .= "-\01-\01"; + } + $res1 =~ s/.$/\0/s; + + my $res = "$res1$res2$res3"; + $res =~ s/.$//s; + $packages_small_db{$pkg} = $res; } untie %packages_small_db; diff --git a/lib/Packages/DoSearch.pm b/lib/Packages/DoSearch.pm index c1c5446..275cb9b 100644 --- a/lib/Packages/DoSearch.pm +++ b/lib/Packages/DoSearch.pm @@ -183,7 +183,7 @@ sub do_search { $desc{$pkg}{$suite}{$archive}{$version} = $desc; } else { - $provided_by{$pkg}{$suite}{$archive} = [ split /\s+/, $desc ]; + $provided_by{$pkg}{$suite} = [ split /\s+/, $desc ]; } } @@ -297,12 +297,12 @@ sub print_package { if @archs_to_print; $archs_printed{$_}++ foreach @archs_to_print; } - if (my $p = $provided_by->{$suite}{$archive}) { + if (my $p = $provided_by->{$suite}) { $str .= '
'._g( 'also provided by: ' ). join( ', ', map { "$_" } @$p); } $str .= "\n"; - } elsif (my $p = $provided_by->{$suite}{$archive}) { + } elsif (my $p = $provided_by->{$suite}) { $str .= sprintf( "
  • %s: Virtual package
    ", $path, $pkg, $path ); $str .= _g( 'provided by: ' ). diff --git a/lib/Packages/HTML.pm b/lib/Packages/HTML.pm index 28dbb76..fc37c94 100644 --- a/lib/Packages/HTML.pm +++ b/lib/Packages/HTML.pm @@ -286,16 +286,17 @@ sub print_deps { my $entry = $entries{$p_name} || read_entry_simple( $packages, $p_name, $opts->{h_archives}, $suite); my $short_desc = $entry->[-1]; - my $arch = $entry->[2]; - my $archive = $entry->[0]; + my $arch = $entry->[3]; + my $archive = $entry->[1]; if ( $short_desc ) { my $path = $one_archive eq $archive ? "$suite/$archive" : $suite; if ( $is_old_pkgs ) { push @res_pkgs, dep_item( "$ROOT/$path/$p_name", $p_name, "$pkg_version$arch_str" ); - } elsif ($arch eq 'virtual') { - my @provided_by = split /\s/, $short_desc; + } elsif (defined $entry->[0]) { +# FIXME: can be both virtual package (defined $entry->[0]) and real one + my @provided_by = split /\s/, $entry->[0]; $short_desc = "virtual package provided by "; if (@provided_by < 10) { $short_desc .= join( ', ',map { "$_" } @provided_by); @@ -382,12 +383,7 @@ sub header { $search_in_header = <
    - - - - - - + %s
    diff --git a/lib/Packages/Search.pm b/lib/Packages/Search.pm index d04f44a..0211ec2 100644 --- a/lib/Packages/Search.pm +++ b/lib/Packages/Search.pm @@ -340,14 +340,26 @@ sub printindexline { sub read_entry_all { my ($hash, $key, $results, $non_results, $opts) = @_; - my $result = $hash->{$key} || ''; + my ($virt, $result) = split /\000/o, $hash->{$key} || "-\01-", 2; + + my %virt = split /\01/o, $virt; + while (my ($suite, $provides) = each %virt) { + next if $suite eq '-'; + if ($opts->{h_suites}{$suite}) { + push @$results, [ $key, "-", $suite, 'virtual', 'v', 'v', 'v', 'v', + (split /\s/, $provides)]; + } else { + push @$non_results, [ $key, "-", $suite, 'virtual', 'v', 'v', 'v', 'v', + (split /\s/, $provides)]; + } + } + foreach (split /\000/o, $result) { my @data = split ( /\s/o, $_, 8 ); debug( "Considering entry ".join( ':', @data), 2) if DEBUG; - if ($opts->{h_archives}{$data[0]} && $opts->{h_suites}{$data[1]} - && ($opts->{h_archs}{$data[2]} || $data[2] eq 'all' - || $data[2] eq 'virtual') - && ($opts->{h_sections}{$data[3]} || $data[3] eq 'v')) { + if ($opts->{h_suites}{$data[1]} + && ($opts->{h_archs}{$data[2]} || $data[2] eq 'all') + && $opts->{h_sections}{$data[3]}) { debug( "Using entry ".join( ':', @data), 2) if DEBUG; push @$results, [ $key, @data ]; } else { @@ -362,35 +374,20 @@ sub read_entry { } sub read_entry_simple { my ($hash, $key, $archives, $suite) = @_; - my $result = $hash->{$key} || ''; + # FIXME: drop $archives + + my ($virt, $result) = split /\000/o, $hash->{$key} || "-\01-\0", 2; + my %virt = split /\01/o, $virt; debug( "read_entry_simple: key=$key, archives=". join(" ",(keys %$archives)).", suite=$suite", 1); - my (@data_fuzzy, @data_virtual, @data_fuzzy_virtual); - foreach (split /\000/o, $result) { + # FIXME: magically encoded a max of 7 suites here by the '8' + foreach (split /\000/o, $result, 8) { my @data = split ( /\s/o, $_, 8 ); - debug( "Considering entry ".join( ':', @data), 2) if DEBUG; - if ($data[1] eq $suite) { - if ($archives->{$data[0]} - && ($data[2] ne 'virtual')) { - debug( "Using entry ".join( ':', @data), 2) if DEBUG; - return \@data; - } elsif ($archives->{$data[0]}) { - debug( "Virtual entry ".join( ':', @data), 2) if DEBUG; - @data_virtual = @data; - } elsif (($data[0] eq 'us') - && ($data[2] ne 'virtual')) { - debug( "Fuzzy entry ".join( ':', @data), 2) if DEBUG; - @data_fuzzy = @data; - } elsif ($data[0] eq 'us') { - debug( "Virtual fuzzy entry ".join( ':', @data), 2) if DEBUG; - @data_fuzzy_virtual = @data; - } - } + return [ $virt{$suite}, @data ] if $data[1] eq $suite; } - return \@data_virtual if @data_virtual; - return \@data_fuzzy if @data_fuzzy; - return \@data_fuzzy_virtual; + return [ $virt{$suite} ]; } + sub read_src_entry_all { my ($hash, $key, $results, $non_results, $opts) = @_; my $result = $hash->{$key} || ''; -- 2.39.2