diff options
author | Timo Teräs <timo.teras@iki.fi> | 2023-03-05 12:15:56 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2023-03-06 21:39:48 +0200 |
commit | bd3e2be64d1118cb07ec1ecd82ca4abd2ad9ae96 (patch) | |
tree | cc051ec85ea0e870a1afc1ca7bfd25eeceab0173 /src/app_search.c | |
parent | 8453943c2ebee0f0c1b08c88e927da1fffdf1784 (diff) | |
download | apk-tools-bd3e2be64d1118cb07ec1ecd82ca4abd2ad9ae96.tar.gz apk-tools-bd3e2be64d1118cb07ec1ecd82ca4abd2ad9ae96.tar.bz2 apk-tools-bd3e2be64d1118cb07ec1ecd82ca4abd2ad9ae96.tar.xz apk-tools-bd3e2be64d1118cb07ec1ecd82ca4abd2ad9ae96.zip |
db, apps: sort packages by pkgname and pkgver
This will also fix "search" to display one match from each principal
pkgname group. "search -e vim" will now show both vim and gvim.
fixes #10864
fixes #10777
Diffstat (limited to 'src/app_search.c')
-rw-r--r-- | src/app_search.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/app_search.c b/src/app_search.c index 48b19d5..1dcb7b6 100644 --- a/src/app_search.c +++ b/src/app_search.c @@ -26,18 +26,11 @@ struct search_ctx { unsigned int matches; struct apk_string_array *filter; + struct apk_package *prev_match; }; -static int unique_match(struct apk_package *pkg) -{ - if (pkg->state_int) return 0; - pkg->state_int = 1; - return 1; -} - static void print_package_name(struct search_ctx *ctx, struct apk_package *pkg) { - if (!unique_match(pkg)) return; printf("%s", pkg->name->name); if (ctx->verbosity > 0) printf("-" BLOB_FMT, BLOB_PRINTF(*pkg->version)); @@ -48,7 +41,6 @@ static void print_package_name(struct search_ctx *ctx, struct apk_package *pkg) static void print_origin_name(struct search_ctx *ctx, struct apk_package *pkg) { - if (!unique_match(pkg)) return; if (pkg->origin != NULL) printf(BLOB_FMT, BLOB_PRINTF(*pkg->origin)); else @@ -144,26 +136,28 @@ match: ctx->print_result(ctx, pkg); } -static int print_result(struct apk_database *db, const char *match, struct apk_name *name, void *pctx) +static int print_result(struct apk_database *db, const char *match, struct apk_package *pkg, void *pctx) { struct search_ctx *ctx = pctx; - struct apk_provider *p; - struct apk_package *pkg = NULL; - if (!name) return 0; + if (!pkg) return 0; if (ctx->show_all) { - foreach_array_item(p, name->providers) - print_result_pkg(ctx, p->pkg); - } else { - foreach_array_item(p, name->providers) { - if (pkg == NULL || - apk_version_compare_blob(*p->version, *pkg->version) == APK_VERSION_GREATER) - pkg = p->pkg; - } - if (pkg) - print_result_pkg(ctx, pkg); + print_result_pkg(ctx, pkg); + return 0; } + + if (!ctx->prev_match) { + ctx->prev_match = pkg; + return 0; + } + if (ctx->prev_match->name != pkg->name) { + print_result_pkg(ctx, ctx->prev_match); + ctx->prev_match = pkg; + return 0; + } + if (apk_pkg_version_compare(pkg, ctx->prev_match) == APK_VERSION_GREATER) + ctx->prev_match = pkg; return 0; } @@ -194,7 +188,9 @@ static int search_main(void *pctx, struct apk_ctx *ac, struct apk_string_array * *pmatch = tmp; } } - apk_db_foreach_sorted_name(db, args, print_result, ctx); + apk_db_foreach_sorted_providers(db, args, print_result, ctx); + if (ctx->prev_match) print_result_pkg(ctx, ctx->prev_match); + return 0; } |