diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-09-13 12:46:41 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-09-13 13:03:38 +0300 |
commit | 17d3db4e3a36861ffc50d7232e92d39834079931 (patch) | |
tree | e5891fc5cd9729d6376f12069a3f970bfefeb9d2 /lib | |
parent | 26ae2e4390f4e03d70ee3b267a0735f1f2b1ef10 (diff) | |
download | librpm-tizen-17d3db4e3a36861ffc50d7232e92d39834079931.tar.gz librpm-tizen-17d3db4e3a36861ffc50d7232e92d39834079931.tar.bz2 librpm-tizen-17d3db4e3a36861ffc50d7232e92d39834079931.zip |
Unify the three rpmdsFooMatchesDep() functions into one
- These all do more or less the same thing, easily handled with a common
function that takes a couple of more extra parameters. The old variants
become just wrappers to call the pool-aware rpmdsMatches() with suitable
arguments.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rpmds.c | 70 | ||||
-rw-r--r-- | lib/rpmds.h | 12 |
2 files changed, 46 insertions, 36 deletions
diff --git a/lib/rpmds.c b/lib/rpmds.c index 2ed3d8d54..973490fda 100644 --- a/lib/rpmds.c +++ b/lib/rpmds.c @@ -858,58 +858,56 @@ exit: return result; } -int rpmdsMatchesDep (const Header h, int ix, const rpmds req, int nopromote) +int rpmdsMatches(rpmstrPool pool, Header h, int prix, + rpmds req, int selfevr, int nopromote) { - /* Get provides information from header */ - rpmds provides = rpmdsInit(rpmdsNew(h, RPMTAG_PROVIDENAME, 0)); - int result = 0; - - rpmdsSetIx(provides,ix); - result = rpmdsCompare(provides, req); - - rpmdsFree(provides); - return result; -} - -int rpmdsAnyMatchesDep (const Header h, const rpmds req, int nopromote) -{ - rpmds provides = NULL; + rpmds provides; + rpmTagVal tag = RPMTAG_PROVIDENAME; int result = 0; /* Get provides information from header */ - provides = rpmdsInit(rpmdsNew(h, RPMTAG_PROVIDENAME, 0)); - if (provides == NULL) - goto exit; /* XXX should never happen */ - - (void) rpmdsSetNoPromote(provides, nopromote); + if (selfevr) + provides = rpmdsThisPool(pool, h, tag, RPMSENSE_EQUAL); + else + provides = rpmdsNewPool(pool, h, tag, 0); - while (rpmdsNext(provides) >= 0) { + rpmdsSetNoPromote(provides, nopromote); + /* + * For a self-provide and indexed provide, we only need one comparison. + * Otherwise loop through the provides until match or end. + */ + if (prix >= 0 || selfevr) { + if (prix >= 0) + rpmdsSetIx(provides, prix); result = rpmdsCompare(provides, req); - - /* If this provide matches the require, we're done. */ - if (result) - break; + } else { + provides = rpmdsInit(provides); + while (rpmdsNext(provides) >= 0) { + result = rpmdsCompare(provides, req); + /* If this provide matches the require, we're done. */ + if (result) + break; + } } -exit: rpmdsFree(provides); - return result; } -int rpmdsNVRMatchesDep(const Header h, const rpmds req, int nopromote) +int rpmdsMatchesDep (const Header h, int ix, const rpmds req, int nopromote) { - rpmds pkg; - int rc = 1; /* XXX assume match, names already match here */ + return rpmdsMatches(NULL, h, ix, req, 0, nopromote); +} - /* Get package information from header */ - pkg = rpmdsThis(h, RPMTAG_PROVIDENAME, RPMSENSE_EQUAL); - rpmdsSetNoPromote(pkg, nopromote); - rc = rpmdsCompare(pkg, req); - rpmdsFree(pkg); +int rpmdsAnyMatchesDep (const Header h, const rpmds req, int nopromote) +{ + return rpmdsMatches(NULL, h, -1, req, 0, nopromote); +} - return rc; +int rpmdsNVRMatchesDep(const Header h, const rpmds req, int nopromote) +{ + return rpmdsMatches(NULL, h, -1, req, 1, nopromote); } /** diff --git a/lib/rpmds.h b/lib/rpmds.h index 9127e51bd..750fe37ab 100644 --- a/lib/rpmds.h +++ b/lib/rpmds.h @@ -377,6 +377,18 @@ int rpmdsMatchesDep (const Header h, int ix, const rpmds req, int nopromote); */ int rpmdsNVRMatchesDep(const Header h, const rpmds req, int nopromote); +/** \ingroup rpmds + * Swiss army knife dependency matching function. + * @param pool string pool (or NULL for private pool) + * @param h header + * @param prix index to provides (or -1 or any) + * @param req dependency set + * @param selfevr only look at package EVR? + * @param nopromote dont promote epoch in comparison? + * @return 1 if dependency overlaps, 0 otherwise + */ +int rpmdsMatches(rpmstrPool pool, Header h, int prix, + rpmds req, int selfevr, int nopromote); /** * Load rpmlib provides into a dependency set. * @retval *dsp (loaded) depedency set |