From patchwork Tue Sep 28 21:09:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonathan_Sk=C3=B6ld?= X-Patchwork-Id: 1974 X-Patchwork-Delegate: andrew.gregory.8@gmail.com Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [2a01:4f9:c010:3052::1] by patchwork.archlinux.org with IMAP (fetchmail-6.4.22) for (single-drop); Tue, 28 Sep 2021 21:10:26 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id qLyqMcGEU2E16gAAK+/4rw (envelope-from ) for ; Tue, 28 Sep 2021 21:10:25 +0000 Received: from lists.archlinux.org (lists.archlinux.org [IPv6:2a01:4f9:c010:9eb4::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.archlinux.org (Postfix) with ESMTPS id B9953967745; Tue, 28 Sep 2021 21:10:24 +0000 (UTC) Received: from lists.archlinux.org (localhost [IPv6:::1]) by lists.archlinux.org (Postfix) with ESMTP id 39F948933EF; Tue, 28 Sep 2021 21:10:24 +0000 (UTC) X-Original-To: pacman-dev@lists.archlinux.org Delivered-To: pacman-dev@lists.archlinux.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050::465:202]) by lists.archlinux.org (Postfix) with ESMTPS id BBDB48933E7 for ; Tue, 28 Sep 2021 21:10:20 +0000 (UTC) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4HJsbc1j32zQk14; Tue, 28 Sep 2021 23:10:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skold.dev; s=MBO0001; t=1632863416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1S7SIOpSgnVg+XkOQowy/qE8cwk06Md1vrT2R7RDbXI=; b=qQkE3rKXTJO22urP1h1Ccq22HO/w/KKzZZBQQyUXYdAsNhB3mfW+NBb1wPF875+nADHZsN eyrSWhphWUSxA2zirR1e36fyr0qFPlc7i9aRwiMAgdfSQa3iSdaHYaQQgu39L3Ctx8rvkG h+Zov1wCuiN4bL0J2xY6EP3Jsl/iFM/lAQDXvb6hUY9H3MQs2PJZvbWZ25hZc8poC8yLlQ rhWtt4VttFMpjLZqAGigiF/mu/kL4htIPOp911v9dRhZgzNeEheoe7ldhw2NlTMzTQT6Q8 sc71Pjn1ErySYlpI4jZ6xKnfKfr8BMsXE5xLuLpVfmJ6/TJbGbsvbMqN1YgX8g== From: =?utf-8?q?Jonathan_Sk=C3=B6ld?= To: pacman-dev@lists.archlinux.org Cc: =?utf-8?q?Jonathan_Sk=C3=B6ld?= Subject: [PATCH v3] Print the target arch when using the %a format specifier Date: Tue, 28 Sep 2021 23:09:02 +0200 Message-Id: <20210928210902.1966177-1-arch@skold.dev> In-Reply-To: <00a1c003-f60b-7273-cbc0-263992cdeb41@archlinux.org> References: <00a1c003-f60b-7273-cbc0-263992cdeb41@archlinux.org> MIME-Version: 1.0 X-BeenThere: pacman-dev@lists.archlinux.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pacman-dev-bounces@lists.archlinux.org Sender: "pacman-dev" Authentication-Results: mail.archlinux.org; dkim=pass header.d=skold.dev header.s=MBO0001 header.b=qQkE3rKX; dmarc=pass (policy=none) header.from=skold.dev; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 2a01:4f9:c010:9eb4::1 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Rspamd-Queue-Id: B9953967745 X-Spamd-Result: default: False [-1.11 / 15.00]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[skold.dev,none]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; R_DKIM_ALLOW(-0.20)[skold.dev:s=MBO0001]; RCVD_IN_DNSWL_LOW(-0.20)[2001:67c:2050:105:465:1:2:0:received,2001:67c:2050::465:202:received]; RCVD_IN_DNSWL_MED(-0.20)[2a01:4f9:c010:9eb4::1:from]; R_SPF_ALLOW(-0.20)[+ip6:2a01:4f9:c010:9eb4::1]; MAILLIST(-0.20)[mailman]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[pacman-dev@lists.archlinux.org]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[arch@skold.dev,pacman-dev-bounces@lists.archlinux.org]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_THREE(0.00)[4]; ASN(0.00)[asn:24940, ipnet:2a01:4f9::/32, country:DE]; DKIM_TRACE(0.00)[skold.dev:+]; NEURAL_HAM(-0.00)[-1.000]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Server: mail.archlinux.org Adds the %a format specifier to allow printing of a target's arch when using --print-format. Signed-off-by: Jonathan Sköld --- 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* :: 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));