[pacman-dev] [PATCH] Make alpm_pkg_find public
This function is particularly useful, so make it public. Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/add.c | 2 +- lib/libalpm/alpm.h | 7 +++++++ lib/libalpm/deps.c | 12 ++++++------ lib/libalpm/package.c | 2 +- lib/libalpm/package.h | 1 - lib/libalpm/remove.c | 10 +++++----- lib/libalpm/sync.c | 20 ++++++++++---------- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index edddc31..ecdccff 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -67,7 +67,7 @@ int SYMEXPORT alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg) _alpm_log(handle, ALPM_LOG_DEBUG, "adding package '%s'\n", pkgname); - if(_alpm_pkg_find(trans->add, pkgname)) { + if(alpm_pkg_find(trans->add, pkgname)) { RET_ERR(handle, ALPM_ERR_TRANS_DUP_TARGET, -1); } diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 5b4eb6d..e3808d3 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -698,6 +698,13 @@ alpm_list_t *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles); int alpm_pkg_load(alpm_handle_t *handle, const char *filename, int full, alpm_siglevel_t level, alpm_pkg_t **pkg); +/** Find a package in a list by name. + * @param haystack a list of alpm_pkg_t + * @param needle the package name + * @return a pointer to the package if found or NULL + */ +alpm_pkg_t *alpm_pkg_find(alpm_list_t *haystack, const char *needle); + /** Free a package. * @param pkg package pointer to free * @return 0 on success, -1 on error (pm_errno is set accordingly) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 2a06bb0..27656bc 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -281,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_handle_t *handle, for(i = pkglist; i; i = i->next) { alpm_pkg_t *pkg = i->data; - if(_alpm_pkg_find(rem, pkg->name) || _alpm_pkg_find(upgrade, pkg->name)) { + if(alpm_pkg_find(rem, pkg->name) || alpm_pkg_find(upgrade, pkg->name)) { modified = alpm_list_add(modified, pkg); } else { dblist = alpm_list_add(dblist, pkg); @@ -495,7 +495,7 @@ static int can_remove_package(alpm_db_t *db, alpm_pkg_t *pkg, { alpm_list_t *i; - if(_alpm_pkg_find(targets, pkg->name)) { + if(alpm_pkg_find(targets, pkg->name)) { return 0; } @@ -517,7 +517,7 @@ static int can_remove_package(alpm_db_t *db, alpm_pkg_t *pkg, /* see if other packages need it */ for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { alpm_pkg_t *lpkg = i->data; - if(_alpm_dep_edge(lpkg, pkg) && !_alpm_pkg_find(targets, lpkg->name)) { + if(_alpm_dep_edge(lpkg, pkg) && !alpm_pkg_find(targets, lpkg->name)) { return 0; } } @@ -591,7 +591,7 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, for(i = dbs; i; i = i->next) { alpm_pkg_t *pkg = _alpm_db_get_pkgfromcache(i->data, dep->name); if(pkg && _alpm_depcmp_literal(pkg, dep) - && !_alpm_pkg_find(excluding, pkg->name)) { + && !alpm_pkg_find(excluding, pkg->name)) { if(_alpm_pkg_should_ignore(handle, pkg)) { int install = 0; if(prompt) { @@ -616,7 +616,7 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep, /* with hash != hash, we can even skip the strcmp() as we know they can't * possibly be the same string */ if(pkg->name_hash != dep->name_hash && _alpm_depcmp(pkg, dep) - && !_alpm_pkg_find(excluding, pkg->name)) { + && !alpm_pkg_find(excluding, pkg->name)) { if(_alpm_pkg_should_ignore(handle, pkg)) { int install = 0; if(prompt) { @@ -730,7 +730,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs, alpm_list_t *deps = NULL; alpm_list_t *packages_copy; - if(_alpm_pkg_find(*packages, pkg->name) != NULL) { + if(alpm_pkg_find(*packages, pkg->name) != NULL) { return 0; } diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index f3e0b7f..853771f 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -685,7 +685,7 @@ int _alpm_pkg_cmp(const void *p1, const void *p2) /* Test for existence of a package in a alpm_list_t* * of alpm_pkg_t* */ -alpm_pkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle) +alpm_pkg_t SYMEXPORT *alpm_pkg_find(alpm_list_t *haystack, const char *needle) { alpm_list_t *lp; unsigned long needle_hash; diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 313fe9d..a915bc3 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -140,7 +140,6 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle, int _alpm_pkg_cmp(const void *p1, const void *p2); int _alpm_pkg_compare_versions(alpm_pkg_t *local_pkg, alpm_pkg_t *pkg); -alpm_pkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle); int _alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg); #endif /* _ALPM_PACKAGE_H */ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 80c847e..d1020a6 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -68,7 +68,7 @@ int SYMEXPORT alpm_remove_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg) pkgname = pkg->name; - if(_alpm_pkg_find(trans->remove, pkgname)) { + if(alpm_pkg_find(trans->remove, pkgname)) { RET_ERR(handle, ALPM_ERR_TRANS_DUP_TARGET, -1); } @@ -100,7 +100,7 @@ static int remove_prepare_cascade(alpm_handle_t *handle, alpm_list_t *lp) alpm_pkg_t *info = _alpm_db_get_pkgfromcache(handle->db_local, miss->target); if(info) { alpm_pkg_t *copy; - if(!_alpm_pkg_find(trans->remove, info->name)) { + if(!alpm_pkg_find(trans->remove, info->name)) { _alpm_log(handle, ALPM_LOG_DEBUG, "pulling %s in target list\n", info->name); if(_alpm_pkg_dup(info, ©) == -1) { @@ -137,7 +137,7 @@ static void remove_prepare_keep_needed(alpm_handle_t *handle, alpm_list_t *lp) for(i = lp; i; i = i->next) { alpm_depmissing_t *miss = i->data; void *vpkg; - alpm_pkg_t *pkg = _alpm_pkg_find(trans->remove, miss->causingpkg); + alpm_pkg_t *pkg = alpm_pkg_find(trans->remove, miss->causingpkg); if(pkg == NULL) { continue; } @@ -171,11 +171,11 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t * alpm_pkg_t *pkg = i->data; alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg); - if(optdeps && !_alpm_pkg_find(lp, pkg->name)) { + if(optdeps && !alpm_pkg_find(lp, pkg->name)) { alpm_list_t *j; for(j = optdeps; j; j = alpm_list_next(j)) { alpm_depend_t *optdep = j->data; - if(_alpm_pkg_find(lp, optdep->name)) { + if(alpm_pkg_find(lp, optdep->name)) { EVENT(handle, ALPM_EVENT_OPTDEP_REQUIRED, pkg, optdep); } } diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index ca6b507..841e5d6 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -159,7 +159,7 @@ static alpm_list_t *check_replacers(alpm_handle_t *handle, alpm_pkg_t *lpkg, /* If spkg is already in the target list, we append lpkg to spkg's * removes list */ - tpkg = _alpm_pkg_find(handle->trans->add, spkg->name); + tpkg = alpm_pkg_find(handle->trans->add, spkg->name); if(tpkg) { /* sanity check, multiple repos can contain spkg->name */ if(tpkg->origin_data.db != sdb) { @@ -204,7 +204,7 @@ int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade) for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) { alpm_pkg_t *lpkg = i->data; - if(_alpm_pkg_find(trans->add, lpkg->name)) { + if(alpm_pkg_find(trans->add, lpkg->name)) { _alpm_log(handle, ALPM_LOG_DEBUG, "%s is already in the target list -- skipping\n", lpkg->name); continue; } @@ -257,7 +257,7 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs, for(j = grp->packages; j; j = j->next) { alpm_pkg_t *pkg = j->data; - if(_alpm_pkg_find(ignorelist, pkg->name)) { + if(alpm_pkg_find(ignorelist, pkg->name)) { continue; } if(_alpm_pkg_should_ignore(db->handle, pkg)) { @@ -268,7 +268,7 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs, if(!install) continue; } - if(!_alpm_pkg_find(pkgs, pkg->name)) { + if(!alpm_pkg_find(pkgs, pkg->name)) { pkgs = alpm_list_add(pkgs, pkg); } } @@ -448,7 +448,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) /* Set DEPEND reason for pulled packages */ for(i = resolved; i; i = i->next) { alpm_pkg_t *pkg = i->data; - if(!_alpm_pkg_find(trans->add, pkg->name)) { + if(!alpm_pkg_find(trans->add, pkg->name)) { pkg->reason = ALPM_PKG_REASON_DEPEND; } } @@ -482,8 +482,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_pkg_t *rsync, *sync, *sync1, *sync2; /* have we already removed one of the conflicting targets? */ - sync1 = _alpm_pkg_find(trans->add, conflict->package1); - sync2 = _alpm_pkg_find(trans->add, conflict->package2); + sync1 = alpm_pkg_find(trans->add, conflict->package1); + sync2 = alpm_pkg_find(trans->add, conflict->package2); if(!sync1 || !sync2) { continue; } @@ -545,7 +545,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) int found = 0; for(j = trans->add; j && !found; j = j->next) { alpm_pkg_t *spkg = j->data; - if(_alpm_pkg_find(spkg->removes, conflict->package2)) { + if(alpm_pkg_find(spkg->removes, conflict->package2)) { found = 1; } } @@ -556,7 +556,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) _alpm_log(handle, ALPM_LOG_DEBUG, "package '%s' conflicts with '%s'\n", conflict->package1, conflict->package2); - alpm_pkg_t *sync = _alpm_pkg_find(trans->add, conflict->package1); + alpm_pkg_t *sync = alpm_pkg_find(trans->add, conflict->package1); alpm_pkg_t *local = _alpm_db_get_pkgfromcache(handle->db_local, conflict->package2); int doremove = 0; QUESTION(handle, ALPM_QUESTION_CONFLICT_PKG, conflict->package1, @@ -590,7 +590,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data) alpm_pkg_t *spkg = i->data; for(j = spkg->removes; j; j = j->next) { alpm_pkg_t *rpkg = j->data; - if(!_alpm_pkg_find(trans->remove, rpkg->name)) { + if(!alpm_pkg_find(trans->remove, rpkg->name)) { alpm_pkg_t *copy; _alpm_log(handle, ALPM_LOG_DEBUG, "adding '%s' to remove list\n", rpkg->name); if(_alpm_pkg_dup(rpkg, ©) == -1) { -- 1.7.11.4
When a packages (new) optdepends are printed in install (update), add a note of their current installation status. Packages currently installed are labelled with [installed] and packages to be installed in this transaction are labelled [pending]. Signed-off-by: Allan McRae <allan@archlinux.org> --- I went a different way to previous patches that altered this. They all did not display installed optdependencies, but I prefer showing them by default. Later there may be an option added to install all optdepends by default and in that case the output can be removed. Example output:
sudo ./src/pacman/pacman -S git perl-term-readkey Password: resolving dependencies... looking for inter-conflicts...
Packages (2): git-1.7.11.4-1 perl-term-readkey-2.30.02-2 Total Installed Size: 16.79 MiB Proceed with installation? [Y/n] (2/2) checking package integrity [######################] 100% (2/2) loading package files [######################] 100% (2/2) checking for file conflicts [######################] 100% (1/2) installing git [######################] 100% Optional dependencies for git tk: gitk and git gui [installed] perl-libwww: git svn perl-term-readkey: git svn [pending] perl-mime-tools: git send-email perl-net-smtp-ssl: git send-email TLS support perl-authen-sasl: git send-email TLS support python2: various helper scripts [installed] subversion: git svn [installed] cvsps: git cvsimport (2/2) installing perl-term-readkey [######################] 100% src/pacman/util.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 995308c..4d8727f 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1192,6 +1192,22 @@ static int depend_cmp(const void *d1, const void *d2) return ret; } +static char *make_optstring(alpm_depend_t *optdep) +{ + char *optstring = alpm_dep_compute_string(optdep); + char *status = NULL; + if(alpm_db_get_pkg(alpm_get_localdb(config->handle), optdep->name)) { + status = _(" [installed]"); + } else if(alpm_pkg_find(alpm_trans_get_add(config->handle), optdep->name)) { + status = _(" [pending]"); + } + if(status) { + optstring = realloc(optstring, strlen(optstring) + strlen(status) + 1); + strcpy(optstring + strlen(optstring), status); + } + return optstring; +} + void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) { alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL; @@ -1203,7 +1219,7 @@ void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) /* turn optdepends list into a text list */ for(i = optdeps; i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; - optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep)); + optstrings = alpm_list_add(optstrings, make_optstring(optdep)); } if(optstrings) { @@ -1225,7 +1241,7 @@ void display_optdepends(alpm_pkg_t *pkg) /* turn optdepends list into a text list */ for(i = optdeps; i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; - optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep)); + optstrings = alpm_list_add(optstrings, make_optstring(optdep)); } if(optstrings) { -- 1.7.11.4
Hi, I would prefer to see [install] and [pending] in front of the package name and description, not after it, i.e. [installed] tk: gitk and git gui perl-libwww: git svn [pending] perl-term-readkey: git svn perl-mime-tools: git send-email perl-net-smtp-ssl: git send-email TLS support maybe even like this: [installed] tk: gitk and git gui perl-libwww: git svn [pending] perl-term-readkey: git svn perl-mime-tools: git send-email perl-net-smtp-ssl: git send-email TLS support Best, Arokux On Sun, Aug 12, 2012 at 1:11 PM, Allan McRae <allan@archlinux.org> wrote:
When a packages (new) optdepends are printed in install (update), add a note of their current installation status. Packages currently installed are labelled with [installed] and packages to be installed in this transaction are labelled [pending].
Signed-off-by: Allan McRae <allan@archlinux.org> ---
I went a different way to previous patches that altered this. They all did not display installed optdependencies, but I prefer showing them by default. Later there may be an option added to install all optdepends by default and in that case the output can be removed.
Example output:
sudo ./src/pacman/pacman -S git perl-term-readkey Password: resolving dependencies... looking for inter-conflicts...
Packages (2): git-1.7.11.4-1 perl-term-readkey-2.30.02-2
Total Installed Size: 16.79 MiB
Proceed with installation? [Y/n] (2/2) checking package integrity [######################] 100% (2/2) loading package files [######################] 100% (2/2) checking for file conflicts [######################] 100% (1/2) installing git [######################] 100% Optional dependencies for git tk: gitk and git gui [installed] perl-libwww: git svn perl-term-readkey: git svn [pending] perl-mime-tools: git send-email perl-net-smtp-ssl: git send-email TLS support perl-authen-sasl: git send-email TLS support python2: various helper scripts [installed] subversion: git svn [installed] cvsps: git cvsimport (2/2) installing perl-term-readkey [######################] 100%
src/pacman/util.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 995308c..4d8727f 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1192,6 +1192,22 @@ static int depend_cmp(const void *d1, const void *d2) return ret; }
+static char *make_optstring(alpm_depend_t *optdep) +{ + char *optstring = alpm_dep_compute_string(optdep); + char *status = NULL; + if(alpm_db_get_pkg(alpm_get_localdb(config->handle), optdep->name)) { + status = _(" [installed]"); + } else if(alpm_pkg_find(alpm_trans_get_add(config->handle), optdep->name)) { + status = _(" [pending]"); + } + if(status) { + optstring = realloc(optstring, strlen(optstring) + strlen(status) + 1); + strcpy(optstring + strlen(optstring), status); + } + return optstring; +} + void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) { alpm_list_t *i, *old, *new, *optdeps, *optstrings = NULL; @@ -1203,7 +1219,7 @@ void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg) /* turn optdepends list into a text list */ for(i = optdeps; i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; - optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep)); + optstrings = alpm_list_add(optstrings, make_optstring(optdep)); }
if(optstrings) { @@ -1225,7 +1241,7 @@ void display_optdepends(alpm_pkg_t *pkg) /* turn optdepends list into a text list */ for(i = optdeps; i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; - optstrings = alpm_list_add(optstrings, alpm_dep_compute_string(optdep)); + optstrings = alpm_list_add(optstrings, make_optstring(optdep)); }
if(optstrings) { -- 1.7.11.4
participants (2)
-
Allan McRae
-
Arokux B.