summaryrefslogtreecommitdiff
path: root/src/package.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-06-15 20:39:05 +0300
committerTimo Teräs <timo.teras@iki.fi>2013-06-15 22:25:23 +0300
commitf79e3946a40bf6beb2a38050a866c0fb1ed4bcf4 (patch)
treee49fefbf64cc88b24db54fe726386fb4950bea8c /src/package.c
parent5b02400b268e4e867a30cd76821ff7139502089e (diff)
downloadapk-tools-f79e3946a40bf6beb2a38050a866c0fb1ed4bcf4.tar.gz
apk-tools-f79e3946a40bf6beb2a38050a866c0fb1ed4bcf4.tar.bz2
apk-tools-f79e3946a40bf6beb2a38050a866c0fb1ed4bcf4.tar.xz
apk-tools-f79e3946a40bf6beb2a38050a866c0fb1ed4bcf4.zip
pkg: apk_pkg_foreach_* add matching generation
So same package it is possible to not match same package multiple times. Use generation count, so this is handled cleanly during recursion, like in the use case of search applet.
Diffstat (limited to 'src/package.c')
-rw-r--r--src/package.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/package.c b/src/package.c
index 31321e7..0fca1db 100644
--- a/src/package.c
+++ b/src/package.c
@@ -1190,28 +1190,46 @@ int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b)
return apk_version_compare_blob(*a->version, *b->version);
}
+unsigned int apk_foreach_genid(void)
+{
+ static unsigned int foreach_genid;
+ foreach_genid += (~APK_FOREACH_GENID_MASK) + 1;
+ return foreach_genid;
+}
+
void apk_pkg_foreach_matching_dependency(
- struct apk_package *pkg, struct apk_dependency_array *deps, int match, struct apk_package *mpkg,
+ struct apk_package *pkg, struct apk_dependency_array *deps,
+ unsigned int match, struct apk_package *mpkg,
void cb(struct apk_package *pkg0, struct apk_dependency *dep0, struct apk_package *pkg, void *ctx),
void *ctx)
{
+ unsigned int genid = match & APK_FOREACH_GENID_MASK;
struct apk_dependency *d;
+ if (genid && pkg->foreach_genid >= genid)
+ return;
+ if (pkg)
+ pkg->foreach_genid = genid;
+
foreach_array_item(d, deps) {
- if (apk_dep_analyze(d, mpkg) & match)
+ if (apk_dep_analyze(d, mpkg) & match) {
cb(pkg, d, mpkg, ctx);
+ if (genid)
+ break;
+ }
}
}
static void foreach_reverse_dependency(
struct apk_package *pkg,
struct apk_name_array *rdepends,
- int match,
+ unsigned int match,
void cb(struct apk_package *pkg0, struct apk_dependency *dep0, struct apk_package *pkg, void *ctx),
void *ctx)
{
- int installed = match & APK_FOREACH_INSTALLED;
- int marked = match & APK_FOREACH_MARKED;
+ unsigned int installed = match & APK_FOREACH_INSTALLED;
+ unsigned int marked = match & APK_FOREACH_MARKED;
+ unsigned int genid = match & APK_FOREACH_GENID_MASK;
struct apk_name **pname0, *name0;
struct apk_provider *p0;
struct apk_package *pkg0;
@@ -1225,6 +1243,9 @@ static void foreach_reverse_dependency(
continue;
if (marked && !pkg0->marked)
continue;
+ if (genid && pkg0->foreach_genid >= genid)
+ continue;
+ pkg0->foreach_genid = genid;
foreach_array_item(d0, pkg0->depends) {
if (apk_dep_analyze(d0, pkg) & match)
cb(pkg0, d0, pkg, ctx);
@@ -1234,7 +1255,7 @@ static void foreach_reverse_dependency(
}
void apk_pkg_foreach_reverse_dependency(
- struct apk_package *pkg, int match,
+ struct apk_package *pkg, unsigned int match,
void cb(struct apk_package *pkg0, struct apk_dependency *dep0, struct apk_package *pkg, void *ctx),
void *ctx)
{