xbps-query(8): added --fulldeptree to print a full dependency tree with -x.

This fixes the regression introduced in 0.37 with -xx; -xx is not supported
anymore, use `--fulldeptree -x`.
This commit is contained in:
Juan RP
2014-08-19 13:14:37 +02:00
parent 4257f0b914
commit d7c7783ac2
5 changed files with 171 additions and 100 deletions

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2013 Juan Romero Pardines.
* Copyright (c) 2009-2014 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -32,74 +32,159 @@
#include <xbps.h>
#include "defs.h"
#include "queue.h"
struct pkgdep {
SLIST_ENTRY(pkgdep) pkgdep_entries;
const char *pkg;
xbps_array_t rdeps;
};
static SLIST_HEAD(pkgdep_head, pkgdep) pkgdep_list =
SLIST_HEAD_INITIALIZER(pkgdep_list);
static void
print_rdeps(struct xbps_handle *xhp, xbps_array_t rdeps,
bool full, bool repo, bool origin, int *indent)
print_rdeps(struct xbps_handle *xhp, xbps_array_t rdeps, bool full, bool repo)
{
xbps_array_t currdeps;
xbps_dictionary_t pkgd;
const char *pkgdep;
if (!origin)
(*indent)++;
const char *curdep;
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
xbps_array_get_cstring_nocopy(rdeps, i, &pkgdep);
if (!origin || !full)
for (int j = 0; j < *indent; j++)
putchar(' ');
struct pkgdep *pd;
const char *pkgver;
char *vpkg;
bool virtual = false, found = false;
printf("%s\n", pkgdep);
if (!full)
xbps_array_get_cstring_nocopy(rdeps, i, &curdep);
if (!full) {
printf("%s\n", curdep);
continue;
if (repo) {
pkgd = xbps_rpool_get_pkg(xhp, pkgdep);
if (pkgd == NULL)
pkgd = xbps_rpool_get_virtualpkg(xhp, pkgdep);
} else {
pkgd = xbps_pkgdb_get_pkg(xhp, pkgdep);
if (pkgd == NULL)
pkgd = xbps_pkgdb_get_virtualpkg(xhp, pkgdep);
}
if (pkgd != NULL) {
currdeps = xbps_dictionary_get(pkgd, "run_depends");
if (currdeps != NULL)
print_rdeps(xhp, currdeps,
full, repo, false, indent);
if (repo) {
if ((pkgd = xbps_rpool_get_pkg(xhp, curdep)) == NULL)
pkgd = xbps_rpool_get_virtualpkg(xhp, curdep);
} else {
if ((pkgd = xbps_pkgdb_get_pkg(xhp, curdep)) == NULL) {
pkgd = xbps_pkgdb_get_virtualpkg(xhp, curdep);
virtual = true;
}
}
assert(pkgd);
currdeps = xbps_dictionary_get(pkgd, "run_depends");
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
assert(pkgver);
if (virtual) {
char *p;
if ((p = xbps_pkgpattern_name(curdep)) == NULL)
p = xbps_pkg_name(curdep);
assert(p);
vpkg = xbps_xasprintf("%s-0.1_1", p);
assert(vpkg);
free(p);
}
/* uniquify dependencies, sorting will be done later */
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
if (virtual && strcmp(pd->pkg, vpkg) == 0) {
found = true;
break;
} else if (strcmp(pd->pkg, pkgver) == 0) {
found = true;
break;
}
}
if (!found) {
pd = malloc(sizeof(*pd));
assert(pd);
if (virtual)
pd->pkg = vpkg;
else
pd->pkg = pkgver;
pd->rdeps = xbps_array_copy(currdeps);
SLIST_INSERT_HEAD(&pkgdep_list, pd, pkgdep_entries);
}
if (xbps_array_count(currdeps))
print_rdeps(xhp, currdeps, full, repo);
}
}
static xbps_array_t
sort_rdeps(void)
{
struct pkgdep *pd;
xbps_array_t result;
unsigned int ndeps = 0;
result = xbps_array_create();
assert(result);
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
if (!pd->rdeps) {
xbps_array_add_cstring_nocopy(result, pd->pkg);
SLIST_REMOVE(&pkgdep_list, pd, pkgdep, pkgdep_entries);
}
ndeps++;
}
while (xbps_array_count(result) < ndeps) {
bool found = false;
SLIST_FOREACH(pd, &pkgdep_list, pkgdep_entries) {
unsigned int i = 0, mdeps = 0, rdeps = 0;
rdeps = xbps_array_count(pd->rdeps);
for (i = 0; i < rdeps; i++) {
const char *pkgdep;
char *pkgname;
xbps_array_get_cstring_nocopy(pd->rdeps, i, &pkgdep);
pkgname = xbps_pkgpattern_name(pkgdep);
if (pkgname == NULL)
pkgname = xbps_pkg_name(pkgdep);
if (xbps_match_pkgname_in_array(result, pkgname))
mdeps++;
free(pkgname);
}
if (mdeps == rdeps) {
found = true;
break;
}
//printf("%s ndeps: %u result: %u rdeps: %u mdeps: %u\n", pd->pkg, ndeps, xbps_array_count(result), rdeps, mdeps);
}
if (found && !xbps_match_string_in_array(result, pd->pkg)) {
xbps_array_add_cstring_nocopy(result, pd->pkg);
SLIST_REMOVE(&pkgdep_list, pd, pkgdep, pkgdep_entries);
}
}
(*indent)--;
return result;
}
int
show_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool full)
show_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool repomode, bool full)
{
xbps_array_t rdeps;
xbps_array_t rdeps, res;
xbps_dictionary_t pkgd;
int indent = 0;
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
if (pkgd == NULL)
return ENOENT;
if (repomode) {
if (((pkgd = xbps_rpool_get_pkg(xhp, pkgname)) == NULL) &&
((pkgd = xbps_rpool_get_virtualpkg(xhp, pkgname)) == NULL))
return errno;
} else {
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL)
return ENOENT;
}
if ((rdeps = xbps_dictionary_get(pkgd, "run_depends")))
print_rdeps(xhp, rdeps, full, repomode);
if (full) {
res = sort_rdeps();
for (unsigned int i = 0; i < xbps_array_count(res); i++) {
const char *pkgdep;
rdeps = xbps_dictionary_get(pkgd, "run_depends");
if (rdeps != NULL)
print_rdeps(xhp, rdeps, full, false, true, &indent);
return 0;
}
int
show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
{
xbps_array_t reqby;
const char *pkgdep;
if ((reqby = xbps_pkgdb_get_pkg_revdeps(xhp, pkg)) != NULL) {
for (unsigned int i = 0; i < xbps_array_count(reqby); i++) {
xbps_array_get_cstring_nocopy(reqby, i, &pkgdep);
xbps_array_get_cstring_nocopy(res, i, &pkgdep);
printf("%s\n", pkgdep);
}
}
@@ -107,37 +192,22 @@ show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
}
int
repo_show_pkg_deps(struct xbps_handle *xhp, const char *pattern, bool full)
{
xbps_array_t rdeps;
xbps_dictionary_t pkgd;
int indent = 0;
if (((pkgd = xbps_rpool_get_pkg(xhp, pattern)) == NULL) &&
((pkgd = xbps_rpool_get_virtualpkg(xhp, pattern)) == NULL))
return errno;
rdeps = xbps_dictionary_get(pkgd, "run_depends");
if (rdeps != NULL)
print_rdeps(xhp, rdeps, full, true, true, &indent);
return 0;
}
int
repo_show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg, bool repomode)
{
xbps_array_t revdeps;
const char *pkgver;
int rv;
const char *pkgdep;
revdeps = xbps_rpool_get_pkg_revdeps(xhp, pkg);
rv = errno;
if (repomode)
revdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkg);
else
revdeps = xbps_rpool_get_pkg_revdeps(xhp, pkg);
if (revdeps == NULL)
return ENOENT;
for (unsigned int i = 0; i < xbps_array_count(revdeps); i++) {
xbps_array_get_cstring_nocopy(revdeps, i, &pkgver);
printf("%s\n", pkgver);
xbps_array_get_cstring_nocopy(revdeps, i, &pkgdep);
printf("%s\n", pkgdep);
}
return rv;
return 0;
}