From patchwork Wed Jul 29 23:30:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Jakubiak X-Patchwork-Id: 1738 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 1B7D81A3A2605 for ; Wed, 29 Jul 2020 23:31:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_ADSP_CUSTOM_MED=0.001, DKIM_INVALID=1,DKIM_SIGNED=0.1,FREEMAIL_FROM=0.5,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_MSPIKE_H4=-0.01,RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001,T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-BL-Results: [127.0.9.2] [127.0.0.4] [127.0.0.19] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 29 Jul 2020 23:31:05 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id E18411D363C5FB; Wed, 29 Jul 2020 23:31:03 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id AD5501D363C5F7; Wed, 29 Jul 2020 23:31:03 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HXeyHYPo Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id A0F6A29CAC; Wed, 29 Jul 2020 23:31:03 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HXeyHYPo Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id C3A4229CAB for ; Wed, 29 Jul 2020 23:31:00 +0000 (UTC) Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by luna.archlinux.org (Postfix) with ESMTPS for ; Wed, 29 Jul 2020 23:31:00 +0000 (UTC) Received: by mail-ed1-x541.google.com with SMTP id v22so7847704edy.0 for ; Wed, 29 Jul 2020 16:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RdVNlNiXncF7aCR/c1wa19zzqVBT3HWRUwNOlypAMo8=; b=HXeyHYPoTOQc06LGYYXwlDbH/ry2ykteos0SfVWE+tnHYZPqF/aHuKwTUYLj3+A2jq aPCk7BlFMR4OBRm3OUcr8ZlojE5v4q+GOL1gOlO7kIl/+HvtqyKJaralH0whakhOmHSd lGj4SFhsUMfSFE5utt/OkBKsaKvv9NZnoREvzyy3eiSd82LH5u9ntTLn0eRN9zKryD4i d/iY92GoJgsybwzTgcITnO6CzGPEb55vP4NBr5/DVOSet2rs8gcjXSiwyhaHRhZOq48e JGqhyf9npv1KqF3XRPv9Fa5zvkv76lKZBqhHyJVZNx0AGySLBHsmcCbzDQqr6UrVKvI2 9m6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RdVNlNiXncF7aCR/c1wa19zzqVBT3HWRUwNOlypAMo8=; b=paTujMl4oeOhvSAkF0UbgfokpqEkuz5CYXdLxHTQ2IjwbzdFrt3pILEl7ppLxEE4UZ fBUHi6XYiVETSXz4rYFuu2lhocP4BQycabVrG+pZDO+qOThmH2GFKPaZmoiVNjqIRlY1 EbIBkvEk/QlRyZqd+hR50EgZgkjV0bQYWmCSWLR9ooADgOO5SrvBQMf4gLP8BdPGDQ9G 5Qu+F/3r6td0gRN+VHW5deDUmKP4S4rjYU7nGp9r9EzqGxblZgyFAOEO2L90ZK05AESR HEWsIl7xh6g9iiivD5yhyXXMypgFFF+xTvFSe0bTwbpGhi7T3iAzgmJfZ1itWx9oHkQa UTyw== X-Gm-Message-State: AOAM533dmrt+ARvtz3RXFFrzwAWIhIcs2U0YraEo7t7LwteZZFVqJYvQ 1dKdgWKG8yYqd1TMCpJPXzyxVpRsKYg= X-Google-Smtp-Source: ABdhPJzmxcevIdLrNPB4qTSg8Bjf/6bYbjsNZuHAXn7hQnC1GPqjpJxcGXXRRqDKFC61CH+63x3IYA== X-Received: by 2002:a05:6402:1758:: with SMTP id v24mr158875edx.274.1596065458876; Wed, 29 Jul 2020 16:30:58 -0700 (PDT) Received: from localhost ([46.166.182.65]) by smtp.gmail.com with ESMTPSA id m24sm3145974eje.80.2020.07.29.16.30.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2020 16:30:58 -0700 (PDT) From: Sebastian Jakubiak To: pacman-contrib@lists.archlinux.org Subject: [PATCH] pactree: Fix tree drawing for --optional Date: Thu, 30 Jul 2020 01:30:54 +0200 Message-Id: <20200729233054.18118-1-jakseb.dev@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: pacman-contrib@lists.archlinux.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion list for pacman-contrib development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" Example of an incorrect behavior: $ pactree -a -d1 -o dia dia |-libxslt `-gtk2 `-python2 (optional) The last non-optional dependency, gtk2, has its limb drawn as if it were the last child of a node, even though an optional dependency follows. Signed-off-by: Sebastian Jakubiak --- src/pactree.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/pactree.c b/src/pactree.c index 39328e7..e34ecc8 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -505,7 +505,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r /** * print the dependency list given, passing the optional parameter when required */ -static void print_dep_list(alpm_list_t *deps, alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev, int optional, int opt_dep) +static void print_dep_list(alpm_list_t *deps, alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev, int optional, int opt_dep, int final) { alpm_list_t *i; int new_optional; @@ -520,7 +520,7 @@ static void print_dep_list(alpm_list_t *deps, alpm_list_t *dblist, alpm_pkg_t *p for(i = deps; i; i = alpm_list_next(i)) { const char *pkgname = i->data; - int last = alpm_list_next(i) ? 0 : 1; + int last = final && (alpm_list_next(i) ? 0 : 1); alpm_pkg_t *dep_pkg = alpm_find_dbs_satisfier(handle, dblist, pkgname); @@ -561,7 +561,7 @@ static void print_dep_list(alpm_list_t *deps, alpm_list_t *dblist, alpm_pkg_t *p */ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int rev, int optional) { - alpm_list_t *deps; + alpm_list_t *deps, *optdeps; if(!pkg || ((max_depth >= 0) && (depth->level > max_depth))) { return; @@ -575,21 +575,20 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r deps = get_pkg_deps(pkg); } - print_dep_list(deps, dblist, pkg, depth, rev, optional, 0); - - FREELIST(deps); - + optdeps = NULL; if(optional){ if(rev) { - deps = alpm_pkg_compute_optionalfor(pkg); + optdeps = alpm_pkg_compute_optionalfor(pkg); } else { - deps = get_pkg_optdeps(pkg); + optdeps = get_pkg_optdeps(pkg); } + } - print_dep_list(deps, dblist, pkg, depth, rev, optional, 1); + print_dep_list(deps, dblist, pkg, depth, rev, optional, 0, !optdeps); + FREELIST(deps); - FREELIST(deps); - } + print_dep_list(optdeps, dblist, pkg, depth, rev, optional, 1, 1); + FREELIST(optdeps); } int main(int argc, char *argv[])