more surgery:

- don't ask the database about existing pathkeys, it's simpler to have
our hash.
- in dependencies, don't like for non normalized pathkeys
- add CANONICAL column, and fill it.
This commit is contained in:
espie 2012-05-20 11:06:07 +00:00
parent 77b9840f10
commit e79b763a4e
7 changed files with 80 additions and 43 deletions

View File

@ -1,7 +1,7 @@
# $OpenBSD: Makefile,v 1.40 2012/05/18 12:11:28 espie Exp $
# $OpenBSD: Makefile,v 1.41 2012/05/20 11:06:07 espie Exp $
CATEGORIES = databases
V = 2.0
V = 2.1
DISTNAME = sqlports-$V
DISTFILES =
COMMENT = sqlite database of ports

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: Inserter.pm,v 1.10 2012/05/18 12:11:28 espie Exp $
# $OpenBSD: Inserter.pm,v 1.11 2012/05/20 11:06:07 espie Exp $
#
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
#
@ -104,7 +104,7 @@ sub create_tables
$self->create_ports_table;
$self->prepare_normal_inserter('Ports', @{$self->{varlist}});
$self->prepare_normal_inserter('Paths', 'PKGPATH');
$self->prepare_normal_inserter('Paths', 'PKGPATH', 'CANONICAL');
$self->create_view_info;
$self->commit_to_db;
print '-'x50, "\n" if $self->{verbose};
@ -172,9 +172,9 @@ sub new_table
return if defined $self->{tables_created}->{$name};
$self->db->do("DROP TABLE IF EXISTS $name");
print "CREATE TABLE $name (".join(', ', @cols).")\n"
if $self->{verbose};
$self->db->do("CREATE TABLE $name (".join(', ', @cols).")");
my $request = "CREATE TABLE $name (".join(', ', @cols).")";
print "$request\n" if $self->{verbose};
$self->db->do($request);
$self->{tables_created}->{$name} = 1;
}
@ -331,7 +331,8 @@ sub create_path_table
my $self = shift;
$self->new_table("Paths", "ID INTEGER PRIMARY KEY",
"FULLPKGPATH TEXT NOT NULL UNIQUE",
"PKGPATH INTEGER REFERENCES Paths(ID)");
"PKGPATH INTEGER REFERENCES Paths(ID)", "CANONICAL INTEGER REFERENCES Paths(ID)");
$self->{adjust} = $self->db->prepare("UPDATE Paths set canonical=? where id=?");
}
sub handle_column
@ -347,10 +348,10 @@ sub create_view_info
my $self = shift;
my @columns = sort {$a->name cmp $b->name} @{$self->{columnlist}};
$self->create_view("Ports", @columns);
$self->{find_pathkey} =
$self->prepare("SELECT ID From Paths WHERE FULLPKGPATH=?");
}
my $path_cache = {};
my $newid = 1;
sub find_pathkey
{
my ($self, $key) = @_;
@ -359,24 +360,29 @@ sub find_pathkey
print STDERR "Empty pathkey\n";
return 0;
}
# get pathkey for existing value
$self->{find_pathkey}->execute($key);
my $z = $self->{find_pathkey}->fetchrow_arrayref;
if (!defined $z) {
# if none, we create one
my $path = $key;
$path =~ s/\,.*//;
if ($path ne $key) {
$path = $self->find_pathkey($path);
} else {
$path = undef;
}
$self->insert('Paths', $key, $path);
return $self->last_id;
} else {
return $z->[0];
if (defined $path_cache->{$key}) {
return $path_cache->{$key};
}
# if none, we create one
my $path = $key;
$path =~ s/\,.*//;
if ($path ne $key) {
$path = $self->find_pathkey($path);
} else {
$path = $newid;
}
$self->insert('Paths', $key, $path, $newid);
my $r = $self->last_id;
$path_cache->{$key} = $r;
$newid++;
return $r;
}
sub add_path
{
my ($self, $key, $alias) = @_;
$self->{adjust}->execute($path_cache->{$alias}, $path_cache->{$key});
}
sub set_newkey
@ -449,7 +455,7 @@ sub create_path_table
{
my $self = shift;
$self->new_table("Paths", "FULLPKGPATH TEXT NOT NULL PRIMARY KEY",
"PKGPATH TEXT NOT NULL");
"PKGPATH TEXT NOT NULL", "CANONICAL TEXT NOT NULL");
}
sub pathref
@ -489,10 +495,18 @@ sub set_newkey
my $path = $key;
$path =~ s/\,.*//;
$self->insert('Paths', $key, $path);
$self->insert('Paths', $key, $path, $key);
$self->set($key);
}
sub add_path
{
my ($self, $key, $alias) = @_;
my $path = $key;
$path =~ s/\,.*//;
$self->insert('Paths', $key, $path, $alias);
}
sub find_pathkey
{
my ($self, $key) = @_;

View File

@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
# $OpenBSD: PkgPath.pm,v 1.1 2012/05/18 12:11:28 espie Exp $
# $OpenBSD: PkgPath.pm,v 1.2 2012/05/20 11:06:07 espie Exp $
#
# Copyright (c) 2012 Marc Espie <espie@openbsd.org>
#
@ -60,7 +60,6 @@ sub equates
sub simplifies_to
{
my ($self, $other, $inserter) = @_;
}
1;

View File

@ -1,4 +1,4 @@
# $OpenBSD: Var.pm,v 1.13 2012/05/18 12:11:28 espie Exp $
# $OpenBSD: Var.pm,v 1.14 2012/05/20 11:06:07 espie Exp $
#
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
#
@ -270,7 +270,7 @@ sub add
my $p = PkgPath->new($pkgpath2);
$p->{want} = 1;
$self->normal_insert($ins, $depends,
$ins->find_pathkey($pkgpath2),
$ins->find_pathkey($p->fullpkgpath),
$ins->convert_depends($self->depends_type),
$pkgspec, $rest);
# XXX $ins->add_todo($pkgpath2);

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: mksqlitedb,v 1.38 2012/05/18 12:11:28 espie Exp $
# $OpenBSD: mksqlitedb,v 1.39 2012/05/20 11:06:07 espie Exp $
#
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
#
@ -61,6 +61,8 @@ sub parse_dump
}
$pkgpath->{info}->reclaim;
$pkgpath->{info}{done} = 1;
$pkgpath->{info}{canonical} = $pkgpath;
$pkgpath->{done} = 1;
$inserter->finish_port;
}
$h = {};
@ -152,7 +154,12 @@ while (1) {
for my $v (PkgPath->seen) {
if (defined $v->{info}) {
delete $v->{tried};
delete $v->{want};
if (defined $v->{want}) {
delete $v->{want};
if (!defined $v->{done}) {
$v->{needalias} = 1;
}
}
next;
}
if (defined $v->{tried}) {
@ -167,6 +174,20 @@ while (1) {
dump_dirs($inserter, $subdirlist);
}
print "Aliases\n";
for my $v (PkgPath->seen) {
next unless defined $v->{needalias};
my $alias = $v->{info}{canonical};
if (defined $alias) {
print $v->fullpkgpath, "->", $alias->fullpkgpath, "\n";
$inserter->add_path($v->fullpkgpath, $alias->fullpkgpath);
} else {
print "!!! Can't figure out alias for ", $v->fullpkgpath, "\n";
}
}
$inserter->commit_to_db;
while (my ($k, $v) = each %$Info::unknown) {
next if $k eq 'CHECKSUM_FILE';
print STDERR "Unknown variable $k in ", $v->fullpkgpath, "\n";

View File

@ -5,14 +5,16 @@ This schema is mostly optimized for tools, and cumbersome to query by
hand.
Database Schema:
- Paths (ID, FULLPKGPATH, PKGPATH)
- Paths (ID, FULLPKGPATH, PKGPATH, CANONICAL)
PKGPATH points to a PATHS entry corresponding to the stripped down version of
FULLPKGPATH, without flavors or subpackage markers, or is null if FULLPKGPATH
is already stripped. Every other FULLPKGPATH, PKGPATH, DEPENDSPATH entry
in the database points to this table.
The FULLPKGPATH is complete, including flavors markers (but not pseudo
flavors, tack on PSEUDO_FLAVOR for that). For every port with MULTI_PACKAGES
settings, one entry is written for each SUBPACKAGE.
The FULLPKGPATH is complete, including flavors and pseudo flavors markers.
For every port with MULTI_PACKAGES settings, one entry is written
for each SUBPACKAGE.
CANONICAL points to the actual ID to use as an entry in other tables, for
FULLPKGPATH which don't have their own entry.
- Ports(FULLPKGPATH, ...)
holds all the information retrieved through various variables that is not

View File

@ -50,13 +50,14 @@ with 1/0. Variables not present in a given port are left undefined.
Note that USE_LIBTOOL is 3-valued: 2 is gnu, 1 is yes, undef is no.
The FULLPKGPATH is complete, including flavors markers (but not pseudo
flavors, tack on PSEUDO_FLAVOR for that). For every port with MULTI_PACKAGES
settings, one entry is written for each SUBPACKAGE.
The FULLPKGPATH is complete, including flavor and pseudo-flavors markers.
For every port with MULTI_PACKAGES settings, one entry is written for
each SUBPACKAGE.
- Paths (FULLPKGPATH, PKGPATH)
- Paths (FULLPKGPATH, PKGPATH, CANONICAL)
PKGPATH is the stripped down version or FULLPKGPATH, without flavors
or subpackage markers.
CANONICAL points to the reduced version.
- Flavors(FULLPKGPATH, VALUE)
- Categories(FULLPKGPATH, VALUE)