On Mon, Jul 2, 2012 at 5:02 PM, <[email protected]> wrote:
> From: Andrew Gregory <[email protected]>
>
> Showing vertical limbs makes the tree easier to follow.
>
> Old: New:
> |--pkg |--pkg
> |--dep1 |--dep1
> |--dep2 | |--dep2
> |--dep3 |--dep3
>
> Signed-off-by: Andrew Gregory <[email protected]>
> ---
> src/util/pactree.c | 105
> ++++++++++++++++++++++++++++++++++++++++++-----------
> 1 file changed, 83 insertions(+), 22 deletions(-)
>
> diff --git a/src/util/pactree.c b/src/util/pactree.c
> index aa02c80..2fafd6d 100644
> --- a/src/util/pactree.c
> +++ b/src/util/pactree.c
> @@ -397,7 +419,24 @@ static void walk_reverse_deps(alpm_list_t *dblist,
> alpm_pkg_t *pkg, int depth)
> }
> } else {
> print(alpm_pkg_get_name(pkg), pkgname, NULL, depth);
> - walk_reverse_deps(dblist, get_pkg_from_dbs(dblist,
> pkgname), depth + 1);
> + tdepth d = {
> + depth,
> + NULL,
> + depth->level + 1
> + };
> + depth->next = &d;
> + /* last dep, cut off the limb here */
> + if(!alpm_list_next(i)){
> + if(depth->prev){
> + depth->prev->next = &d;
> + d.prev = depth->prev;
> + depth = &d;
> + } else {
> + d.prev = NULL;
> + }
> + }
> + walk_reverse_deps(dblist, get_pkg_from_dbs(dblist,
> pkgname), &d);
> + depth->next = NULL;
> }
> }
>
> @@ -432,7 +471,24 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t
> *pkg, int depth)
> }
> } else {
> print(alpm_pkg_get_name(pkg), provname,
> depend->name, depth);
> - walk_deps(dblist, provider, depth + 1);
> + tdepth d = {
> + depth,
> + NULL,
> + depth->level + 1
> + };
> + depth->next = &d;
> + /* last dep, cut off the limb here */
> + if(!alpm_list_next(i)){
> + if(depth->prev){
> + depth->prev->next = &d;
> + d.prev = depth->prev;
> + depth = &d;
> + } else {
> + d.prev = NULL;
> + }
> + }
> + walk_deps(dblist, provider, &d);
> + depth->next = NULL;
> }
> } else {
> /* unresolvable package */
This screams "refactor into a common method" to me... and if not, I
need a good reason why from a quick glance this code is (or isn't)
exactly the same logic.
-Dan