pactree: carry a list of databases for dep resolution

Declare an alpm_list which, for now, only holds our local database.
walk_deps and walk_reverse_deps are refactored to account for this, and
a helper function is added to wrap alpm_db_get_pkg for traversing a
list.

This is groundwork for letting pactree walk the sync DBs.

Signed-off-by: Dave Reisner <d@falconindy.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-06-21 13:42:17 -04:00 committed by Dan McGee
parent 61cb8e76c3
commit e06586ceb4
1 changed files with 25 additions and 12 deletions

View File

@ -75,7 +75,6 @@ static struct color_choices no_color = {
/* globals */ /* globals */
pmhandle_t *handle = NULL; pmhandle_t *handle = NULL;
pmdb_t *db_local;
alpm_list_t *walked = NULL; alpm_list_t *walked = NULL;
alpm_list_t *provisions = NULL; alpm_list_t *provisions = NULL;
@ -241,15 +240,27 @@ static void print_end(void)
} }
} }
static pmpkg_t *get_pkg_from_dbs(alpm_list_t *dbs, const char *needle) {
alpm_list_t *i;
pmpkg_t *ret;
for(i = dbs; i; i = alpm_list_next(i)) {
ret = alpm_db_get_pkg(alpm_list_getdata(i), needle);
if(ret) {
return ret;
}
}
return NULL;
}
/** /**
* walk dependencies in reverse, showing packages which require the target * walk dependencies in reverse, showing packages which require the target
*/ */
static void walk_reverse_deps(pmpkg_t *pkg, int depth) static void walk_reverse_deps(alpm_list_t *dblist, pmpkg_t *pkg, int depth)
{ {
alpm_list_t *required_by, *i; alpm_list_t *required_by, *i;
if((max_depth >= 0) && (depth == max_depth + 1)) { if(!pkg || ((max_depth >= 0) && (depth == max_depth + 1))) {
return; return;
} }
@ -267,7 +278,7 @@ static void walk_reverse_deps(pmpkg_t *pkg, int depth)
} }
} else { } else {
print(alpm_pkg_get_name(pkg), pkgname, NULL, depth); print(alpm_pkg_get_name(pkg), pkgname, NULL, depth);
walk_reverse_deps(alpm_db_get_pkg(db_local, pkgname), depth + 1); walk_reverse_deps(dblist, get_pkg_from_dbs(dblist, pkgname), depth + 1);
} }
} }
@ -277,7 +288,7 @@ static void walk_reverse_deps(pmpkg_t *pkg, int depth)
/** /**
* walk dependencies, showing dependencies of the target * walk dependencies, showing dependencies of the target
*/ */
static void walk_deps(pmpkg_t *pkg, int depth) static void walk_deps(alpm_list_t *dblist, pmpkg_t *pkg, int depth)
{ {
alpm_list_t *i; alpm_list_t *i;
@ -289,8 +300,7 @@ static void walk_deps(pmpkg_t *pkg, int depth)
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) { for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
pmdepend_t *depend = alpm_list_getdata(i); pmdepend_t *depend = alpm_list_getdata(i);
pmpkg_t *provider = alpm_find_satisfier(alpm_db_get_pkgcache(db_local), pmpkg_t *provider = alpm_find_dbs_satisfier(handle, dblist, depend->name);
depend->name);
if(provider) { if(provider) {
const char *provname = alpm_pkg_get_name(provider); const char *provname = alpm_pkg_get_name(provider);
@ -303,7 +313,7 @@ static void walk_deps(pmpkg_t *pkg, int depth)
} }
} else { } else {
print(alpm_pkg_get_name(pkg), provname, depend->name, depth); print(alpm_pkg_get_name(pkg), provname, depend->name, depth);
walk_deps(provider, depth + 1); walk_deps(dblist, provider, depth + 1);
} }
} else { } else {
/* unresolvable package */ /* unresolvable package */
@ -318,6 +328,7 @@ int main(int argc, char *argv[])
enum _pmerrno_t err; enum _pmerrno_t err;
const char *target_name; const char *target_name;
pmpkg_t *pkg; pmpkg_t *pkg;
alpm_list_t *dblist = NULL;
if(parse_options(argc, argv) != 0) { if(parse_options(argc, argv) != 0) {
usage(); usage();
@ -333,12 +344,12 @@ int main(int argc, char *argv[])
goto finish; goto finish;
} }
db_local = alpm_option_get_localdb(handle); dblist = alpm_list_add(dblist, alpm_option_get_localdb(handle));
/* we only care about the first non option arg for walking */ /* we only care about the first non option arg for walking */
target_name = argv[optind]; target_name = argv[optind];
pkg = alpm_find_satisfier(alpm_db_get_pkgcache(db_local), target_name); pkg = alpm_find_dbs_satisfier(handle, dblist, target_name);
if(!pkg) { if(!pkg) {
fprintf(stderr, "error: package '%s' not found\n", target_name); fprintf(stderr, "error: package '%s' not found\n", target_name);
ret = 1; ret = 1;
@ -348,13 +359,15 @@ int main(int argc, char *argv[])
print_start(alpm_pkg_get_name(pkg), target_name); print_start(alpm_pkg_get_name(pkg), target_name);
if(reverse) { if(reverse) {
walk_reverse_deps(pkg, 1); walk_reverse_deps(dblist, pkg, 1);
} else { } else {
walk_deps(pkg, 1); walk_deps(dblist, pkg, 1);
} }
print_end(); print_end();
alpm_list_free(dblist);
finish: finish:
cleanup(); cleanup();
return ret; return ret;