[pacman-dev] [PATCH] pactree: show tree vertical "limbs"

Dan McGee dpmcgee at gmail.com
Mon Jul 2 18:37:58 EDT 2012


On Mon, Jul 2, 2012 at 5:02 PM,  <andrew.gregory.8 at gmail.com> wrote:
> From: Andrew Gregory <andrew.gregory.8 at gmail.com>
>
> Showing vertical limbs makes the tree easier to follow.
>
> Old:            New:
> |--pkg          |--pkg
>    |--dep1         |--dep1
>       |--dep2      |  |--dep2
>    |--dep3         |--dep3
>
> Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
> ---
>  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


More information about the pacman-dev mailing list