From 9d3f22380ac48d46cfafa9f8bb1ddb59ea486431 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Wed, 5 Dec 2012 11:25:10 +0100 Subject: rename selection_limit to selection_filter, add flags to make selection_make more flexible --- bindings/solv.i | 11 +++++++---- examples/p5solv | 1 + examples/pysolv | 27 ++++++++++++++------------- examples/rbsolv | 1 + examples/solv.c | 9 +++++---- src/libsolv.ver | 2 +- src/selection.c | 42 +++++++++++++++++++++++------------------- src/selection.h | 5 ++++- 8 files changed, 56 insertions(+), 42 deletions(-) diff --git a/bindings/solv.i b/bindings/solv.i index d83df92..bc3f1ab 100644 --- a/bindings/solv.i +++ b/bindings/solv.i @@ -833,10 +833,13 @@ typedef struct { static const Id SELECTION_NAME = SELECTION_NAME; static const Id SELECTION_PROVIDES = SELECTION_PROVIDES; static const Id SELECTION_FILELIST = SELECTION_FILELIST; - static const Id SELECTION_GLOB = SELECTION_GLOB; - static const Id SELECTION_NOCASE = SELECTION_NOCASE; + static const Id SELECTION_CANON = SELECTION_CANON; + static const Id SELECTION_DOTARCH = SELECTION_DOTARCH; + static const Id SELECTION_REL = SELECTION_REL; static const Id SELECTION_INSTALLED_ONLY = SELECTION_INSTALLED_ONLY; + static const Id SELECTION_GLOB = SELECTION_GLOB; static const Id SELECTION_FLAT = SELECTION_FLAT; + static const Id SELECTION_NOCASE = SELECTION_NOCASE; static const Id SELECTION_SOURCE_ONLY = SELECTION_SOURCE_ONLY; static const Id SELECTION_WITH_SOURCE = SELECTION_WITH_SOURCE; @@ -863,11 +866,11 @@ typedef struct { bool isempty() { return $self->q.count == 0; } - void limit(Selection *lsel) { + void filter(Selection *lsel) { if ($self->pool != lsel->pool) queue_empty(&$self->q); else - selection_limit($self->pool, &$self->q, &lsel->q); + selection_filter($self->pool, &$self->q, &lsel->q); } void add(Selection *lsel) { if ($self->pool == lsel->pool) diff --git a/examples/p5solv b/examples/p5solv index 56edbd5..fdb47d7 100755 --- a/examples/p5solv +++ b/examples/p5solv @@ -568,6 +568,7 @@ $pool->createwhatprovides(); my @jobs; for my $arg (@ARGV) { my $flags = $solv::Selection::SELECTION_NAME | $solv::Selection::SELECTION_PROVIDES | $solv::Selection::SELECTION_GLOB; + $flags |= $solv::Selection::SELECTION_CANON | $solv::Selection::SELECTION_DOTARCH | $solv::Selection::SELECTION_REL; if ($arg =~ /^\//) { $flags |= $solv::Selection::SELECTION_FILELIST; $flags |= $solv::Selection::SELECTION_INSTALLED_ONLY if $cmd eq 'erase'; diff --git a/examples/pysolv b/examples/pysolv index 7e2eda5..e898c09 100755 --- a/examples/pysolv +++ b/examples/pysolv @@ -633,7 +633,7 @@ for repo in repos: if int(repo['enabled']): repo.load(pool) -repolimiter = None +repofilter = None if options.repos: for reponame in options.repos: mrepos = [ repo for repo in repos if repo.name == reponame ] @@ -642,9 +642,9 @@ if options.repos: sys.exit(1) repo = mrepos[0] if hasattr(repo, 'handle'): - if not repolimiter: - repolimiter = pool.Selection() - repolimiter.add_raw(Job.SOLVER_SOLVABLE_REPO|Job.SOLVER_SETREPO|Job.SOLVER_SETVENDOR, repo.handle.id) + if not repofilter: + repofilter = pool.Selection() + repofilter.add_raw(Job.SOLVER_SOLVABLE_REPO|Job.SOLVER_SETREPO|Job.SOLVER_SETVENDOR, repo.handle.id) if cmd == 'search': pool.createwhatprovides() @@ -652,8 +652,8 @@ if cmd == 'search': di = pool.Dataiterator(0, solv.SOLVABLE_NAME, args[0], Dataiterator.SEARCH_SUBSTRING|Dataiterator.SEARCH_NOCASE) for d in di: sel.add_raw(Job.SOLVER_SOLVABLE, d.solvid) - if repolimiter: - sel.limit(repolimiter) + if repofilter: + sel.filter(repofilter) for s in sel.solvables(): print " - %s [%s]: %s" % (s, s.repo.name, s.lookup_str(solv.SOLVABLE_SUMMARY)) sys.exit(0) @@ -689,17 +689,18 @@ for arg in args: jobs.append(pool.Job(Job.SOLVER_SOLVABLE, cmdlinerepo['packages'][arg])) else: flags = Selection.SELECTION_NAME|Selection.SELECTION_PROVIDES|Selection.SELECTION_GLOB + flags |= Selection.SELECTION_CANON|Selection.SELECTION_DOTARCH|Selection.SELECTION_REL if len(arg) and arg[0] == '/': flags |= Selection.SELECTION_FILELIST if cmd == 'erase': flags |= Selection.SELECTION_INSTALLED_ONLY sel = pool.select(arg, flags) - if repolimiter: - sel.limit(repolimiter) + if repofilter: + sel.filter(repofilter) if sel.isempty(): sel = pool.select(arg, flags | Selection.SELECTION_NOCASE) - if repolimiter: - sel.limit(repolimiter) + if repofilter: + sel.filter(repofilter) if not sel.isempty(): print "[ignoring case for '%s']" % arg if sel.isempty(): @@ -711,11 +712,11 @@ for arg in args: print "[using capability match for '%s']" % arg jobs += sel.jobs(cmdactionmap[cmd]) -if not jobs and (cmd == 'up' or cmd == 'dup' or cmd == 'verify' or repolimiter): +if not jobs and (cmd == 'up' or cmd == 'dup' or cmd == 'verify' or repofilter): sel = pool.Selection() sel.add_raw(Job.SOLVER_SOLVABLE_ALL, 0) - if repolimiter: - sel.limit(repolimiter) + if repofilter: + sel.filter(repofilter) jobs += sel.jobs(cmdactionmap[cmd]) if not jobs: diff --git a/examples/rbsolv b/examples/rbsolv index b9db10d..367b6c3 100755 --- a/examples/rbsolv +++ b/examples/rbsolv @@ -581,6 +581,7 @@ pool.createwhatprovides() jobs = [] for arg in args flags = Solv::Selection::SELECTION_NAME | Solv::Selection::SELECTION_PROVIDES|Solv::Selection::SELECTION_GLOB + flags |= Solv::Selection::SELECTION_CANON | Solv::Selection::SELECTION_DOTARCH | Solv::Selection::SELECTION_REL if arg =~ /^\// flags |= Solv::Selection::SELECTION_FILELIST flags |= Solv::Selection::SELECTION_INSTALLED_ONLY if cmd == 'erase' diff --git a/examples/solv.c b/examples/solv.c index 9c9510f..8ee8fe8 100644 --- a/examples/solv.c +++ b/examples/solv.c @@ -2612,7 +2612,7 @@ main(int argc, char **argv) queue_push2(&sel, SOLVER_SOLVABLE, di.solvid); dataiterator_free(&di); if (repofilter.count) - selection_limit(pool, &sel, &repofilter); + selection_filter(pool, &sel, &repofilter); queue_init(&q); selection_solvables(pool, &sel, &q); @@ -2692,19 +2692,20 @@ main(int argc, char **argv) } queue_init(&job2); flags = SELECTION_NAME|SELECTION_PROVIDES|SELECTION_GLOB; + flags |= SELECTION_CANON|SELECTION_DOTARCH|SELECTION_REL; if (mode == MODE_LIST) flags |= SELECTION_WITH_SOURCE; if (argv[i][0] == '/') flags |= SELECTION_FILELIST | (mode == MODE_ERASE ? SELECTION_INSTALLED_ONLY : 0); rflags = selection_make(pool, &job2, argv[i], flags); if (repofilter.count) - selection_limit(pool, &job2, &repofilter); + selection_filter(pool, &job2, &repofilter); if (!job2.count) { flags |= SELECTION_NOCASE; rflags = selection_make(pool, &job2, argv[i], flags); if (repofilter.count) - selection_limit(pool, &job2, &repofilter); + selection_filter(pool, &job2, &repofilter); if (job2.count) printf("[ignoring case for '%s']\n", argv[i]); } @@ -2726,7 +2727,7 @@ main(int argc, char **argv) { queue_push2(&job, SOLVER_SOLVABLE_ALL, 0); if (repofilter.count) - selection_limit(pool, &job, &repofilter); + selection_filter(pool, &job, &repofilter); } queue_free(&repofilter); diff --git a/src/libsolv.ver b/src/libsolv.ver index 4296b1a..bc487ce 100644 --- a/src/libsolv.ver +++ b/src/libsolv.ver @@ -228,7 +228,7 @@ SOLV_1.0 { repodata_write_filtered; repopagestore_compress_page; selection_add; - selection_limit; + selection_filter; selection_make; selection_solvables; solv_bin2hex; diff --git a/src/selection.c b/src/selection.c index 66552b2..06717a6 100644 --- a/src/selection.c +++ b/src/selection.c @@ -152,7 +152,7 @@ selection_flatten(Pool *pool, Queue *selection) } static void -selection_limit_rel(Pool *pool, Queue *selection, Id relflags, Id relevr) +selection_filter_rel(Pool *pool, Queue *selection, Id relflags, Id relevr) { int i; for (i = 0; i < selection->count; i += 2) @@ -358,7 +358,7 @@ selection_depglob(Pool *pool, Queue *selection, const char *name, int flags) if (doglob && (flags & SELECTION_NOCASE) != 0) globflags = FNM_CASEFOLD; -#if 0 /* doesn't work with selection_limit_rel yet */ +#if 0 /* doesn't work with selection_filter_rel yet */ if (doglob && !strcmp(name, "*") && (flags & SELECTION_FLAT) != 0) { /* can't do this for SELECTION_PROVIDES, as src rpms don't provide anything */ @@ -438,6 +438,8 @@ selection_depglob_arch(Pool *pool, Queue *selection, const char *name, int flags if ((ret = selection_depglob(pool, selection, name, flags)) != 0) return ret; + if (!(flags & SELECTION_DOTARCH)) + return 0; /* check if there is an .arch suffix */ if ((r = strrchr(name, '.')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0) { @@ -447,9 +449,9 @@ selection_depglob_arch(Pool *pool, Queue *selection, const char *name, int flags flags |= SELECTION_SOURCE_ONLY; if ((ret = selection_depglob(pool, selection, rname, flags)) != 0) { - selection_limit_rel(pool, selection, REL_ARCH, archid); + selection_filter_rel(pool, selection, REL_ARCH, archid); solv_free(rname); - return ret; + return ret | SELECTION_DOTARCH; } solv_free(rname); } @@ -531,9 +533,9 @@ selection_rel(Pool *pool, Queue *selection, const char *name, int flags) if ((ret = selection_depglob_arch(pool, selection, rname, flags)) != 0) { if (rflags) - selection_limit_rel(pool, selection, rflags, pool_str2id(pool, r, 1)); + selection_filter_rel(pool, selection, rflags, pool_str2id(pool, r, 1)); solv_free(rname); - return ret; + return ret | SELECTION_REL; } solv_free(rname); return 0; @@ -549,7 +551,7 @@ selection_rel(Pool *pool, Queue *selection, const char *name, int flags) /* magic epoch promotion code, works only for SELECTION_NAME selections */ static void -selection_limit_evr(Pool *pool, Queue *selection, char *evr) +selection_filter_evr(Pool *pool, Queue *selection, char *evr) { int i, j; Queue q; @@ -617,7 +619,7 @@ selection_limit_evr(Pool *pool, Queue *selection, char *evr) } queue_empty(&q); queue_push2(&q, selection->elements[i], selection->elements[i + 1]); - selection_limit_rel(pool, &q, REL_EQ, id); + selection_filter_rel(pool, &q, REL_EQ, id); if (!q.count) continue; /* oops, no match */ selection->elements[j] = q.elements[0]; @@ -628,8 +630,9 @@ selection_limit_evr(Pool *pool, Queue *selection, char *evr) queue_free(&q); } +/* match the "canonical" name of the package */ static int -selection_nevra(Pool *pool, Queue *selection, const char *name, int flags) +selection_canon(Pool *pool, Queue *selection, const char *name, int flags) { char *rname, *r, *r2; Id archid = 0; @@ -660,11 +663,11 @@ selection_nevra(Pool *pool, Queue *selection, const char *name, int flags) if ((r2 = strchr(r, '_')) != 0 && r[1] && (archid = str2archid(pool, r + 1)) != 0) { *r2 = 0; /* split off */ - selection_limit_rel(pool, selection, REL_ARCH, archid); + selection_filter_rel(pool, selection, REL_ARCH, archid); } - selection_limit_rel(pool, selection, REL_EQ, pool_str2id(pool, r, 1)); + selection_filter_rel(pool, selection, REL_EQ, pool_str2id(pool, r, 1)); solv_free(rname); - return ret; + return ret | SELECTION_CANON; } if ((r = strrchr(name, '-')) == 0) @@ -698,10 +701,10 @@ selection_nevra(Pool *pool, Queue *selection, const char *name, int flags) } } if (archid) - selection_limit_rel(pool, selection, REL_ARCH, archid); - selection_limit_evr(pool, selection, r + 1); /* magic epoch promotion */ + selection_filter_rel(pool, selection, REL_ARCH, archid); + selection_filter_evr(pool, selection, r + 1); /* magic epoch promotion */ solv_free(rname); - return ret; + return ret | SELECTION_CANON; } int @@ -713,19 +716,20 @@ selection_make(Pool *pool, Queue *selection, const char *name, int flags) queue_empty(selection); if (*name == '/' && (flags & SELECTION_FILELIST)) ret = selection_filelist(pool, selection, name, flags); - if (!ret && (r = strpbrk(name, "<=>")) != 0) + if (!ret && (flags & SELECTION_REL) != 0 && (r = strpbrk(name, "<=>")) != 0) ret = selection_rel(pool, selection, name, flags); if (!ret) ret = selection_depglob_arch(pool, selection, name, flags); - if (!ret && (flags & SELECTION_NAME) != 0) - ret = selection_nevra(pool, selection, name, flags); + if (!ret && (flags & SELECTION_CANON) != 0) + ret = selection_canon(pool, selection, name, flags); + if (ret && (flags & SELECTION_FLAT) != 0) selection_flatten(pool, selection); return ret; } void -selection_limit(Pool *pool, Queue *sel1, Queue *sel2) +selection_filter(Pool *pool, Queue *sel1, Queue *sel2) { int i, j, miss; Id p, pp; diff --git a/src/selection.h b/src/selection.h index 9b7d454..4aa2db4 100644 --- a/src/selection.h +++ b/src/selection.h @@ -18,6 +18,9 @@ #define SELECTION_NAME (1 << 0) #define SELECTION_PROVIDES (1 << 1) #define SELECTION_FILELIST (1 << 2) +#define SELECTION_CANON (1 << 3) +#define SELECTION_DOTARCH (1 << 4) +#define SELECTION_REL (1 << 5) #define SELECTION_INSTALLED_ONLY (1 << 8) #define SELECTION_GLOB (1 << 9) @@ -27,7 +30,7 @@ #define SELECTION_WITH_SOURCE (1 << 13) extern int selection_make(Pool *pool, Queue *selection, const char *name, int flags); -extern void selection_limit(Pool *pool, Queue *sel1, Queue *sel2); +extern void selection_filter(Pool *pool, Queue *sel1, Queue *sel2); extern void selection_add(Pool *pool, Queue *sel1, Queue *sel2); extern void selection_solvables(Pool *pool, Queue *selection, Queue *pkgs); -- cgit v1.2.3