summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <mls@suse.de>2013-05-17 16:32:44 +0200
committerMichael Schroeder <mls@suse.de>2013-05-17 16:32:44 +0200
commit0424ef2001157e0bf0385da84828a6075c8d291c (patch)
tree975f8bd1d859e61803f72e485d4713ae4b9b5148
parent64ff7df719bcabc86c2c81089745dc4aadbe43b6 (diff)
downloadlibsolv-0424ef2001157e0bf0385da84828a6075c8d291c.tar.gz
libsolv-0424ef2001157e0bf0385da84828a6075c8d291c.tar.bz2
libsolv-0424ef2001157e0bf0385da84828a6075c8d291c.zip
allow SOLVID_META queries through SOLVID_POS
Add 'meta' attribute in repo bindings and get rid of no longer neededed lookup methods.
-rw-r--r--bindings/solv.i40
-rwxr-xr-xexamples/p5solv10
-rwxr-xr-xexamples/pysolv10
-rwxr-xr-xexamples/rbsolv10
-rw-r--r--src/pool.c24
-rw-r--r--src/repo.c21
6 files changed, 73 insertions, 42 deletions
diff --git a/bindings/solv.i b/bindings/solv.i
index 58ed038..8bbbd4a 100644
--- a/bindings/solv.i
+++ b/bindings/solv.i
@@ -1235,6 +1235,7 @@ typedef struct {
return 0;
return pool_id2repo($self, id);
}
+
%newobject repos;
Pool_repo_iterator * const repos;
%{
@@ -1498,15 +1499,6 @@ rb_eval_string(
void internalize() {
repo_internalize($self);
}
- const char *lookup_str(Id entry, Id keyname) {
- return repo_lookup_str($self, entry, keyname);
- }
- Id lookup_id(Id entry, Id keyname) {
- return repo_lookup_id($self, entry, keyname);
- }
- unsigned long long lookup_num(Id entry, Id keyname, unsigned long long notfound = 0) {
- return repo_lookup_num($self, entry, keyname, notfound);
- }
bool write(FILE *fp) {
return repo_write($self, fp) == 0;
}
@@ -1531,12 +1523,24 @@ rb_eval_string(
return repo->repoid;
}
%}
+ %newobject solvables;
Repo_solvable_iterator * const solvables;
%{
SWIGINTERN Repo_solvable_iterator * Repo_solvables_get(Repo *repo) {
return new_Repo_solvable_iterator(repo);
}
%}
+ %newobject meta;
+ Datapos * const meta;
+ %{
+ SWIGINTERN Datapos * Repo_meta_get(Repo *repo) {
+ Datapos *pos = solv_calloc(1, sizeof(*pos));
+ pos->solvid = SOLVID_META;
+ pos->repo = repo;
+ return pos;
+ }
+ %}
+
%newobject solvables_iter;
Repo_solvable_iterator *solvables_iter() {
return new_Repo_solvable_iterator($self);
@@ -1709,6 +1713,24 @@ rb_eval_string(
pool->pos = oldpos;
return r;
}
+ unsigned long long lookup_num(Id keyname, unsigned long long notfound = 0) {
+ Pool *pool = $self->repo->pool;
+ Datapos oldpos = pool->pos;
+ unsigned long long r;
+ pool->pos = *$self;
+ r = pool_lookup_num(pool, SOLVID_POS, keyname, notfound);
+ pool->pos = oldpos;
+ return r;
+ }
+ bool lookup_void(Id keyname) {
+ Pool *pool = $self->repo->pool;
+ Datapos oldpos = pool->pos;
+ int r;
+ pool->pos = *$self;
+ r = pool_lookup_void(pool, SOLVID_POS, keyname);
+ pool->pos = oldpos;
+ return r;
+ }
%newobject lookup_checksum;
Chksum *lookup_checksum(Id keyname) {
Pool *pool = $self->repo->pool;
diff --git a/examples/p5solv b/examples/p5solv
index 77b26c7..5c25954 100755
--- a/examples/p5solv
+++ b/examples/p5solv
@@ -387,8 +387,8 @@ sub load_ext {
return 1;
}
print "fetching]\n";
- my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
- my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
+ my $defvendorid = $self->{'handle'}->{'meta'}->lookup_id($solv::SUSETAGS_DEFAULTVENDOR);
+ my $descrdir = $self->{'handle'}->{'meta'}->lookup_str($solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
my $filechksum = $repodata->lookup_checksum($solv::SOLVID_META, $solv::SUSETAGS_FILE_CHECKSUM);
my $f = $self->download("$descrdir/$filename", 1, $filechksum);
return 0 unless $f;
@@ -418,8 +418,8 @@ sub load {
}
$self->{'handle'}->add_content($f, 0);
print "fetching\n";
- my $defvendorid = $self->{'handle'}->lookup_id($solv::SOLVID_META, $solv::SUSETAGS_DEFAULTVENDOR);
- my $descrdir = $self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
+ my $defvendorid = $self->{'handle'}->{'meta'}->lookup_id($solv::SUSETAGS_DEFAULTVENDOR);
+ my $descrdir = $self->{'handle'}->{'meta'}->lookup_str($solv::SUSETAGS_DESCRDIR) || 'suse/setup/descr';
my ($filename, $filechksum) = $self->find('packages.gz');
($filename, $filechksum) = $self->find('packages') unless $filename;
if ($filename) {
@@ -445,7 +445,7 @@ sub load {
sub packagespath {
my ($self) = @_;
- return ($self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') . '/';
+ return ($self->{'handle'}->{'meta'}->lookup_str($solv::SUSETAGS_DATADIR) || 'suse') . '/';
}
package Repo::unknown;
diff --git a/examples/pysolv b/examples/pysolv
index 2293ff5..f300d08 100755
--- a/examples/pysolv
+++ b/examples/pysolv
@@ -418,8 +418,8 @@ class repo_susetags(repo_generic):
return True
self.handle.add_content(f, 0)
print "fetching"
- defvendorid = self.handle.lookup_id(solv.SOLVID_META, solv.SUSETAGS_DEFAULTVENDOR)
- descrdir = self.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DESCRDIR)
+ defvendorid = self.handle.meta.lookup_id(solv.SUSETAGS_DEFAULTVENDOR)
+ descrdir = self.handle.meta.lookup_str(solv.SUSETAGS_DESCRDIR)
if not descrdir:
descrdir = "suse/setup/descr"
(filename, filechksum) = self.find('packages.gz')
@@ -510,8 +510,8 @@ class repo_susetags(repo_generic):
return True
sys.stdout.write("fetching]\n")
sys.stdout.flush()
- defvendorid = self.handle.lookup_id(solv.SOLVID_META, solv.SUSETAGS_DEFAULTVENDOR)
- descrdir = self.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DESCRDIR)
+ defvendorid = self.handle.meta.lookup_id(solv.SUSETAGS_DEFAULTVENDOR)
+ descrdir = self.handle.meta.lookup_str(solv.SUSETAGS_DESCRDIR)
if not descrdir:
descrdir = "suse/setup/descr"
filechksum = repodata.lookup_checksum(solv.SOLVID_META, solv.SUSETAGS_FILE_CHECKSUM)
@@ -526,7 +526,7 @@ class repo_susetags(repo_generic):
return True
def packagespath(self):
- datadir = repo.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DATADIR)
+ datadir = repo.handle.meta.lookup_str(solv.SUSETAGS_DATADIR)
if not datadir:
datadir = 'suse'
return datadir + '/'
diff --git a/examples/rbsolv b/examples/rbsolv
index ad57e4d..e011010 100755
--- a/examples/rbsolv
+++ b/examples/rbsolv
@@ -366,8 +366,8 @@ class Repo_susetags < Repo_generic
@handle.add_content(f, 0)
f.close
puts "fetching"
- defvendorid = @handle.lookup_id(Solv::SOLVID_META, Solv::SUSETAGS_DEFAULTVENDOR)
- descrdir = @handle.lookup_str(Solv::SOLVID_META, Solv::SUSETAGS_DESCRDIR)
+ defvendorid = @handle.meta.lookup_id(Solv::SUSETAGS_DEFAULTVENDOR)
+ descrdir = @handle.meta.lookup_str(Solv::SUSETAGS_DESCRDIR)
descrdir = "suse/setup/descr" unless descrdir
(filename, filechksum) = find('packages.gz')
(filename, filechksum) = find('packages') unless filename
@@ -449,8 +449,8 @@ class Repo_susetags < Repo_generic
return true
end
puts "fetching]\n"
- defvendorid = @handle.lookup_id(Solv::SOLVID_META, Solv::SUSETAGS_DEFAULTVENDOR)
- descrdir = @handle.lookup_str(Solv::SOLVID_META, Solv::SUSETAGS_DESCRDIR)
+ defvendorid = @handle.meta.lookup_id(Solv::SUSETAGS_DEFAULTVENDOR)
+ descrdir = @handle.meta.lookup_str(Solv::SUSETAGS_DESCRDIR)
descrdir = "suse/setup/descr" unless descrdir
filechksum = repodata.lookup_checksum(Solv::SOLVID_META, Solv::SUSETAGS_FILE_CHECKSUM)
f = download("#{descrdir}/#{filename}", true, filechksum)
@@ -464,7 +464,7 @@ class Repo_susetags < Repo_generic
end
def packagespath()
- datadir = @handle.lookup_str(Solv::SOLVID_META, Solv::SUSETAGS_DATADIR)
+ datadir = @handle.meta.lookup_str(Solv::SUSETAGS_DATADIR)
datadir = "suse" unless datadir
return datadir + '/'
end
diff --git a/src/pool.c b/src/pool.c
index 5244f2a..5d3e61a 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -2081,7 +2081,7 @@ const char *
pool_lookup_str(Pool *pool, Id entry, Id keyname)
{
if (entry == SOLVID_POS && pool->pos.repo)
- return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
+ return repo_lookup_str(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
if (entry <= 0)
return 0;
return solvable_lookup_str(pool->solvables + entry, keyname);
@@ -2091,11 +2091,7 @@ Id
pool_lookup_id(Pool *pool, Id entry, Id keyname)
{
if (entry == SOLVID_POS && pool->pos.repo)
- {
- Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
- Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
- return data->localpool ? repodata_globalize_id(data, id, 1) : id;
- }
+ return repo_lookup_id(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
if (entry <= 0)
return 0;
return solvable_lookup_id(pool->solvables + entry, keyname);
@@ -2105,12 +2101,7 @@ unsigned long long
pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound)
{
if (entry == SOLVID_POS && pool->pos.repo)
- {
- unsigned long long value;
- if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
- return value;
- return notfound;
- }
+ return repo_lookup_num(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, notfound);
if (entry <= 0)
return notfound;
return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
@@ -2120,7 +2111,7 @@ int
pool_lookup_void(Pool *pool, Id entry, Id keyname)
{
if (entry == SOLVID_POS && pool->pos.repo)
- return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
+ return repo_lookup_void(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname);
if (entry <= 0)
return 0;
return solvable_lookup_void(pool->solvables + entry, keyname);
@@ -2130,7 +2121,7 @@ const unsigned char *
pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
{
if (entry == SOLVID_POS && pool->pos.repo)
- return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
+ return repo_lookup_bin_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
if (entry <= 0)
return 0;
return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
@@ -2140,10 +2131,7 @@ const char *
pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
{
if (entry == SOLVID_POS && pool->pos.repo)
- {
- const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
- return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
- }
+ return repo_lookup_checksum(pool->pos.repo, pool->pos.repodataid ? entry : pool->pos.solvid, keyname, typep);
if (entry <= 0)
return 0;
return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
diff --git a/src/repo.c b/src/repo.c
index 9ea328f..abb2b3b 100644
--- a/src/repo.c
+++ b/src/repo.c
@@ -1140,6 +1140,8 @@ repo_lookup_str(Repo *repo, Id entry, Id keyname)
return pool_id2str(pool, pool->solvables[entry].vendor);
}
}
+ else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
+ return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
FOR_REPODATAS(repo, i, data)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
@@ -1159,6 +1161,7 @@ repo_lookup_str(Repo *repo, Id entry, Id keyname)
unsigned long long
repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound)
{
+ Pool *pool = repo->pool;
Repodata *data;
int i;
unsigned long long value;
@@ -1172,6 +1175,8 @@ repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound)
return notfound;
}
}
+ else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
+ return repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, &value) ? value : notfound;
FOR_REPODATAS(repo, i, data)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
@@ -1189,6 +1194,7 @@ repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound)
Id
repo_lookup_id(Repo *repo, Id entry, Id keyname)
{
+ Pool *pool = repo->pool;
Repodata *data;
int i;
Id id;
@@ -1207,6 +1213,12 @@ repo_lookup_id(Repo *repo, Id entry, Id keyname)
return repo->pool->solvables[entry].vendor;
}
}
+ else if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
+ {
+ Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
+ Id id = repodata_lookup_id(data, entry, keyname);
+ return data->localpool ? repodata_globalize_id(data, id, 1) : id;
+ }
FOR_REPODATAS(repo, i, data)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
@@ -1317,10 +1329,13 @@ repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker)
const unsigned char *
repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
{
+ Pool *pool = repo->pool;
Repodata *data;
int i;
const unsigned char *chk;
+ if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
+ return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname, typep);
FOR_REPODATAS(repo, i, data)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
@@ -1347,10 +1362,13 @@ repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep)
int
repo_lookup_void(Repo *repo, Id entry, Id keyname)
{
+ Pool *pool = repo->pool;
Repodata *data;
int i;
Id type;
+ if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
+ return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
FOR_REPODATAS(repo, i, data)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))
@@ -1367,10 +1385,13 @@ repo_lookup_void(Repo *repo, Id entry, Id keyname)
Id
repo_lookup_type(Repo *repo, Id entry, Id keyname)
{
+ Pool *pool = repo->pool;
Repodata *data;
int i;
Id type;
+ if (entry == SOLVID_POS && pool->pos.repo == repo && pool->pos.repodataid)
+ return repodata_lookup_type(pool->pos.repo->repodata + pool->pos.repodataid, entry, keyname);
FOR_REPODATAS(repo, i, data)
{
if (entry != SOLVID_META && (entry < data->start || entry >= data->end))