[PATCH] pactree: Compress self-provided optional dependencies
Remove `provides X` from `X provides X: ...` lines describing optional dependencies to make the output more compact. Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> --- I noticed that most optional dependencies in the output of `pactree --optional` have this unneeded repetition. With this patch the following: vim-runtime ├─bash provides sh: support for some tools and macros (optional) ├─python provides python: demoserver example tool (optional) └─gawk provides gawk: mve tools upport (optional) will change to: vim-runtime ├─bash provides sh: support for some tools and macros (optional) ├─python: demoserver example tool (optional) └─gawk: mve tools upport (optional) src/pactree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pactree.c b/src/pactree.c index e34ecc8..4bd4601 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -383,6 +383,14 @@ static int parse_options(int argc, char *argv[]) return 0; } +int pkg_provides_itself(const char *pkg, const char *depstring) +{ + size_t pkglen = strlen(pkg); + return (strncmp(pkg, depstring, pkglen) == 0 && + (depstring[pkglen] == '\0' || + strncmp(": ", depstring + pkglen, 2) == 0)); +} + /* pkg provides provision */ static void print_text(const char *pkg, const char *provision, tdepth *depth, int last, int opt_dep) @@ -419,12 +427,12 @@ static void print_text(const char *pkg, const char *provision, if(!pkg && provision) { printf("%s%s%s%s [unresolvable]%s%s\n", tip, color->leaf1, provision, color->branch1, opt_str, color->off); - } else if(provision && strcmp(pkg, provision) != 0 && *(style->provides) != '\0') { + } else if(provision && *(style->provides) != '\0' && !pkg_provides_itself(pkg, provision)) { printf("%s%s%s%s%s %s%s%s%s\n", tip, color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision, opt_str, color->off); } else { - printf("%s%s%s%s%s\n", tip, color->leaf1, pkg, opt_str, color->off); + printf("%s%s%s%s%s\n", tip, color->leaf1, (provision ? provision : pkg), opt_str, color->off); } } -- 2.27.0
On 7/31/20 12:00 PM, Sebastian Jakubiak wrote:
Remove `provides X` from `X provides X: ...` lines describing optional dependencies to make the output more compact.
Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> --- I noticed that most optional dependencies in the output of `pactree --optional` have this unneeded repetition. With this patch the following:
vim-runtime ├─bash provides sh: support for some tools and macros (optional) ├─python provides python: demoserver example tool (optional) └─gawk provides gawk: mve tools upport (optional)
will change to:
vim-runtime ├─bash provides sh: support for some tools and macros (optional) ├─python: demoserver example tool (optional) └─gawk: mve tools upport (optional)
Just for the record: these don't "provide themselves" at all. However, pactree might not distinguish between matching on the package name vs. matching on the package provides, since either one is a route to a valid *satisfier*. Looking at pactree.c the "provision" variable in print_text starts life as: dep_pkg = alpm_dbs_find_satisfier() -> depname = alpm_pkg_get_name(dep_pkg) ... The "pkg_provides_itself" function name sounds weird, and furthermore seems to be a *fix* for strcmp(pkg, provision) != 0 not performing its intended purpose since provision can be a freeform string containing e.g. descriptions. (The comment message should specify this, rather than implying it adds a new functionality.) I think you should instead use alpm_dep_from_string to turn the provision string into something you can get a properly formatted name from. Essentially reversing the work from get_pkg_deps. -- Eli Schwartz Bug Wrangler and Trusted User
Pactree takes care not to print both a dependency and the package to which it resolves if they are equal. Extend (fix?) this to cover versioned dependencies and optional dependencies containing descriptions, so that e.g. `gnupg provides gnupg>=2` and `clang provides clang: for qdoc` will be made more compact. Implementation suggested by Eli Schwartz. Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> --- Note that, in addition to the completely changed commit message and implementation, this version produces compact output for more cases than v1. To get v1's behavior, the condition should be changed to: result = dep->mod != ALPM_DEP_MOD_ANY || strcmp... src/pactree.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pactree.c b/src/pactree.c index e34ecc84..ad3dd737 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -383,6 +383,16 @@ static int parse_options(int argc, char *argv[]) return 0; } +static int should_show_satisfier(const char *pkg, const char *depstring) +{ + int result; + alpm_depend_t *dep = alpm_dep_from_string(depstring); + if(!dep) return 1; + result = strcmp(pkg, dep->name) != 0; + free(dep); + return result; +} + /* pkg provides provision */ static void print_text(const char *pkg, const char *provision, tdepth *depth, int last, int opt_dep) @@ -419,12 +429,12 @@ static void print_text(const char *pkg, const char *provision, if(!pkg && provision) { printf("%s%s%s%s [unresolvable]%s%s\n", tip, color->leaf1, provision, color->branch1, opt_str, color->off); - } else if(provision && strcmp(pkg, provision) != 0 && *(style->provides) != '\0') { + } else if(provision && *(style->provides) != '\0' && should_show_satisfier(pkg, provision)) { printf("%s%s%s%s%s %s%s%s%s\n", tip, color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision, opt_str, color->off); } else { - printf("%s%s%s%s%s\n", tip, color->leaf1, pkg, opt_str, color->off); + printf("%s%s%s%s%s\n", tip, color->leaf1, provision ? provision : pkg, opt_str, color->off); } } -- 2.28.0
On Wed Sep 2, 2020 at 1:41 PM EDT, Sebastian Jakubiak wrote:
Pactree takes care not to print both a dependency and the package to which it resolves if they are equal. Extend (fix?) this to cover versioned dependencies and optional dependencies containing descriptions, so that e.g. `gnupg provides gnupg>=2` and `clang provides clang: for qdoc` will be made more compact.
Implementation suggested by Eli Schwartz.
Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> ---
Note that, in addition to the completely changed commit message and implementation, this version produces compact output for more cases than v1. To get v1's behavior, the condition should be changed to:
result = dep->mod != ALPM_DEP_MOD_ANY || strcmp...
src/pactree.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/pactree.c b/src/pactree.c index e34ecc84..ad3dd737 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -383,6 +383,16 @@ static int parse_options(int argc, char *argv[]) return 0; }
+static int should_show_satisfier(const char *pkg, const char *depstring) +{ + int result; + alpm_depend_t *dep = alpm_dep_from_string(depstring); + if(!dep) return 1; + result = strcmp(pkg, dep->name) != 0; + free(dep); + return result; +} + /* pkg provides provision */ static void print_text(const char *pkg, const char *provision, tdepth *depth, int last, int opt_dep) @@ -419,12 +429,12 @@ static void print_text(const char *pkg, const char *provision, if(!pkg && provision) { printf("%s%s%s%s [unresolvable]%s%s\n", tip, color->leaf1, provision, color->branch1, opt_str, color->off); - } else if(provision && strcmp(pkg, provision) != 0 && *(style->provides) != '\0') { + } else if(provision && *(style->provides) != '\0' && should_show_satisfier(pkg, provision)) { printf("%s%s%s%s%s %s%s%s%s\n", tip, color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision, opt_str, color->off); } else { - printf("%s%s%s%s%s\n", tip, color->leaf1, pkg, opt_str, color->off); + printf("%s%s%s%s%s\n", tip, color->leaf1, provision ? provision : pkg, opt_str, color->off); } }
-- 2.28.0
Merged, thanks! -- Best, Daniel <https://danielcapella.com>
participants (3)
-
Daniel M. Capella
-
Eli Schwartz
-
Sebastian Jakubiak