summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2011-06-21 19:42:17 +0200
committerDan McGee <dan@archlinux.org>2011-06-24 20:37:09 +0200
commite06586ceb49a0dc7e59996ae3a1483337d2ada05 (patch)
tree39f47670caa36eb63860a8e7bd8c368dfe0e8119 /src
parent61cb8e76c3f42bad318462e51bbfade752425023 (diff)
downloadpacman-e06586ceb49a0dc7e59996ae3a1483337d2ada05.tar.gz
pacman-e06586ceb49a0dc7e59996ae3a1483337d2ada05.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/util/pactree.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 6b29d935..87bac6d1 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -75,7 +75,6 @@ static struct color_choices no_color = {
/* globals */
pmhandle_t *handle = NULL;
-pmdb_t *db_local;
alpm_list_t *walked = 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
*/
-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;
- if((max_depth >= 0) && (depth == max_depth + 1)) {
+ if(!pkg || ((max_depth >= 0) && (depth == max_depth + 1))) {
return;
}
@@ -267,7 +278,7 @@ static void walk_reverse_deps(pmpkg_t *pkg, int depth)
}
} else {
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
*/
-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;
@@ -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)) {
pmdepend_t *depend = alpm_list_getdata(i);
- pmpkg_t *provider = alpm_find_satisfier(alpm_db_get_pkgcache(db_local),
- depend->name);
+ pmpkg_t *provider = alpm_find_dbs_satisfier(handle, dblist, depend->name);
if(provider) {
const char *provname = alpm_pkg_get_name(provider);
@@ -303,7 +313,7 @@ static void walk_deps(pmpkg_t *pkg, int depth)
}
} else {
print(alpm_pkg_get_name(pkg), provname, depend->name, depth);
- walk_deps(provider, depth + 1);
+ walk_deps(dblist, provider, depth + 1);
}
} else {
/* unresolvable package */
@@ -318,6 +328,7 @@ int main(int argc, char *argv[])
enum _pmerrno_t err;
const char *target_name;
pmpkg_t *pkg;
+ alpm_list_t *dblist = NULL;
if(parse_options(argc, argv) != 0) {
usage();
@@ -333,12 +344,12 @@ int main(int argc, char *argv[])
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 */
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) {
fprintf(stderr, "error: package '%s' not found\n", target_name);
ret = 1;
@@ -348,13 +359,15 @@ int main(int argc, char *argv[])
print_start(alpm_pkg_get_name(pkg), target_name);
if(reverse) {
- walk_reverse_deps(pkg, 1);
+ walk_reverse_deps(dblist, pkg, 1);
} else {
- walk_deps(pkg, 1);
+ walk_deps(dblist, pkg, 1);
}
print_end();
+ alpm_list_free(dblist);
+
finish:
cleanup();
return ret;