[PATCH 3/3] util.c: extend --print-format with %C, %D, %M

Emil Velikov emil.l.velikov at gmail.com
Sun Mar 27 13:33:46 UTC 2022


On Sat, 26 Mar 2022 at 15:54, Jelle van der Waa <jelle at vdwaa.nl> wrote:
>
> From: Jelle van der Waa <jelle at archlinux.org>
>
> Extend print-format with checkdepends, depends and makedepends.
>
> Signed-off-by: Jelle van der Waa <jelle at archlinux.org>
> ---
>  doc/pacman.8.asciidoc |  3 ++-
>  src/pacman/util.c     | 49 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 1 deletion(-)
>
> diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc
> index 8a9294fc..2040f98d 100644
> --- a/doc/pacman.8.asciidoc
> +++ b/doc/pacman.8.asciidoc
> @@ -239,7 +239,8 @@ Transaction Options (apply to '-S', '-R' and '-U')
>         builddate, "%d" for description, "%e" for pkgbase, "%f" for filename,
>         "%g" for base64 encoded PGP signature, "%h" for sha256sum, "%n" for
>         pkgname, "%p" for packager, "%v" for pkgver, "%l" for location, "%r"
> -       for repository, and "%s" for size.
> +       for repository, "%s" for size, "%C" for checkdepends, "%D" for depends
> +       and "%M" for makedepends.
>         Implies '\--print'.
>
>
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 519765f1..cae024e4 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -405,6 +405,28 @@ char *strreplace(const char *str, const char *needle, const char *replace)
>         return newstr;
>  }
>
> +static char *concat_alpm_depends(alpm_list_t *lst)
> +{
> +       char *depends = NULL;
> +       char *tmp = NULL;
> +       for(alpm_list_t *i = lst; i; i = alpm_list_next(i)) {
> +               alpm_depend_t *dep = i->data;
> +               char *depstring = alpm_dep_compute_string(dep);
> +               if(tmp) {
> +                   asprintf(&depends, "%s %s", tmp, depstring);
> +                   free(tmp);
> +               } else {
> +                   asprintf(&depends, "%s", depstring);
> +               }
> +               tmp = depends;
> +               free(depstring);

Function does 2x allocation for each dependency. Where a bunch of
packages easily have 20+.
In case that matters and one wants to micro-optimise - a pre/re
allocated 4k page should reduce that.

Just throwing the idea - doubt it matters too much to care.
-Emil


More information about the pacman-dev mailing list