Permalink
Browse files

Query: add proper version filtering.

The EVR searching implementation based on dataiterator only worked with HY_EQ.
  • Loading branch information...
1 parent ac52df8 commit 8bd639c5c3166d84aa236f5781cc5f716aa7ecd4 Ales Kozumplik committed Aug 28, 2012
Showing with 44 additions and 8 deletions.
  1. +29 −4 src/query.c
  2. +15 −4 tests/test_query.c
View
@@ -123,19 +123,41 @@ filter_dataiterator(HyQuery q, struct _Filter *f, Map *m)
}
static void
+filter_evr(HyQuery q, struct _Filter *f, Map *m)
+{
+ Pool *pool = sack_pool(q->sack);
+
+ for (int mi = 0; mi < f->nmatches; ++mi) {
+ Id match_evr = pool_str2id(pool, f->matches[mi], 1);
+
+ for (Id id = 1; id < pool->nsolvables; ++id) {
+ Solvable *s = pool_id2solvable(pool, id);
+ int cmp = pool_evrcmp(pool, s->evr, match_evr, EVRCMP_COMPARE);
+
+ if ((cmp > 0 && f->filter_type & HY_GT) ||
+ (cmp < 0 && f->filter_type & HY_LT) ||
+ (cmp == 0 && f->filter_type & HY_EQ))
+ MAPSET(m, id);
+ }
+ }
+}
+
+static void
filter_providers(HyQuery q, struct _Filter *f, Map *m)
{
Pool *pool = sack_pool(q->sack);
- Id id_n, id_evr, r, p, pp;
+ Id id, id_evr, r, p, pp;
int flags;
assert(f->nmatches == 1);
-
sack_make_provides_ready(q->sack);
- id_n = pool_str2id(pool, f->matches[0], 0);
+
+ id = pool_str2id(pool, f->matches[0], 0);
+ if (id == STRID_NULL || id == STRID_EMPTY)
+ return;
id_evr = pool_str2id(pool, f->evr, 1);
flags = type2relflags(f->filter_type);
- r = pool_rel2id(pool, id_n, id_evr, flags, 1);
+ r = pool_rel2id(pool, id, id_evr, flags, 1);
FOR_JOB_SELECT(p, pp, SOLVER_SOLVABLE_PROVIDES, r)
MAPSET(m, p);
}
@@ -466,6 +488,9 @@ hy_query_run(HyQuery q)
map_empty(&m);
switch (f->keyname) {
+ case HY_PKG_EVR:
+ filter_evr(q, f, &m);
+ break;
case HY_PKG_PROVIDES:
filter_providers(q, f, &m);
break;
View
@@ -94,13 +94,24 @@ END_TEST
START_TEST(test_query_evr)
{
HyQuery q = hy_query_create(test_globals.sack);
- hy_query_filter(q, HY_PKG_EVR, HY_EQ, "5.1-0");
- fail_unless(query_count_results(q) == 0);
+ hy_query_filter(q, HY_PKG_EVR, HY_EQ, "6.0-0");
+ fail_unless(query_count_results(q) == 1);
hy_query_free(q);
q = hy_query_create(test_globals.sack);
- hy_query_filter(q, HY_PKG_EVR, HY_EQ, "5.0-0");
- fail_unless(query_count_results(q) == 2);
+ hy_query_filter(q, HY_PKG_EVR, HY_GT, "5.9-0");
+ fail_unless(query_count_results(q) == 1);
+ hy_query_free(q);
+
+ q = hy_query_create(test_globals.sack);
+ hy_query_filter(q, HY_PKG_EVR, HY_GT|HY_EQ, "5.0-0");
+ fail_unless(query_count_results(q) == 3);
+ hy_query_free(q);
+
+ const char *evrs[] = {"6.0-0", "2-9", "5.0-0", "0-100", NULL};
+ q = hy_query_create(test_globals.sack);
+ hy_query_filter_in(q, HY_PKG_EVR, HY_EQ, evrs);
+ fail_unless(query_count_results(q) == 4);
hy_query_free(q);
}
END_TEST

0 comments on commit 8bd639c

Please sign in to comment.