From 8fcb57bf0f80cec68ce24ef5d9305f23a8d99779 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 29 Jan 2018 02:39:39 +0000 Subject: list: refactor package dumping vs package filtering --- src/list.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/list.c') diff --git a/src/list.c b/src/list.c index 08c02a1..a3e8f84 100644 --- a/src/list.c +++ b/src/list.c @@ -125,36 +125,36 @@ static void print_package(const struct apk_package *pkg, const struct list_ctx * printf("\n"); } -static void print_result(struct apk_database *db, const char *match, struct apk_name *name, void *pctx) +static void filter_package(const struct apk_package *pkg, const struct list_ctx *ctx) { - struct list_ctx *ctx = pctx; - struct apk_provider *p; - struct apk_package *pkg; + if (ctx->match_origin && !origin_matches(ctx, pkg)) + return; - if (name == NULL) + if (ctx->installed && pkg->ipkg == NULL) return; - foreach_array_item(p, name->providers) - { - pkg = p->pkg; + if (ctx->orphaned && !is_orphaned(pkg->name)) + return; - if (ctx->match_origin && !origin_matches(ctx, pkg)) - continue; + if (ctx->available && pkg->repos == BIT(1)) + return; - if (ctx->installed && pkg->ipkg == NULL) - continue; + if (ctx->upgradable && !is_upgradable(pkg->name, pkg)) + return; - if (ctx->orphaned && !is_orphaned(name)) - continue; + print_package(pkg, ctx); +} - if (ctx->available && pkg->repos == BIT(1)) - continue; +static void print_result(struct apk_database *db, const char *match, struct apk_name *name, void *pctx) +{ + struct list_ctx *ctx = pctx; + struct apk_provider *p; - if (ctx->upgradable && !is_upgradable(name, pkg)) - continue; + if (name == NULL) + return; - print_package(pkg, ctx); - } + foreach_array_item(p, name->providers) + filter_package(p->pkg, ctx); } static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg) -- cgit v1.2.3-70-g09d2