[pacman-dev] [PATCH] pactree: Add support for getting optional dependencies
Johannes Löthberg
johannes at kyriasis.com
Thu Feb 25 21:44:07 UTC 2016
Signed-off-by: Johannes Löthberg <johannes at kyriasis.com>
---
doc/pactree.8.txt | 3 +++
src/util/pactree.c | 41 ++++++++++++++++++++++++++++++++++++-----
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/doc/pactree.8.txt b/doc/pactree.8.txt
index b177788..4c391c0 100644
--- a/doc/pactree.8.txt
+++ b/doc/pactree.8.txt
@@ -49,6 +49,9 @@ Options
*-l, \--linear*::
Prints package names at the start of each line, one per line.
+*-o, \--optdeps*::
+ Show packages that are optionally depended upon by the named package.
+
*-r, \--reverse*::
Show packages that depend on the named package.
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 67be9f9..fb91b39 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -118,6 +118,7 @@ struct graph_style *style = &graph_utf8;
int graphviz = 0;
int max_depth = -1;
int reverse = 0;
+int optdeps = 0;
int unique = 0;
int searchsyncs = 0;
const char *dbpath = DBPATH;
@@ -182,6 +183,7 @@ static int parse_options(int argc, char *argv[])
{"help", no_argument, 0, 'h'},
{"linear", no_argument, 0, 'l'},
{"reverse", no_argument, 0, 'r'},
+ {"optdeps", no_argument, 0, 'o'},
{"sync", no_argument, 0, 's'},
{"unique", no_argument, 0, 'u'},
@@ -198,7 +200,7 @@ static int parse_options(int argc, char *argv[])
style = &graph_default;
#endif
- while((opt = getopt_long(argc, argv, "ab:cd:ghlrsu", opts, &option_index))) {
+ while((opt = getopt_long(argc, argv, "ab:cd:ghlorsu", opts, &option_index))) {
if(opt < 0) {
break;
}
@@ -236,6 +238,9 @@ static int parse_options(int argc, char *argv[])
case 's':
searchsyncs = 1;
break;
+ case 'o':
+ optdeps = 1;
+ break;
case 'u':
unique = 1;
style = &graph_linear;
@@ -266,6 +271,7 @@ static void usage(void)
" -g, --graph generate output for graphviz's dot\n"
" -h, --help display this help message\n"
" -l, --linear enable linear output\n"
+ " -o, --optdeps list packages that are optionally depended upon by the named package\n"
" -r, --reverse list packages that depend on the named package\n"
" -s, --sync search sync databases instead of local\n"
" -u, --unique show dependencies with no duplicates (implies -l)\n"
@@ -381,12 +387,29 @@ static alpm_list_t *get_pkg_dep_names(alpm_pkg_t *pkg)
return names;
}
+static alpm_list_t *get_pkg_optdep_names(alpm_pkg_t *pkg)
+{
+ alpm_list_t *i = NULL, *names = NULL;
+ for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
+ alpm_depend_t *d = i->data;
+ if(searchsyncs) {
+ names = alpm_list_add(names, d->name);
+ } else {
+ alpm_db_t *localdb = alpm_get_localdb(handle);
+ if(alpm_find_satisfier(alpm_db_get_pkgcache(localdb), d->name)) {
+ names = alpm_list_add(names, d->name);
+ }
+ }
+ }
+ return names;
+}
+
/**
* walk dependencies, showing dependencies of the target
*/
-static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev)
+static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev, int optdeps)
{
- alpm_list_t *deps, *i;
+ alpm_list_t *deps = NULL, *i = NULL;
if(!pkg || ((max_depth >= 0) && (depth->level > max_depth))) {
return;
@@ -396,8 +419,16 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r
if(rev) {
deps = alpm_pkg_compute_requiredby(pkg);
+ if(optdeps) {
+ alpm_list_t *odeps = alpm_pkg_compute_optionalfor(pkg);
+ deps = alpm_list_join(deps, odeps);
+ }
} else {
deps = get_pkg_dep_names(pkg);
+ if(optdeps) {
+ alpm_list_t *odeps = get_pkg_optdep_names(pkg);
+ deps = alpm_list_join(deps, odeps);
+ }
}
for(i = deps; i; i = alpm_list_next(i)) {
@@ -431,7 +462,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r
d.prev = NULL;
}
}
- walk_deps(dblist, dep_pkg, &d, rev);
+ walk_deps(dblist, dep_pkg, &d, rev, optdeps);
depth->next = NULL;
}
}
@@ -494,7 +525,7 @@ int main(int argc, char *argv[])
NULL,
1
};
- walk_deps(dblist, pkg, &d, reverse);
+ walk_deps(dblist, pkg, &d, reverse, optdeps);
print_end();
--
2.7.1
More information about the pacman-dev
mailing list