[PATCH] Resubmission: Print the package arch using the %a format specifier.
This is a resubmission of this patch, since my email got DMARC'ed the first time around. That should hopefully be fixed now and I apologise to anyone who received this email twice. Adds the %a format specifier to allow printing of the package arch when using --print-format. Signed-off-by: Jonathan Sköld <arch@skold.dev> --- src/pacman/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pacman/util.c b/src/pacman/util.c index 5486e7a5..bb57e950 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1146,6 +1146,12 @@ void print_packages(const alpm_list_t *packages) alpm_pkg_t *pkg = i->data; char *string = strdup(config->print_format); char *temp = string; + /* %a : pkgarch */ + if(strstr(temp, "%a")) { + string = strreplace(temp, "%a", alpm_pkg_get_arch(pkg)); + free(temp); + temp = string; + } /* %n : pkgname */ if(strstr(temp, "%n")) { string = strreplace(temp, "%n", alpm_pkg_get_name(pkg)); -- 2.33.0
Was pointed out in the IRC channel that package arch may be NULL. Revised the patch to include a NULL check before trying to replace string. Signed-off-by: Jonathan Sköld <arch@skold.dev> --- src/pacman/util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pacman/util.c b/src/pacman/util.c index 5486e7a5..70df6128 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages) alpm_pkg_t *pkg = i->data; char *string = strdup(config->print_format); char *temp = string; + /* %a : pkgarch */ + if(strstr(temp, "%a")) { + const char *arch = alpm_pkg_get_arch(pkg); + if(arch == NULL) { + arch = ""; + } + string = strreplace(temp, "%a", arch); + free(temp); + temp = string; + } /* %n : pkgname */ if(strstr(temp, "%n")) { string = strreplace(temp, "%n", alpm_pkg_get_name(pkg)); -- 2.33.0
On 26/09/2021 14:57, Jonathan Sköld wrote:
Was pointed out in the IRC channel that package arch may be NULL. Revised the patch to include a NULL check before trying to replace string.
Signed-off-by: Jonathan Sköld <arch@skold.dev> --- src/pacman/util.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 5486e7a5..70df6128 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages) alpm_pkg_t *pkg = i->data; char *string = strdup(config->print_format); char *temp = string; + /* %a : pkgarch */ + if(strstr(temp, "%a")) { + const char *arch = alpm_pkg_get_arch(pkg); + if(arch == NULL) { + arch = ""; + } + string = strreplace(temp, "%a", arch); + free(temp); + temp = string; + } /* %n : pkgname */ if(strstr(temp, "%n")) { string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));
Looks good to me. Though in future the bit about irc should be a comment instead of inside the commit message. You can write --- in the commit message and everything below it will be a comment when sent as a patch.
On 27/09/2021 21:35, Morgan Adamiec wrote:
On 26/09/2021 14:57, Jonathan Sköld wrote:
Was pointed out in the IRC channel that package arch may be NULL. Revised the patch to include a NULL check before trying to replace string.
Signed-off-by: Jonathan Sköld <arch@skold.dev> --- src/pacman/util.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 5486e7a5..70df6128 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages) alpm_pkg_t *pkg = i->data; char *string = strdup(config->print_format); char *temp = string; + /* %a : pkgarch */ + if(strstr(temp, "%a")) { + const char *arch = alpm_pkg_get_arch(pkg); + if(arch == NULL) { + arch = ""; + } + string = strreplace(temp, "%a", arch); + free(temp); + temp = string; + } /* %n : pkgname */ if(strstr(temp, "%n")) { string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));
Looks good to me. Though in future the bit about irc should be a comment instead of inside the commit message.
You can write --- in the commit message and everything below it will be a comment when sent as a patch.
Also forgot to mention, the man page needs to also mention %a
Adds the %a format specifier to allow printing of a target's arch when using --print-format. Signed-off-by: Jonathan Sköld <arch@skold.dev> --- Fixed my commit message now that I know how it works, thanks for the heads up. Modified the man page. I opted to use the phrase 'arch' to match the field used in PKGBUILDs. I hope this is not too ambiguous for users. I also changed the comment in util.c to match this. --- doc/pacman.8.asciidoc | 5 +++-- src/pacman/util.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/pacman.8.asciidoc b/doc/pacman.8.asciidoc index bb205627..785844ce 100644 --- a/doc/pacman.8.asciidoc +++ b/doc/pacman.8.asciidoc @@ -235,8 +235,9 @@ Transaction Options (apply to '-S', '-R' and '-U') *\--print-format* <format>:: Specify a printf-like format to control the output of the '\--print' - operation. The possible attributes are: "%n" for pkgname, "%v" for pkgver, - "%l" for location, "%r" for repository, and "%s" for size. Implies '\--print'. + operation. The possible attributes are: "%a" for arch, "%n" for pkgname, + "%v" for pkgver, "%l" for location, "%r" for repository, and "%s" for size. + Implies '\--print'. Upgrade Options (apply to '-S' and '-U')[[UO]] diff --git a/src/pacman/util.c b/src/pacman/util.c index 5486e7a5..2b2b27ca 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages) alpm_pkg_t *pkg = i->data; char *string = strdup(config->print_format); char *temp = string; + /* %a : arch */ + if(strstr(temp, "%a")) { + const char *arch = alpm_pkg_get_arch(pkg); + if(arch == NULL) { + arch = ""; + } + string = strreplace(temp, "%a", arch); + free(temp); + temp = string; + } /* %n : pkgname */ if(strstr(temp, "%n")) { string = strreplace(temp, "%n", alpm_pkg_get_name(pkg)); -- 2.33.0
participants (2)
-
Jonathan Sköld
-
Morgan Adamiec