[pacman-dev] [PATCH 1/4] libalpm: fix incorrect documentation
--- lib/libalpm/deps.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 71185c68..ce7869c3 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -643,10 +643,9 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit) * @param dep is the dependency to search for * @param dbs are the databases to search * @param excluding are the packages to exclude from the search - * @param prompt if true, will cause an unresolvable dependency to issue an - * interactive prompt asking whether the package should be removed from - * the transaction or the transaction aborted; if false, simply returns - * an error code without prompting + * @param prompt if true, ask an alpm_question_install_ignorepkg_t to decide + * if ignored packages should be installed; if false, skip ignored + * packages. * @return the resolved package **/ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, @@ -766,8 +765,11 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, /** Find a package satisfying a specified dependency. * First look for a literal, going through each db one by one. Then look for - * providers. The first satisfier found is returned. + * providers. The first satisfier that belongs to an installed package is + * returned. If no providers belong to an installed package then an + * alpm_question_select_provider_t is created to select the provider. * The dependency can include versions with depmod operators. + * * @param handle the context handle * @param dbs an alpm_list_t* of alpm_db_t where the satisfier will be searched * @param depstring package or provision name, versioned or not -- 2.23.0
If we failed to get the pkg from pkgcache then we know no satisfying package exists by name. So only compare provides. --- lib/libalpm/deps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index ce7869c3..322c4e7e 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -698,7 +698,8 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, for(j = _alpm_db_get_pkgcache(db); j; j = j->next) { alpm_pkg_t *pkg = j->data; if((pkg->name_hash != dep->name_hash || strcmp(pkg->name, dep->name) != 0) - && _alpm_depcmp(pkg, dep) && !alpm_pkg_find(excluding, pkg->name)) { + && _alpm_depcmp_provides(dep, alpm_pkg_get_provides(pkg)) + && !alpm_pkg_find(excluding, pkg->name)) { if(alpm_pkg_should_ignore(handle, pkg)) { alpm_question_install_ignorepkg_t question = { .type = ALPM_QUESTION_INSTALL_IGNOREPKG, -- 2.23.0
On 09/08/19 at 10:45pm, morganamilo wrote:
If we failed to get the pkg from pkgcache then we know no satisfying package exists by name. So only compare provides. --- lib/libalpm/deps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index ce7869c3..322c4e7e 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -698,7 +698,8 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, for(j = _alpm_db_get_pkgcache(db); j; j = j->next) { alpm_pkg_t *pkg = j->data; if((pkg->name_hash != dep->name_hash || strcmp(pkg->name, dep->name) != 0)
Unrelated to this patch, but we probably shouldn't be filtering out name matches here. A package could provide a different version of itself.
- && _alpm_depcmp(pkg, dep) && !alpm_pkg_find(excluding, pkg->name)) { + && _alpm_depcmp_provides(dep, alpm_pkg_get_provides(pkg)) + && !alpm_pkg_find(excluding, pkg->name)) { if(alpm_pkg_should_ignore(handle, pkg)) { alpm_question_install_ignorepkg_t question = { .type = ALPM_QUESTION_INSTALL_IGNOREPKG, -- 2.23.0
On 9/9/19 7:45 am, morganamilo wrote:
If we failed to get the pkg from pkgcache then we know no satisfying package exists by name. So only compare provides. --- lib/libalpm/deps.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Thanks. Applied.
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index ce7869c3..322c4e7e 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -698,7 +698,8 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, for(j = _alpm_db_get_pkgcache(db); j; j = j->next) { alpm_pkg_t *pkg = j->data; if((pkg->name_hash != dep->name_hash || strcmp(pkg->name, dep->name) != 0) - && _alpm_depcmp(pkg, dep) && !alpm_pkg_find(excluding, pkg->name)) { + && _alpm_depcmp_provides(dep, alpm_pkg_get_provides(pkg)) + && !alpm_pkg_find(excluding, pkg->name)) { if(alpm_pkg_should_ignore(handle, pkg)) { alpm_question_install_ignorepkg_t question = { .type = ALPM_QUESTION_INSTALL_IGNOREPKG,
when a satisfying package is already installed, we always pick it instead of prompting the user. So we can return that package as soon as we find it, instead of waiting until we've iterated through all the databases. --- lib/libalpm/deps.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 322c4e7e..f69f24ad 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -719,20 +719,19 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, } _alpm_log(handle, ALPM_LOG_DEBUG, "provider found (%s provides %s)\n", pkg->name, dep->name); + + /* provide is already installed so return early instead of prompting later */ + if(_alpm_db_get_pkgfromcache(handle->db_local, pkg->name)) { + alpm_list_free(providers); + return pkg; + } + providers = alpm_list_add(providers, pkg); /* keep looking for other providers in the all dbs */ } } } - /* first check if one provider is already installed locally */ - for(i = providers; i; i = i->next) { - alpm_pkg_t *pkg = i->data; - if(_alpm_db_get_pkgfromcache(handle->db_local, pkg->name)) { - alpm_list_free(providers); - return pkg; - } - } count = alpm_list_count(providers); if(count >= 1) { alpm_question_select_provider_t question = { -- 2.23.0
On 9/9/19 7:45 am, morganamilo wrote:
when a satisfying package is already installed, we always pick it instead of prompting the user. So we can return that package as soon as we find it, instead of waiting until we've iterated through all the databases. ---
Ack.
lib/libalpm/deps.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 322c4e7e..f69f24ad 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -719,20 +719,19 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, } _alpm_log(handle, ALPM_LOG_DEBUG, "provider found (%s provides %s)\n", pkg->name, dep->name); + + /* provide is already installed so return early instead of prompting later */ + if(_alpm_db_get_pkgfromcache(handle->db_local, pkg->name)) { + alpm_list_free(providers); + return pkg; + } + providers = alpm_list_add(providers, pkg); /* keep looking for other providers in the all dbs */ } } }
- /* first check if one provider is already installed locally */ - for(i = providers; i; i = i->next) { - alpm_pkg_t *pkg = i->data; - if(_alpm_db_get_pkgfromcache(handle->db_local, pkg->name)) { - alpm_list_free(providers); - return pkg; - } - } count = alpm_list_count(providers); if(count >= 1) { alpm_question_select_provider_t question = {
Try and find an exact match via pkgcache before iterating the entire localdb. Gives a noticeable speed up for exact matches e.g. `pacman -T zlib` --- Do note this fails for versioned exact matches. "zlib>1" will not take the faster route because alpm_db_get_pkgfromcache() does not work for versioned deps. I do have a solution for this in an alternative patch which adds alpm_db_find_local_satisfier() "62 insertions(+), 7 deletions(-)" But is that worth it just for a speed up on -T? Nowhere else really makes extensive use of searching the localdb. --- src/pacman/deptest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 597eee42..76bf223e 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -32,11 +32,13 @@ int pacman_deptest(alpm_list_t *targets) alpm_list_t *i; alpm_list_t *deps = NULL; alpm_db_t *localdb = alpm_get_localdb(config->handle); + alpm_list_t *pkgcache = alpm_db_get_pkgcache(localdb); for(i = targets; i; i = alpm_list_next(i)) { char *target = i->data; - if(!alpm_find_satisfier(alpm_db_get_pkgcache(localdb), target)) { + if(!alpm_db_get_pkg(localdb, target) && + !alpm_find_satisfier(pkgcache, target)) { deps = alpm_list_add(deps, target); } } -- 2.23.0
On 9/9/19 7:45 am, morganamilo wrote:
Try and find an exact match via pkgcache before iterating the entire localdb.
Gives a noticeable speed up for exact matches e.g. `pacman -T zlib`
Thanks. Applied.
---
Do note this fails for versioned exact matches. "zlib>1" will not take the faster route because alpm_db_get_pkgfromcache() does not work for versioned deps.
I do have a solution for this in an alternative patch which adds alpm_db_find_local_satisfier() "62 insertions(+), 7 deletions(-)"
But is that worth it just for a speed up on -T? Nowhere else really makes extensive use of searching the localdb.
Probably not worth the extra complexity given current usage of -T is normally followed by a lot of compiling...
--- src/pacman/deptest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 597eee42..76bf223e 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -32,11 +32,13 @@ int pacman_deptest(alpm_list_t *targets) alpm_list_t *i; alpm_list_t *deps = NULL; alpm_db_t *localdb = alpm_get_localdb(config->handle); + alpm_list_t *pkgcache = alpm_db_get_pkgcache(localdb);
for(i = targets; i; i = alpm_list_next(i)) { char *target = i->data;
- if(!alpm_find_satisfier(alpm_db_get_pkgcache(localdb), target)) { + if(!alpm_db_get_pkg(localdb, target) && + !alpm_find_satisfier(pkgcache, target)) { deps = alpm_list_add(deps, target); } }
On 9/9/19 7:45 am, morganamilo wrote:
--- lib/libalpm/deps.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
Changes look fine. A
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 71185c68..ce7869c3 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -643,10 +643,9 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit) * @param dep is the dependency to search for * @param dbs are the databases to search * @param excluding are the packages to exclude from the search - * @param prompt if true, will cause an unresolvable dependency to issue an - * interactive prompt asking whether the package should be removed from - * the transaction or the transaction aborted; if false, simply returns - * an error code without prompting + * @param prompt if true, ask an alpm_question_install_ignorepkg_t to decide + * if ignored packages should be installed; if false, skip ignored + * packages. * @return the resolved package **/ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, @@ -766,8 +765,11 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
/** Find a package satisfying a specified dependency. * First look for a literal, going through each db one by one. Then look for - * providers. The first satisfier found is returned. + * providers. The first satisfier that belongs to an installed package is + * returned. If no providers belong to an installed package then an + * alpm_question_select_provider_t is created to select the provider. * The dependency can include versions with depmod operators. + * * @param handle the context handle * @param dbs an alpm_list_t* of alpm_db_t where the satisfier will be searched * @param depstring package or provision name, versioned or not
participants (3)
-
Allan McRae
-
Andrew Gregory
-
morganamilo