From eb15c1e5a6b64178abbbb5a6b58c8b65c9f27358 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Wed, 4 Sep 2013 11:45:26 +0200 Subject: [PATCH] add solv_depmarker function to simplify the bindings --- bindings/solv.i | 30 ++---------------------------- src/libsolv.ver | 1 + src/repo.c | 25 +++++++++++++++++++++++-- src/repo.h | 1 + 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/bindings/solv.i b/bindings/solv.i index 23dfdf1..7c0db0a 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -2151,14 +2151,6 @@ rb_eval_string( Solvable *s = $self->pool->solvables + $self->id; Queue r; queue_init(&r); - if (marker == -1 || marker == 1) { - if (keyname == SOLVABLE_PROVIDES) - marker = marker < 0 ? -SOLVABLE_FILEMARKER : SOLVABLE_FILEMARKER; - else if (keyname == SOLVABLE_REQUIRES) - marker = marker < 0 ? -SOLVABLE_PREREQMARKER : SOLVABLE_PREREQMARKER; - else - marker = 0; - } solvable_lookup_deparray(s, keyname, &r, marker); return r; } @@ -2168,14 +2160,6 @@ rb_eval_string( Solvable *s = $self->pool->solvables + $self->id; Queue r; queue_init(&r); - if (marker == -1 || marker == 1) { - if (keyname == SOLVABLE_PROVIDES) - marker = marker < 0 ? -SOLVABLE_FILEMARKER : SOLVABLE_FILEMARKER; - else if (keyname == SOLVABLE_REQUIRES) - marker = marker < 0 ? -SOLVABLE_PREREQMARKER : SOLVABLE_PREREQMARKER; - else - marker = 0; - } solvable_lookup_deparray(s, keyname, &r, marker); return r; } @@ -2290,8 +2274,7 @@ rb_eval_string( /* old interface, please use the generic add_deparray instead */ void add_provides(DepId id, Id marker = -1) { Solvable *s = $self->pool->solvables + $self->id; - if (marker == -1 || marker == 1) - marker = marker < 0 ? -SOLVABLE_FILEMARKER : SOLVABLE_FILEMARKER; + marker = solv_depmarker(SOLVABLE_PROVIDES, marker); s->provides = repo_addid_dep(s->repo, s->provides, id, marker); } void add_obsoletes(DepId id) { @@ -2304,8 +2287,7 @@ rb_eval_string( } void add_requires(DepId id, Id marker = -1) { Solvable *s = $self->pool->solvables + $self->id; - if (marker == -1 || marker == 1) - marker = marker < 0 ? -SOLVABLE_PREREQMARKER : SOLVABLE_PREREQMARKER; + marker = solv_depmarker(SOLVABLE_REQUIRES, marker); s->requires = repo_addid_dep(s->repo, s->requires, id, marker); } void add_recommends(DepId id) { @@ -2332,14 +2314,6 @@ rb_eval_string( void add_deparray(Id keyname, DepId id, Id marker = -1) { Solvable *s = $self->pool->solvables + $self->id; - if (marker == -1 || marker == 1) { - if (keyname == SOLVABLE_PROVIDES) - marker = marker < 0 ? -SOLVABLE_FILEMARKER : SOLVABLE_FILEMARKER; - else if (keyname == SOLVABLE_REQUIRES) - marker = marker < 0 ? -SOLVABLE_PREREQMARKER : SOLVABLE_PREREQMARKER; - else - marker = 0; - } solvable_add_deparray(s, keyname, id, marker); } diff --git a/src/libsolv.ver b/src/libsolv.ver index 0ae3390..0fd6993 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -253,6 +253,7 @@ SOLV_1.0 { solv_chksum_len; solv_chksum_str2type; solv_chksum_type2str; + solv_depmarker; solv_dupappend; solv_dupjoin; solv_free; diff --git a/src/repo.c b/src/repo.c index a6caa4b..be112c5 100644 --- a/src/repo.c +++ b/src/repo.c @@ -590,6 +590,20 @@ repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker) return repo_addid(repo, olddeps, id); } +/* return standard marker for the keyname dependency. + * 1: return positive marker, -1: return negative marker + */ +Id +solv_depmarker(Id keyname, Id marker) +{ + if (marker != 1 && marker != -1) + return marker; + if (keyname == SOLVABLE_PROVIDES) + return marker < 0 ? -SOLVABLE_FILEMARKER : SOLVABLE_FILEMARKER; + if (keyname == SOLVABLE_REQUIRES) + return marker < 0 ? -SOLVABLE_PREREQMARKER : SOLVABLE_PREREQMARKER; + return 0; +} /* * reserve Ids @@ -598,7 +612,6 @@ repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker) * * reserved ids will always begin at offset idarraysize */ - Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num) { @@ -1313,7 +1326,11 @@ int repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker) { int r = repo_lookup_idarray(repo, entry, keyname, q); - if (r && marker && q->count) + if (!r) + return 0; + if (marker == -1 || marker == 1) + marker = solv_depmarker(keyname, marker); + if (marker && q->count) { int i; if (marker < 0) @@ -1598,6 +1615,8 @@ void repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker) { Repodata *data; + if (marker == -1 || marker == 1) + marker = solv_depmarker(keyname, marker); if (p >= 0) { Solvable *s = repo->pool->solvables + p; @@ -1653,6 +1672,8 @@ void repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker) { Repodata *data; + if (marker == -1 || marker == 1) + marker = solv_depmarker(keyname, marker); if (marker) { /* complex case, splice old and new arrays */ diff --git a/src/repo.h b/src/repo.h index 5010b5d..21f4628 100644 --- a/src/repo.h +++ b/src/repo.h @@ -150,6 +150,7 @@ int repo_lookup_void(Repo *repo, Id entry, Id keyname); const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep); const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep); const void *repo_lookup_binary(Repo *repo, Id entry, Id keyname, int *lenp); +Id solv_depmarker(Id keyname, Id marker); void repo_set_id(Repo *repo, Id p, Id keyname, Id id); void repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num); -- 2.34.1