From patchwork Wed Dec 9 15:52:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11961777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AB01C433FE for ; Wed, 9 Dec 2020 15:53:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 147A322B48 for ; Wed, 9 Dec 2020 15:53:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731170AbgLIPxN (ORCPT ); Wed, 9 Dec 2020 10:53:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731114AbgLIPxH (ORCPT ); Wed, 9 Dec 2020 10:53:07 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3878EC0613D6 for ; Wed, 9 Dec 2020 07:52:27 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id t16so2279440wra.3 for ; Wed, 09 Dec 2020 07:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j2ZTSvWySxS2pIoV3RsjQzL7KBtb1JQBiJDaBIgVfGA=; b=j6a21c8IX3zOXw0QOJ6tXPBCK0c6eAWAtIP+rxlXMx/Ru8NW30xfI9uWRFaXAA0vaQ KcAq3LBKdIJZ+CjDj3uEmwup2sqhtoJT6Tfn5VhCES76lOyZl9ukmM8zMiR2JpzfpAOA cJF5FB7+Avn4wg0Nqg/zvYFE6DLzhFNofC+zfNc8lGmgDXdieA3VHn2eZMj+U9gnlhZh Xcu7VYsr2pRx0UBvOLq+WqI/ee9IySZoijLUB3JO0OrKCzaRq/ct58KaFybraOB5Q8Pa qqkWrDCFhOexybWdvPyAjiYg+7ayQlHskMOkchdGTDE6+YPx1naTnio9cgrlSfY2QydB egTA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=j2ZTSvWySxS2pIoV3RsjQzL7KBtb1JQBiJDaBIgVfGA=; b=KYL2WbsSVSJpgq95MVhE+HkZDXFRLvWWWGnDnSaKtUmUAyMYedFYjkZ4nu9NPQRHVh o3R1UpKFY/hHhPNPK0A7Hy+N9x0SZpym4rOCwd1i3blDoT7EeCIv5vxOPIwxv4UQEjr1 7LVFKiOTbugtL/Mnu27Nm+E8aXFWtZ62a1QvHRXiH/VysRPrYUmZlDw8silseXx4YtPZ DMI+neJqI+xxfGMPHyDj4x/znx1ef5H0omLll7LP000OAVd+suzN7pTG46RYM1D/Tb03 udK3hA5up2qF9ihc3xdE9wRpHrjqfIsnwQhqyjZTfdYF2Ae8ckVHDQkUu9hlSMjLsK7m L3VA== X-Gm-Message-State: AOAM532tH1O6bNpKpSJKdu4wkmEAQia4kM0zYjq8y7v5PggrAUqO4qTW RJCSkD2ZKgY4rK86vWiC04Moo3VxTlDStw== X-Google-Smtp-Source: ABdhPJzzgBZSI+eoJ5bG6LcsMNg2v0z1rYrMA+FN4Bvte8xyrfUDP0d3AZeMy/u3TamgbAzhekA7zQ== X-Received: by 2002:a5d:660b:: with SMTP id n11mr3395190wru.407.1607529145905; Wed, 09 Dec 2020 07:52:25 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b7sm4424495wrv.47.2020.12.09.07.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 07:52:25 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com, Hariom Verma , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 1/5] pretty format %(trailers) test: split a long line Date: Wed, 9 Dec 2020 16:52:04 +0100 Message-Id: <20201209155208.17782-2-avarab@gmail.com> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8 In-Reply-To: <20201206002449.31452-1-avarab@gmail.com> References: <20201206002449.31452-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split a very long line in a test introduced in 0b691d86851 (pretty: add support for separator option in %(trailers), 2019-01-28). This makes it easier to read, especially as follow-up commits will copy this test as a template. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t4205-log-pretty-formats.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 204c149d5a4..5e5452212d2 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -717,7 +717,12 @@ test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' test_expect_success 'pretty format %(trailers:separator) changes separator' ' git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual && - printf "XSigned-off-by: A U Thor \0Acked-by: A U Thor \0[ v2 updated patch description ]\0Signed-off-by: A U Thor X" >expect && + ( + printf "XSigned-off-by: A U Thor \0" && + printf "Acked-by: A U Thor \0" && + printf "[ v2 updated patch description ]\0" && + printf "Signed-off-by: A U Thor X" + ) >expect && test_cmp expect actual ' From patchwork Wed Dec 9 15:52:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11961785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 756E7C433FE for ; Wed, 9 Dec 2020 15:53:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49FD822B47 for ; Wed, 9 Dec 2020 15:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731059AbgLIPxM (ORCPT ); Wed, 9 Dec 2020 10:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731121AbgLIPxJ (ORCPT ); Wed, 9 Dec 2020 10:53:09 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2FFAC061793 for ; Wed, 9 Dec 2020 07:52:28 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id 91so2266386wrj.7 for ; Wed, 09 Dec 2020 07:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H4i9L0kmWoZZ/AgS0l9EwDfBeBCRHWLwMxoe/jUBloI=; b=tibIzE02qE10x6mmtyYI9QrwODAGx6JYFcpgYA4ZvCebeOWg/4MBK4FGi+/JdFvmgs TLyw26Zt41yMXKf4SHOG749jdrXD2cMkVRD7hztuAC10IkxsU92VWKU5KJTneQQLmTF1 WVwNE22S/Dvd793Yl0FSfxzo2PIS9cmntHns/j+9SWPvhXgo1/fs1THtTrYUaGZ+n1mX P8gVg8Qv1INgAgjnsXMekxhXyFVPy1N78tYXEugqz5S/+XxFc78ChknGd43kuf/4B7yI rmFaXCmwFZOskni4yP71mDKMYIP8tBHl0qpCU2FRHBpnYqWe9bx7nO3iBkiEqIzGIlvq At3A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=H4i9L0kmWoZZ/AgS0l9EwDfBeBCRHWLwMxoe/jUBloI=; b=r2hfPmH6A5mxo9nxuKA2b7fcfwcbyc7HAGcV5gcSvShU5qt8Q7K11EPKC09UgbuOt1 oFoJjyjXpkXSoPVbmfJSSUa9ekEFadhOWLF+KiIIQjS13CwzN0HC8/8zDFTxSGC9cOWB TSuGwHV6vSDcDY5dVJQFRS4YPge++GPDh1Uk3oUgrHM/sufpdfJ+oUQhtZgVCgO1bpvb t2QIMSzGjV/WYt20jAtY942QBehjecyx8Fihah6Ms4msHLVydsITA/qa83YBrkk8AjC0 Rn6lL3JEsYy7UKSdu9rmA6kiM8sfgm2prWQICCzgmXv/fOknqVuX9uhTAjf05LECxVii 0ziQ== X-Gm-Message-State: AOAM531aANWDkB07t+SK7g1ABasSvvpbEuRRfk0f+50NUtxC3OawFUgJ 5KoURxqBwq9FsP951ik5byDFWFu5nv8Mgg== X-Google-Smtp-Source: ABdhPJxBSnbeGFepOSlyDhjzyFlnZpl2XUvUkid4zjCdRS+iWjFE657vGSvSOVr/0GdGK/vfVF4bcw== X-Received: by 2002:a5d:69d1:: with SMTP id s17mr3470580wrw.104.1607529147412; Wed, 09 Dec 2020 07:52:27 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b7sm4424495wrv.47.2020.12.09.07.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 07:52:26 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com, Hariom Verma , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 2/5] pretty format %(trailers) doc: avoid repetition Date: Wed, 9 Dec 2020 16:52:05 +0100 Message-Id: <20201209155208.17782-3-avarab@gmail.com> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8 In-Reply-To: <20201206002449.31452-1-avarab@gmail.com> References: <20201206002449.31452-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the documentation for the various %(trailers) options so it isn't repeating part of the documentation for "only" about how boolean values are handled. Instead, let's split the description of that into general documentation at the top. It then suffices to refer to it by listing the options as "opt[=]". I'm also changing it to upper-case "[=]" from "[=val]" for consistency with "" It took me a couple of readings to realize that these options were referring back to the "only" option's treatment of boolean values. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/pretty-formats.txt | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 84bbc7439a6..973b6c7d482 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -252,7 +252,15 @@ endif::git-rev-list[] interpreted by linkgit:git-interpret-trailers[1]. The `trailers` string may be followed by a colon - and zero or more comma-separated options: + and zero or more comma-separated options. + If any option is provided multiple times the + last occurance wins. ++ +The boolean options accept an optional value `[=]`. The values +`true`, `false`, `on`, `off` etc. are all accepted. See the "boolean" +sub-section in "EXAMPLES" in linkgit:git-config[1]. If a boolean +option is given with no value, it's enabled. ++ ** 'key=': only show trailers with specified key. Matching is done case-insensitively and trailing colon is optional. If option is given multiple times trailer lines matching any of the keys are @@ -261,27 +269,21 @@ endif::git-rev-list[] desired it can be disabled with `only=false`. E.g., `%(trailers:key=Reviewed-by)` shows trailer lines with key `Reviewed-by`. -** 'only[=val]': select whether non-trailer lines from the trailer - block should be included. The `only` keyword may optionally be - followed by an equal sign and one of `true`, `on`, `yes` to omit or - `false`, `off`, `no` to show the non-trailer lines. If option is - given without value it is enabled. If given multiple times the last - value is used. +** 'only[=]': select whether non-trailer lines from the trailer + block should be included. ** 'separator=': specify a separator inserted between trailer lines. When this option is not given each trailer line is terminated with a line feed character. The string SEP may contain the literal formatting codes described above. To use comma as separator one must use `%x2C` as it would otherwise be parsed as - next option. If separator option is given multiple times only the - last one is used. E.g., `%(trailers:key=Ticket,separator=%x2C )` + next option. E.g., `%(trailers:key=Ticket,separator=%x2C )` shows all trailer lines whose key is "Ticket" separated by a comma and a space. -** 'unfold[=val]': make it behave as if interpret-trailer's `--unfold` - option was given. In same way as to for `only` it can be followed - by an equal sign and explicit value. E.g., +** 'unfold[=]': make it behave as if interpret-trailer's `--unfold` + option was given. E.g., `%(trailers:only,unfold=true)` unfolds and shows all trailer lines. -** 'valueonly[=val]': skip over the key part of the trailer line and only - show the value part. Also this optionally allows explicit value. +** 'valueonly[=]': skip over the key part of the trailer line and only + show the value part. NOTE: Some placeholders may depend on other options given to the revision traversal engine. For example, the `%g*` reflog options will From patchwork Wed Dec 9 15:52:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11961783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3276CC433FE for ; Wed, 9 Dec 2020 15:53:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF0B722B47 for ; Wed, 9 Dec 2020 15:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731121AbgLIPxM (ORCPT ); Wed, 9 Dec 2020 10:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731130AbgLIPxK (ORCPT ); Wed, 9 Dec 2020 10:53:10 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 041ABC0617A6 for ; Wed, 9 Dec 2020 07:52:30 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id e25so2185791wme.0 for ; Wed, 09 Dec 2020 07:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U4qj8uKOjVNvuGI4EuAJXJRGBvpZoYBsOgGr/HA52zs=; b=IelZhEO3eG+fGeBTxH1AFBESE77tJnWo4eqfzhFW1bBldNbI/o+KS2ac/gtfEp5yEe 0SE0VGXy/LaSj3d0AkCVtcOSd2FPtLUl0MIxQ0glxF06qJ132MItUdIP2Ijv5EVo0kfA ysf1BKDlI/dW8fI70RGxApKYCq3U61wVKl29f4BscxN/SbvmVIuMNrw14PxySVN9VmpB 4kOS97TzMt4MtTRockUttMRtDrv/XkCo/+dxyakEy1kHqF7V4sQijKICgd6s79aVGXYf MMBLDsrxIt8XaC9X+1FtBkxrzRV1uiiuqhQkyN8kBEmGxG5Wm4XKeKF2aNxsp7mJr7ux Iayw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=U4qj8uKOjVNvuGI4EuAJXJRGBvpZoYBsOgGr/HA52zs=; b=P+2lOHiAwsurbZjRdQy4iCM4zXtM//oJ2rhx5qsr+EbPAIvT6CH8ul2NSEJS+p0i9w 1m8qoaZ34bZ1+Z/HfOnkNcSNRdX7ss4pC0+1k+KoErUns653e/FEnM3VMZWHuBU8hEmP sQ7GrK03A0WFUE7t4kpk5a1FrEH/OKddu1iA/8AV7ZyFJbzN/mqnKPvda1jfKqDMIykn xuR6OTHl+5xe6Qxco14RdyzXfKfP6F+BhIm6AltSfx81wMPOJ7ndq8ZcxLosYS9mkXPj xjESVVIOZjF6GncESzzgipjxOCo75AotThtbYl1xo4KO++EUxi+MEEHu8C2iEsH178Jg YM5A== X-Gm-Message-State: AOAM532Vgm/lwX0NxdOZwPNVnfiRzhG3nbcoW/IOlXn7BbsviobUPvBb BeCOJLjMFA8FZpZtFXIbbMKBjCLI/DwQ6w== X-Google-Smtp-Source: ABdhPJz34irDYUoacCyU4yVuPAGHTgKN0j/0KO4XogpkwbMenNRBAD9TawH2i9wh1VwDM4yVm3/cVw== X-Received: by 2002:a1c:2c83:: with SMTP id s125mr3435420wms.161.1607529148749; Wed, 09 Dec 2020 07:52:28 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b7sm4424495wrv.47.2020.12.09.07.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 07:52:28 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com, Hariom Verma , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 3/5] pretty-format %(trailers): fix broken standalone "valueonly" Date: Wed, 9 Dec 2020 16:52:06 +0100 Message-Id: <20201209155208.17782-4-avarab@gmail.com> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8 In-Reply-To: <20201206002449.31452-1-avarab@gmail.com> References: <20201206002449.31452-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix %(trailers:valueonly) being a noop due to on overly eager optimization in format_trailer_info() which skips custom formatting if no custom options are given. When "valueonly" was added in d9b936db522 (pretty: add support for "valueonly" option in %(trailers), 2019-01-28) we forgot to add it to the list of options that optimization checks for. See e.g. the addition of "key" in 250bea0c165 (pretty: allow showing specific trailers, 2019-01-28) for a similar change where this wasn't missed. Thus the "valueonly" option in "%(trailers:valueonly)" was a noop and the output was equivalent to that of a plain "%(trailers)". This wasn't caught because the tests for it always combined it with other options. Fix the bug by adding !opts->value_only to the list. I initially attempted to make this more future-proof by setting a flag if we got to ":" in "%(trailers:" in format_commit_one() in pretty.c. However, "%(trailers:" is also parsed in trailers_atom_parser() in ref-filter.c. There is an outstanding patch[1] unify those two, and such a fix, or other future-proofing, such as changing "process_trailer_options" flags into a bitfield, would conflict with that effort. Let's instead do the bare minimum here as this aspect of trailers is being actively worked on by another series. Let's also test for a plain "valueonly" without any other options, as well as "separator". All the other existing options on the pretty.c path had tests where they were the only option provided. I'm also keeping a sanity test for "%(trailers:)" being the same as "%(trailers)". There's no reason to suspect it wouldn't be in the current implementation, but let's keep it in the interest of black box testing. 1. https://lore.kernel.org/git/pull.726.git.1599335291.gitgitgadget@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t4205-log-pretty-formats.sh | 28 ++++++++++++++++++++++++++++ trailer.c | 3 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 5e5452212d2..cb09a13249e 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -605,6 +605,12 @@ test_expect_success 'pretty format %(trailers) shows trailers' ' test_cmp expect actual ' +test_expect_success 'pretty format %(trailers:) enables no options' ' + git log --no-walk --pretty="%(trailers:)" >actual && + # "expect" the same as the test above + test_cmp expect actual +' + test_expect_success '%(trailers:only) shows only "key: value" trailers' ' git log --no-walk --pretty="%(trailers:only)" >actual && { @@ -715,7 +721,29 @@ test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' test_cmp expect actual ' +test_expect_success '%(trailers:valueonly) shows only values' ' + git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && + test_write_lines \ + "A U Thor " \ + "A U Thor " \ + "[ v2 updated patch description ]" \ + "A U Thor" \ + " " >expect && + test_cmp expect actual +' + test_expect_success 'pretty format %(trailers:separator) changes separator' ' + git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual && + ( + printf "XSigned-off-by: A U Thor \0" && + printf "Acked-by: A U Thor \0" && + printf "[ v2 updated patch description ]\0" && + printf "Signed-off-by: A U Thor\n X" + ) >expect && + test_cmp expect actual +' + +test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separator' ' git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual && ( printf "XSigned-off-by: A U Thor \0" && diff --git a/trailer.c b/trailer.c index 3f7391d793c..d2d01015b1d 100644 --- a/trailer.c +++ b/trailer.c @@ -1131,7 +1131,8 @@ static void format_trailer_info(struct strbuf *out, size_t i; /* If we want the whole block untouched, we can take the fast path. */ - if (!opts->only_trailers && !opts->unfold && !opts->filter && !opts->separator) { + if (!opts->only_trailers && !opts->unfold && !opts->filter && + !opts->separator && !opts->value_only) { strbuf_add(out, info->trailer_start, info->trailer_end - info->trailer_start); return; From patchwork Wed Dec 9 15:52:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11961781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FA2BC19425 for ; Wed, 9 Dec 2020 15:53:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0989922B47 for ; Wed, 9 Dec 2020 15:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731147AbgLIPxN (ORCPT ); Wed, 9 Dec 2020 10:53:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729833AbgLIPxL (ORCPT ); Wed, 9 Dec 2020 10:53:11 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2F0C0617A7 for ; Wed, 9 Dec 2020 07:52:31 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id c1so2262460wrq.6 for ; Wed, 09 Dec 2020 07:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GH5bBPflncyWNKOpDQX12xOZqdS8ce/QX1r0FM/M65U=; b=C+AMzhsOaBwxU3g5zRvXnm7tZStTFYkoGZ0dAXz8ycZsFCg/bzbdfqRvKcPzrjvsQd 2HJmgN5SMBccAsc7IM9/zzXPcBJOxbaI314jEmq0JdvYV932pB6XvVQDJij3R7PNkONS evGfDlZKDXn3X93/oBW8Bijtv55orHDu4PtvbiXVUGNitwMIauEi1BR6HeYRucJv0PBV 9F2mrV8y3P9JE89h/eMA4ecTgkyLVcQ9JQKZRqoJLTH7L59UNdbz2AcXF5CfKwpUBAKl Nv2GHjoKpBt7B82OXowTt5nJdhTnVPH4+aAcHUj4Q9MZWLNl6LKvLiapXA4SghVeugRH 7m7A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=GH5bBPflncyWNKOpDQX12xOZqdS8ce/QX1r0FM/M65U=; b=itaSPHEvlM4+daVbFsSlqCd54CglEsc9a64vFUJVSk/elIpvNsY6k6M0df5K5J1h3O Y31+vQCmlthF3Tv7LAWrGoGiJyWSAJ01njoGwODZ5SP7DSKuB6dQ7I5N0hhwtgeY8+/P u99Qc9XI2YslhLe4MdwIrz1XEtLTHmZDebc9dB2xoAN+C8/f5qufHXgQ+783bsh5aG/F j+q0PdcS4Ti8d599EbBUlDtbbI1zN1Ishoh1YMNrfkbAMsMw+oTPaWYDc6EEMGOgwTzv UfD8nUX7KJG9vuovAIA0IVryL6fG6muCTYuSvkvCRS3ontxdm8s+fOAIN4R6yYULrGc6 V4vw== X-Gm-Message-State: AOAM531LZmcgwyygwr9FgbpcOZbvY3ON57nbWqge2F+vG3bJmRFfzQGF RQ7HzTB79xuXqdX1CZgQeXydeOw3SBmYqg== X-Google-Smtp-Source: ABdhPJx9fOS2qK2RQq6J2YnPIWpUCb75F0chNhDZi7KU4O1kCh2czS9dvj5ZlPQFWauj40Rw6WMvZg== X-Received: by 2002:adf:ebc5:: with SMTP id v5mr3374799wrn.392.1607529150103; Wed, 09 Dec 2020 07:52:30 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b7sm4424495wrv.47.2020.12.09.07.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 07:52:29 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com, Hariom Verma , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 4/5] pretty format %(trailers): add a "keyonly" Date: Wed, 9 Dec 2020 16:52:07 +0100 Message-Id: <20201209155208.17782-5-avarab@gmail.com> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8 In-Reply-To: <20201206002449.31452-1-avarab@gmail.com> References: <20201206002449.31452-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add support for a "keyonly". This allows for easier parsing out of the key and value. Before if you didn't want to make assumptions about how the key was formatted. You'd need to parse it out as e.g.: --pretty=format:'%H%x00%(trailers:separator=%x00%x00)' \ '%x00%(trailers:separator=%x00%x00,valueonly)' And then proceed to deduce keys by looking at those two and subtracting the value plus the hardcoded ": " separator from the non-valueonly %(trailers) line. Now it's possible to simply do: --pretty=format:'%H%x00%(trailers:separator=%x00%x00,keyonly)' \ '%x00%(trailers:separator=%x00%x00,valueonly)' Which at least reduces it to a state machine where you get N keys and correlate them with N values. Even better would be to have a way to change the ": " delimiter to something easily machine-readable (a key might contain ": " too). A follow-up change will add support for that. I don't really have a use-case for just "keyonly" myself. I suppose it would be useful in some cases as "key=*" matches case-insensitively, so a plain "keyonly" will give you the variants of the keys you matched. I'm mainly adding it to fix the inconsistency with "valueonly". Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/pretty-formats.txt | 4 ++-- pretty.c | 1 + t/t4205-log-pretty-formats.sh | 31 ++++++++++++++++++++++++++++++- trailer.c | 9 ++++++--- trailer.h | 1 + 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 973b6c7d482..5eac36500d4 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -282,8 +282,8 @@ option is given with no value, it's enabled. ** 'unfold[=]': make it behave as if interpret-trailer's `--unfold` option was given. E.g., `%(trailers:only,unfold=true)` unfolds and shows all trailer lines. -** 'valueonly[=]': skip over the key part of the trailer line and only - show the value part. +** 'keyonly[=]': only show the key part of the trailer. +** 'valueonly[=]': only show the value part of the trailer. NOTE: Some placeholders may depend on other options given to the revision traversal engine. For example, the `%g*` reflog options will diff --git a/pretty.c b/pretty.c index 7a7708a0ea7..1237ee0e45d 100644 --- a/pretty.c +++ b/pretty.c @@ -1451,6 +1451,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ opts.separator = &sepbuf; } else if (!match_placeholder_bool_arg(arg, "only", &arg, &opts.only_trailers) && !match_placeholder_bool_arg(arg, "unfold", &arg, &opts.unfold) && + !match_placeholder_bool_arg(arg, "keyonly", &arg, &opts.key_only) && !match_placeholder_bool_arg(arg, "valueonly", &arg, &opts.value_only)) break; } diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index cb09a13249e..4c9f6eb7946 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -715,6 +715,22 @@ test_expect_success '%(trailers:key) without value is error' ' test_cmp expect actual ' +test_expect_success '%(trailers:keyonly) shows only keys' ' + git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && + test_write_lines \ + "Signed-off-by" \ + "Acked-by" \ + "[ v2 updated patch description ]" \ + "Signed-off-by" >expect && + test_cmp expect actual +' + +test_expect_success '%(trailers:key=foo,keyonly) shows only key' ' + git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual && + echo "Acked-by" >expect && + test_cmp expect actual +' + test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual && echo "A U Thor " >expect && @@ -732,6 +748,12 @@ test_expect_success '%(trailers:valueonly) shows only values' ' test_cmp expect actual ' +test_expect_success '%(trailers:key=foo,keyonly,valueonly) shows nothing' ' + git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual && + echo >expect && + test_cmp expect actual +' + test_expect_success 'pretty format %(trailers:separator) changes separator' ' git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual && ( @@ -754,7 +776,7 @@ test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separa test_cmp expect actual ' -test_expect_success 'pretty format %(trailers) combining separator/key/valueonly' ' +test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' ' git commit --allow-empty -F - <<-\EOF && Important fix @@ -781,6 +803,13 @@ test_expect_success 'pretty format %(trailers) combining separator/key/valueonly "Does not close any tickets" \ "Another fix #567, #890" \ "Important fix #1234" >expect && + test_cmp expect actual && + + git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual && + test_write_lines \ + "Does not close any tickets" \ + "Another fix Closes, Closes" \ + "Important fix Closes" >expect && test_cmp expect actual ' diff --git a/trailer.c b/trailer.c index d2d01015b1d..889b419a4f6 100644 --- a/trailer.c +++ b/trailer.c @@ -1132,7 +1132,7 @@ static void format_trailer_info(struct strbuf *out, /* If we want the whole block untouched, we can take the fast path. */ if (!opts->only_trailers && !opts->unfold && !opts->filter && - !opts->separator && !opts->value_only) { + !opts->separator && !opts->key_only && !opts->value_only) { strbuf_add(out, info->trailer_start, info->trailer_end - info->trailer_start); return; @@ -1154,8 +1154,11 @@ static void format_trailer_info(struct strbuf *out, if (opts->separator && out->len != origlen) strbuf_addbuf(out, opts->separator); if (!opts->value_only) - strbuf_addf(out, "%s: ", tok.buf); - strbuf_addbuf(out, &val); + strbuf_addbuf(out, &tok); + if (!opts->key_only && !opts->value_only) + strbuf_addstr(out, ": "); + if (!opts->key_only) + strbuf_addbuf(out, &val); if (!opts->separator) strbuf_addch(out, '\n'); } diff --git a/trailer.h b/trailer.h index cd93e7ddea7..d2f28776be6 100644 --- a/trailer.h +++ b/trailer.h @@ -71,6 +71,7 @@ struct process_trailer_options { int only_input; int unfold; int no_divider; + int key_only; int value_only; const struct strbuf *separator; int (*filter)(const struct strbuf *, void *); From patchwork Wed Dec 9 15:52:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 11961779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08101C4361B for ; Wed, 9 Dec 2020 15:53:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFB4F22D07 for ; Wed, 9 Dec 2020 15:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726456AbgLIPxO (ORCPT ); Wed, 9 Dec 2020 10:53:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731166AbgLIPxN (ORCPT ); Wed, 9 Dec 2020 10:53:13 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAFF0C0617B0 for ; Wed, 9 Dec 2020 07:52:32 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id t4so2256971wrr.12 for ; Wed, 09 Dec 2020 07:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KcEqSGOsiXaPJ6jV34M5r6wl3qXeqxbsXAcm7tF7IxM=; b=rlIQBATQaYeDDLGGiIJsVJs709hgKPSpimOyLYz5j7mtsh/G0PqJcV/vDjq/cJ9YIT 2tWUHsjxnZ1qZW5Y+270JtRjVx7v0Aw1aA0ZtnLIuX7kA+nInTNhWZa9mvHkvf72WigB LZxzhcUzGiaN7ptuam6jSwnPD/e4raA2PnR2aZg/WN/O2dCksfLltFpRKysMkx3fD0/K +h4Dd517ytThAPsP9jnx1oiOlXTpdHgKdlIVOWqBbVD1cxvrp4ANA/YKZM+i98qExIZO On0fktGJQONpUuJq8b0e/JzaKEsvkgqhNdpKhpxZIiqZNdVqtZJyrAE9Z8cNbNL0OVDz BbxA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=KcEqSGOsiXaPJ6jV34M5r6wl3qXeqxbsXAcm7tF7IxM=; b=TYMysycZyq7s6cqtDFR7rhUMZcQygQW6OtWrdIfrm8Pvd4MoI9a98BGb2vJvM/4OOk ljA6ViDcFyj2tVtBg2xOO3gbuo7VPfEoBZJZD5N8v1PnA2iH5Si9Qii8QkgVsUS8Mtvx 5UF7uJAC3TfjIK3XQWYRHSjWBwD4c3i5XiZtvSxNCO66QhViOzmvhFi0419NOZLXeqdg dCqTlYBWqLgQmtIBnAuz4E9eaGk4E1II1aSk4qCwbtaKwO1E7p29DPPDP1YtzSdCzeml /V/4Nqd0D2UNvDU/ZVwX1ViOjlmCoi6+rgC+cL8SOc5aBitqZiMFZy9AfiUwJ8m/6xFu PaEg== X-Gm-Message-State: AOAM530vw2kVn4Kq02IXPGKR+tuXl52JqVALuZC2/aKZo1IZes7302F4 l9eI118br+X82conJktEPUL/StDX2nCFrg== X-Google-Smtp-Source: ABdhPJwf3BU+caMVAPVP7X5I+zy3AeEIL8PFRyxhblemIyOpju6eIH7Xu7ltCGNwwI/8lVs4Vf9XFw== X-Received: by 2002:adf:f143:: with SMTP id y3mr3450880wro.138.1607529151564; Wed, 09 Dec 2020 07:52:31 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b7sm4424495wrv.47.2020.12.09.07.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Dec 2020 07:52:30 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Anders Waldenborg , christian.couder@gmail.com, peff@peff.net, jonathantanmy@google.com, Hariom Verma , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 5/5] pretty format %(trailers): add a "key_value_separator" Date: Wed, 9 Dec 2020 16:52:08 +0100 Message-Id: <20201209155208.17782-6-avarab@gmail.com> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8 In-Reply-To: <20201206002449.31452-1-avarab@gmail.com> References: <20201206002449.31452-1-avarab@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a "key_value_separator" option to the "%(trailers)" pretty format, to go along with the existing "separator" argument. In combination these two options make it trivial to produce machine-readable (e.g. \0 and \0\0-delimited) format output. As elaborated on in a previous commit which added "keyonly" it was needlessly tedious to extract structured data from "%(trailers)" before the addition of this "key_value_separator" option. As seen by the test being added here extracting this data now becomes trivial. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/pretty-formats.txt | 4 ++++ pretty.c | 9 +++++++++ t/t4205-log-pretty-formats.sh | 33 ++++++++++++++++++++++++++++++++ trailer.c | 11 ++++++++--- trailer.h | 1 + 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 5eac36500d4..6b59e28d444 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -284,6 +284,10 @@ option is given with no value, it's enabled. `%(trailers:only,unfold=true)` unfolds and shows all trailer lines. ** 'keyonly[=]': only show the key part of the trailer. ** 'valueonly[=]': only show the value part of the trailer. +** 'key_value_separator=': specify a separator inserted between + trailer lines. When this option is not given each trailer key-value + pair is separated by ": ". Otherwise it shares the same semantics + as 'separator=' above. NOTE: Some placeholders may depend on other options given to the revision traversal engine. For example, the `%g*` reflog options will diff --git a/pretty.c b/pretty.c index 1237ee0e45d..05eef7fda0b 100644 --- a/pretty.c +++ b/pretty.c @@ -1418,6 +1418,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT; struct string_list filter_list = STRING_LIST_INIT_NODUP; struct strbuf sepbuf = STRBUF_INIT; + struct strbuf kvsepbuf = STRBUF_INIT; size_t ret = 0; opts.no_divider = 1; @@ -1449,6 +1450,14 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ strbuf_expand(&sepbuf, fmt, strbuf_expand_literal_cb, NULL); free(fmt); opts.separator = &sepbuf; + } else if (match_placeholder_arg_value(arg, "key_value_separator", &arg, &argval, &arglen)) { + char *fmt; + + strbuf_reset(&kvsepbuf); + fmt = xstrndup(argval, arglen); + strbuf_expand(&kvsepbuf, fmt, strbuf_expand_literal_cb, NULL); + free(fmt); + opts.key_value_separator = &kvsepbuf; } else if (!match_placeholder_bool_arg(arg, "only", &arg, &opts.only_trailers) && !match_placeholder_bool_arg(arg, "unfold", &arg, &opts.unfold) && !match_placeholder_bool_arg(arg, "keyonly", &arg, &opts.key_only) && diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 4c9f6eb7946..749bc1431ac 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -776,6 +776,39 @@ test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separa test_cmp expect actual ' +test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' + git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && + ( + printf "XSigned-off-by\0A U Thor \n" && + printf "Acked-by\0A U Thor \n" && + printf "[ v2 updated patch description ]\n" && + printf "Signed-off-by\0A U Thor\n \nX" + ) >expect && + test_cmp expect actual +' + +test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' + git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && + ( + printf "XSigned-off-by\0A U Thor \n" && + printf "Acked-by\0A U Thor \n" && + printf "[ v2 updated patch description ]\n" && + printf "Signed-off-by\0A U Thor \nX" + ) >expect && + test_cmp expect actual +' + +test_expect_success 'pretty format %(trailers:separator,key_value_separator) changes both separators' ' + git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual && + ( + printf "Signed-off-by\0\0A U Thor \0" && + printf "Acked-by\0\0A U Thor \0" && + printf "[ v2 updated patch description ]\0" && + printf "Signed-off-by\0\0A U Thor " + ) >expect && + test_cmp expect actual +' + test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' ' git commit --allow-empty -F - <<-\EOF && Important fix diff --git a/trailer.c b/trailer.c index 889b419a4f6..249ed618ed8 100644 --- a/trailer.c +++ b/trailer.c @@ -1132,7 +1132,8 @@ static void format_trailer_info(struct strbuf *out, /* If we want the whole block untouched, we can take the fast path. */ if (!opts->only_trailers && !opts->unfold && !opts->filter && - !opts->separator && !opts->key_only && !opts->value_only) { + !opts->separator && !opts->key_only && !opts->value_only && + !opts->key_value_separator) { strbuf_add(out, info->trailer_start, info->trailer_end - info->trailer_start); return; @@ -1155,8 +1156,12 @@ static void format_trailer_info(struct strbuf *out, strbuf_addbuf(out, opts->separator); if (!opts->value_only) strbuf_addbuf(out, &tok); - if (!opts->key_only && !opts->value_only) - strbuf_addstr(out, ": "); + if (!opts->key_only && !opts->value_only) { + if (opts->key_value_separator) + strbuf_addbuf(out, opts->key_value_separator); + else + strbuf_addstr(out, ": "); + } if (!opts->key_only) strbuf_addbuf(out, &val); if (!opts->separator) diff --git a/trailer.h b/trailer.h index d2f28776be6..795d2fccfd9 100644 --- a/trailer.h +++ b/trailer.h @@ -74,6 +74,7 @@ struct process_trailer_options { int key_only; int value_only; const struct strbuf *separator; + const struct strbuf *key_value_separator; int (*filter)(const struct strbuf *, void *); void *filter_data; };