diff options
author | Dan McGee <dan@archlinux.org> | 2009-10-07 21:52:09 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-03-23 22:24:14 -0500 |
commit | cdbb90aceb288034dbf4f228fc4c49da1e2ed0c0 (patch) | |
tree | 4762094260856cb5ed34f72adbba8ae8eb90f513 | |
parent | ad4efa539de1e8e9e51baee82efeafde9fb24380 (diff) |
Show 'Required By' in -Sii output
Just as we do in -Qi, we can compute required by information for sync
database packages. The behavior seems sane; for a given package, the -Sii
required by will show all packages in *any* sync database that require it.
Implements FS#16244.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | lib/libalpm/package.c | 40 | ||||
-rw-r--r-- | src/pacman/package.c | 16 | ||||
-rw-r--r-- | src/pacman/package.h | 2 | ||||
-rw-r--r-- | src/pacman/sync.c | 6 |
4 files changed, 44 insertions, 20 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 742d0f59..f1682cbc 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -555,6 +555,21 @@ int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg) return pkg->scriptlet; } +static void find_requiredby(pmpkg_t *pkg, pmdb_t *db, alpm_list_t **reqs) +{ + const alpm_list_t *i; + for(i = _alpm_db_get_pkgcache(db); i; i = i->next) { + if(!i->data) { + continue; + } + pmpkg_t *cachepkg = i->data; + if(_alpm_dep_edge(cachepkg, pkg)) { + const char *cachepkgname = cachepkg->name; + *reqs = alpm_list_add(*reqs, strdup(cachepkgname)); + } + } +} + /** * @brief Compute the packages requiring a given package. * @param pkg a package @@ -564,16 +579,23 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg) { const alpm_list_t *i; alpm_list_t *reqs = NULL; + pmdb_t *db; - pmdb_t *localdb = alpm_option_get_localdb(); - for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) { - if(!i->data) { - continue; - } - pmpkg_t *cachepkg = i->data; - if(_alpm_dep_edge(cachepkg, pkg)) { - const char *cachepkgname = cachepkg->name; - reqs = alpm_list_add(reqs, strdup(cachepkgname)); + if(pkg->origin == PKG_FROM_FILE) { + /* The sane option; search locally for things that require this. */ + db = alpm_option_get_localdb(); + find_requiredby(pkg, db, &reqs); + } else { + /* We have a DB package. if it is a local package, then we should + * only search the local DB; else search all known sync databases. */ + db = pkg->origin_data.db; + if(db->is_local) { + find_requiredby(pkg, db, &reqs); + } else { + for(i = handle->dbs_sync; i; i = i->next) { + db = i->data; + find_requiredby(pkg, db, &reqs); + } } } return(reqs); diff --git a/src/pacman/package.c b/src/pacman/package.c index 060bd438..413754c7 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -38,7 +38,9 @@ /* Display the content of a package * - * level: <0 - sync package [-Si] + * levels: + * <-1 - sync package, extra information (required by) [-Sii] + * -1 - sync package, normal level [-Si] * =0 - file query [-Qip] * 1 - localdb query, normal level [-Qi] * >1 - localdb query, extra information (backup files) [-Qii] @@ -83,7 +85,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level) depstrings = alpm_list_add(depstrings, alpm_dep_compute_string(dep)); } - if(level>0) { + if(level > 0 || level < -1) { /* compute this here so we don't get a pause in the middle of output */ requiredby = alpm_pkg_compute_requiredby(pkg); } @@ -97,10 +99,8 @@ void dump_pkg_full(pmpkg_t *pkg, int level) list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); list_display(_("Depends On :"), depstrings); list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg)); - /* Only applicable if installed */ - if(level > 0) { + if(level > 0 || level < -1) { list_display(_("Required By :"), requiredby); - FREELIST(requiredby); } list_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); list_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); @@ -142,17 +142,19 @@ void dump_pkg_full(pmpkg_t *pkg, int level) printf("\n"); FREELIST(depstrings); + FREELIST(requiredby); } /* Display the content of a sync package */ -void dump_pkg_sync(pmpkg_t *pkg, const char *treename) +void dump_pkg_sync(pmpkg_t *pkg, const char *treename, int level) { if(pkg == NULL) { return; } string_display(_("Repository :"), treename); - dump_pkg_full(pkg, -1); + /* invert the level since we are a sync package */ + dump_pkg_full(pkg, -level); } /* Display list of backup files and their modification states diff --git a/src/pacman/package.h b/src/pacman/package.h index 5b0e02c9..006ea1c9 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -23,7 +23,7 @@ #include <alpm.h> void dump_pkg_full(pmpkg_t *pkg, int level); -void dump_pkg_sync(pmpkg_t *pkg, const char *treename); +void dump_pkg_sync(pmpkg_t *pkg, const char *treename, int level); void dump_pkg_backups(pmpkg_t *pkg); void dump_pkg_files(pmpkg_t *pkg, int quiet); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 3b4adaaa..1abb98fa 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -453,7 +453,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) pmpkg_t *pkg = alpm_list_getdata(k); if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) { - dump_pkg_sync(pkg, alpm_db_get_name(db)); + dump_pkg_sync(pkg, alpm_db_get_name(db), config->op_s_info); foundpkg = 1; break; } @@ -474,7 +474,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) pmpkg_t *pkg = alpm_list_getdata(k); if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) { - dump_pkg_sync(pkg, alpm_db_get_name(db)); + dump_pkg_sync(pkg, alpm_db_get_name(db), config->op_s_info); foundpkg = 1; break; } @@ -492,7 +492,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) pmdb_t *db = alpm_list_getdata(i); for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) { - dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db)); + dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db), config->op_s_info); } } } |