From 05d596b9bcad0e287be75dbba7f47b35d05f69cc Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 25 Jul 2011 01:22:04 -0500 Subject: [PATCH] pkg: implement maximum depth for pkg_traverse() --- main.c | 18 ++++++++++++++---- pkg.c | 8 ++++++-- pkg.h | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 8557835..ffdb110 100644 --- a/main.c +++ b/main.c @@ -32,6 +32,7 @@ static int want_version = 0; static int want_cflags = 0; static int want_libs = 0; static int want_modversion = 0; +static int maximum_traverse_depth = -1; static char *required_pkgconfig_version = NULL; @@ -83,6 +84,14 @@ pkg_queue_walk(pkg_queue_t *head) .realname = "virtual" }; + /* if maximum_traverse_depth is one, then we will not traverse deeper + * than our virtual package. + */ + if (!maximum_traverse_depth) + maximum_traverse_depth = -1; + else if (maximum_traverse_depth) + maximum_traverse_depth++; + foreach_list_entry(head, pkgq) { world.requires = parse_deplist(&world, pkgq->package); @@ -94,19 +103,19 @@ pkg_queue_walk(pkg_queue_t *head) want_cflags = 0; want_libs = 0; - pkg_traverse(&world, print_modversion, NULL); + pkg_traverse(&world, print_modversion, NULL, 1); } if (want_cflags) { wanted_something++; - pkg_traverse(&world, print_cflags, NULL); + pkg_traverse(&world, print_cflags, NULL, maximum_traverse_depth); } if (want_libs) { wanted_something++; - pkg_traverse(&world, print_libs, NULL); + pkg_traverse(&world, print_libs, NULL, maximum_traverse_depth); } if (wanted_something) @@ -138,6 +147,7 @@ main(int argc, const char *argv[]) { "exists", 0, POPT_ARG_NONE, NULL, 0, "return 0 if all packages present" }, { "print-errors", 0, POPT_ARG_NONE, NULL, 0, "dummy option for pkg-config compatibility" }, { "short-errors", 0, POPT_ARG_NONE, NULL, 0, "dummy option for pkg-config compatibility" }, + { "maximum-traverse-depth", 0, POPT_ARG_INT, &maximum_traverse_depth, 0, "limits maximum traversal depth of the computed dependency graph" }, POPT_AUTOHELP { NULL, 0, 0, NULL, 0 } }; @@ -151,7 +161,7 @@ main(int argc, const char *argv[]) poptStrerror(ret)); return EXIT_FAILURE; } - + if (want_version) { version(); diff --git a/pkg.c b/pkg.c index 391a09c..ccd238a 100644 --- a/pkg.c +++ b/pkg.c @@ -36,10 +36,14 @@ pkg_find(const char *name) void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), - void *data) + void *data, + int maxdepth) { pkg_dependency_t *node; + if (maxdepth == 0) + return; + foreach_list_entry(root->requires, node) { pkg_t *pkgdep; @@ -54,7 +58,7 @@ pkg_traverse(pkg_t *root, continue; } - pkg_traverse(pkgdep, pkg_traverse_func, data); + pkg_traverse(pkgdep, pkg_traverse_func, data, maxdepth - 1); } pkg_traverse_func(root, data); diff --git a/pkg.h b/pkg.h index 2132036..5118654 100644 --- a/pkg.h +++ b/pkg.h @@ -85,7 +85,7 @@ struct pkg_ { }; pkg_t *pkg_find(const char *name); -void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data); +void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth); /* parse.c */ pkg_t *parse_file(const char *path);