From patchwork Sun Aug 20 08:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 573A8EE49A4 for ; Sun, 20 Aug 2023 08:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229863AbjHTI75 (ORCPT ); Sun, 20 Aug 2023 04:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjHTI7z (ORCPT ); Sun, 20 Aug 2023 04:59:55 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA457EB for ; Sun, 20 Aug 2023 01:54:55 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2b9f0b7af65so35895541fa.1 for ; Sun, 20 Aug 2023 01:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521694; x=1693126494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EBMBVz9B3urlga6E/UoMxF9IsOvCHCm5LUq29VAOYco=; b=Iy8LhJEJeufrFw8MDhnNJwXZ5NdgVrPoyc8UXPdC1oqiNgrwancWvKbko5vt4i08ou PVUka08wDK5WXLdVBxRjebJNpFqfXu6d+eyJzoW+6ZrKdS+/6rMiRK5JaKn9e7l8cRxk 0FiP74E3Gnd4wwUxMtxzSIzpwEt70a0DAlE4f650vN61xbpLVTrel+aomU3JI7WZcP6e ecgkx44mHrF0SoDmGZJ6ZiPM/zTrx01PJoYyN9Lo1B3BSkRFRZM/oD8Ion6tvYaVnR5k JTffa1flYYUGdZD9C5YVjtTFXOyJAZjtARO5QzaMi1OJSErTpvp96Y0bk/Ff41DTtIv5 FuYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521694; x=1693126494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EBMBVz9B3urlga6E/UoMxF9IsOvCHCm5LUq29VAOYco=; b=Q5PQ9uHBhA7i7Jc1xlk9FTqUQxUuInUI4A9/N3bWBBN7fZaP8EQfEM/e4y0BeO3f/z x9sJDnK0+2s+hP1vqkakXItF826E2tB9Ks4bv7+pLcy3b/8qoMhSDc/NRqKKoBsQN8vb 3/iubMeEVvr08ObAhmQwOqSvmxfCqPfVXxql5PkFR5yA0Qzne60dDNNKziNTj2+jRhCX 7XiZZvDlq0v73aEcwbMy+OlCaJjh9JCn1gQl64gjzezJYNJYboO6CLY0vgHYvXv1m3OD vKBALYcnuVWrN+xkaL32zkRooTm1gVCCwj6LwF1JgHsRRN9HUfZ20RpkwEB9MLb16HkS DdIw== X-Gm-Message-State: AOJu0YxjiMBs8rH9NA+Ve09NaF3wNSzG0nbZstdTcCn8gDGEVPbbBTQR ujWKv8ZwvrTp5SX9odGDYhMAf2T12G9uO6FZ X-Google-Smtp-Source: AGHT+IGFxU7Y7hZanoVhc8iH4jMPWHka4JXmTMfHaf1PCFx25OhmZUDhvGXmMyKKNO2zph5FOk3gQA== X-Received: by 2002:a2e:8295:0:b0:2bb:aaec:abad with SMTP id y21-20020a2e8295000000b002bbaaecabadmr2579804ljg.30.1692521693592; Sun, 20 Aug 2023 01:54:53 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:53 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 1/8] pretty-formats: define "literal formatting code" Date: Sun, 20 Aug 2023 09:53:29 +0100 Message-ID: <20230820085336.8615-2-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Junio C Hamano The description for a %(trailer) option already uses this term without having a definition anywhere in the document, and we are about to add another one in %(decorate) that uses it. Signed-off-by: Junio C Hamano Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 3b71334459..5e1432951b 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -122,7 +122,9 @@ The placeholders are: - Placeholders that expand to a single literal character: '%n':: newline '%%':: a raw '%' -'%x00':: print a byte from a hex code +'%x00':: '%x' followed by two hexadecimal digits is replaced with a + byte with the hexadecimal digits' value (we will call this + "literal formatting code" in the rest of this document). - Placeholders that affect formatting of later placeholders: '%Cred':: switch color to red From patchwork Sun Aug 20 08:53:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7566EE49A4 for ; Sun, 20 Aug 2023 09:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbjHTI75 (ORCPT ); Sun, 20 Aug 2023 04:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjHTI74 (ORCPT ); Sun, 20 Aug 2023 04:59:56 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EFAAEC for ; Sun, 20 Aug 2023 01:54:56 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3feddbb670cso11111495e9.3 for ; Sun, 20 Aug 2023 01:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521695; x=1693126495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SjONEozaizDuIj7r8Z8I6bm4as5NrbCS2U96FB17dbk=; b=VXLElxbeIqd9xyUULlXHyU6mc0yseyzY3De9o9A01RG+aIIfCU6m8Z/rMVb2jrNS/8 zsciPVZmDID0LZ6nVjZMHndMCdxVuxJ9dlkLR6DRK9Lh8C4Zl6y2/PG5qlAHrCp0nvv8 pMkplI16ovS3oT3mybaLaOhZSd5s5IzGBN5WHX2ypxoi8CUDAdtclTMaZj/2XlgDmHPS AOX+HFraBC3DBAJG5nZFsn0aZe7eHRfPsrswNh0JHBRBYtgcbLYiWGzSds7PtKShNVyB bdWbQU1gm096HFi6st87dJxM7viAicsvpKqNhkZW++hl2YPNKjPr+qRC/JmYks4NRi+T nHjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521695; x=1693126495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SjONEozaizDuIj7r8Z8I6bm4as5NrbCS2U96FB17dbk=; b=dHcLabH9Bz8jZUm83Y6zW+7pa4t/1ioDZnxzEXM+LD9lJgNLFRBPzp8Z1Qmx3cKl5E 4Btv8efr6XEy0gHi178veB2XwrYdzqlzTKL2V8tNJvSDwQygHKK01K9qV2sKeP3NYP7o UW7ay6hekiDcZASsX9BWrHV0q71ykYDa2/iKFKQhHljlNfAkT2laQXFyIhcwwF1CP4tN oVvcQAkdJYMWP44Py5F3LDF3N2VpIv8xCIMOt9Fittf0TmSWTh5Dy7tIFA3rwyspnNTd hedGdP2b2nEZ0Y2E2BlFq3UTluQ8Bx6tSUynT/Re2xPwVsoZ9jYlB6zOVHoOV5foI9Iw 4zGQ== X-Gm-Message-State: AOJu0YyqQCJ4bAR7QJeHDby1o0TjU1+233agoNrhYsBM5Cma/voN9eat jBQAqGV/Rx5np2KPg6rimNOrA23erWHoTHEu X-Google-Smtp-Source: AGHT+IFE0nV4xPJ9fRyxAPmGAj7OyUGM900fia8ux0Nl824Evsod914KqrlQIv3eJl7ybjE01ogbmw== X-Received: by 2002:a7b:c051:0:b0:3fc:a49:4c05 with SMTP id u17-20020a7bc051000000b003fc0a494c05mr2495925wmc.40.1692521694397; Sun, 20 Aug 2023 01:54:54 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:54 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 2/8] pretty-formats: enclose options in angle brackets Date: Sun, 20 Aug 2023 09:53:30 +0100 Message-ID: <20230820085336.8615-3-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Enclose the 'options' placeholders in the %(describe) and %(trailers) format specifiers in angle brackets to clarify that they are placeholders rather than keywords. Also remove the indentation from their descriptions, instead of increasing it to account for the extra two angle bracket in the headings. The indentation isn't required by asciidoc, it doesn't reflect how the output text is formatted, and it's inconsistent with the following bullet points that are at the same level in the output. Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 5e1432951b..851a9878e6 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -224,13 +224,11 @@ The placeholders are: linkgit:git-rev-list[1]) '%d':: ref names, like the --decorate option of linkgit:git-log[1] '%D':: ref names without the " (", ")" wrapping. -'%(describe[:options])':: human-readable name, like - linkgit:git-describe[1]; empty string for - undescribable commits. The `describe` string - may be followed by a colon and zero or more - comma-separated options. Descriptions can be - inconsistent when tags are added or removed at - the same time. +'%(describe[:])':: +human-readable name, like linkgit:git-describe[1]; empty string for +undescribable commits. The `describe` string may be followed by a colon and +zero or more comma-separated options. Descriptions can be inconsistent when +tags are added or removed at the same time. + ** 'tags[=]': Instead of only considering annotated tags, consider lightweight tags as well. @@ -283,13 +281,11 @@ endif::git-rev-list[] '%gE':: reflog identity email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1]) '%gs':: reflog subject -'%(trailers[:options])':: display the trailers of the body as - interpreted by - linkgit:git-interpret-trailers[1]. The - `trailers` string may be followed by a colon - and zero or more comma-separated options. - If any option is provided multiple times the - last occurrence wins. +'%(trailers[:])':: +display the trailers of the body as interpreted by +linkgit:git-interpret-trailers[1]. The `trailers` string may be followed by +a colon and zero or more comma-separated options. If any option is provided +multiple times, the last occurrence wins. + ** 'key=': only show trailers with specified . Matching is done case-insensitively and trailing colon is optional. If option is From patchwork Sun Aug 20 08:53:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E06BEEE49A5 for ; Sun, 20 Aug 2023 09:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbjHTJAD (ORCPT ); Sun, 20 Aug 2023 05:00:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjHTJAA (ORCPT ); Sun, 20 Aug 2023 05:00:00 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6BF1ED for ; Sun, 20 Aug 2023 01:54:56 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fee843b44cso5764105e9.1 for ; Sun, 20 Aug 2023 01:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521695; x=1693126495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5zcDsuRavCDviLGOuatKVm+MWPqvnjvYjWGbxy09WDg=; b=Tsn4XqMzr5aTXBXm/4GnbkhjfI+/K5Fl+IxItS0tgqROCRtsgdmODvKvFYyfHiFgk1 ewmoP1ZxR4apWpygjd6FxZEeifEhb+EsLLAOLGM6LpGUQS7VxNfZOXlAs/JIj29TnMyi aGNg3LIpYfo/Oc7IV8/1lQWVIu6unCKUOi6hW/q97hHfAgO5WM+blckEoy8Ni+/2y0gl ppnzeH/6MT80DhFonsFC9tO42ugiOxdRbb4NSPvZGIcuBY2ES3jMJtc8I5G1teiKT+zv Pl12nm+BXNAcPlNtEdWBD43Cf93ggUTjxGonhcYGMT3TotAlkoA/AZE/mMDU+62fcpr9 v3KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521695; x=1693126495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5zcDsuRavCDviLGOuatKVm+MWPqvnjvYjWGbxy09WDg=; b=kdzc/XdlQYElCZ3eDTLNC2GbkDfhCCXeG2uwWKU9rIweH+5wlwZNHmLhYy8BAkMKQt Lo1LN1chWkGVPt72o47nTvbSJ9LBp1uUMg7HiOrkFFh8DmIYj/IcU69dw4yHmTdfkxgR bp33G2bILLoWGiBbpzK1RyyqvibczbTJ5v4KsMEe4eufNv3hkETcFlovQc4QwgT63XEf k1Q4GUW2eLSWqV+x0gD7qn6/8UiwEK1XrIXiTa68SzrK6TqJg/mIkVAWKrLUwIGa6G4a CcPcd5F7Yk1CcR8uHIVLmXPMHSiWXwwatkUYUZ4eDni58S9E48hERyOUHp0puWfK2BX2 8orQ== X-Gm-Message-State: AOJu0Ywij9yu6AUtAJPQ5atAEGIgRwAHVXpDrrmnvIe5r2Bk/SF76rfk gXjh0zJ7KA5ho1cRmPVpOkyZr072Zt+BYTAj X-Google-Smtp-Source: AGHT+IFA1WLbsiMWQD9JmByfqrszI7C5teHcxxKHmF3PF+ZAC2XWytae2cyv/XuQ8TBkUJoxGP66Wg== X-Received: by 2002:a05:600c:2296:b0:3fe:4e4e:beeb with SMTP id 22-20020a05600c229600b003fe4e4ebeebmr2850967wmf.38.1692521695223; Sun, 20 Aug 2023 01:54:55 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:54 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 3/8] decorate: refactor format_decorations() Date: Sun, 20 Aug 2023 09:53:31 +0100 Message-ID: <20230820085336.8615-4-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the format_decorations_extended function to format_decorations and drop the format_decorations wrapper macro. Pass the prefix, suffix and separator strings as a single 'struct format_decorations' pointer argument instead of separate arguments. Use default values defined in the function when either the struct pointer or any of the struct fields are NULL. This is to ease extension with additional options. Signed-off-by: Andy Koppe --- log-tree.c | 23 +++++++++++++++++------ log-tree.h | 15 ++++++++------- pretty.c | 6 ++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/log-tree.c b/log-tree.c index 208c69cbb7..cd12c26c29 100644 --- a/log-tree.c +++ b/log-tree.c @@ -303,14 +303,12 @@ static void show_name(struct strbuf *sb, const struct name_decoration *decoratio /* * The caller makes sure there is no funny color before calling. - * format_decorations_extended makes sure the same after return. + * format_decorations ensures the same after return. */ -void format_decorations_extended(struct strbuf *sb, +void format_decorations(struct strbuf *sb, const struct commit *commit, int use_color, - const char *prefix, - const char *separator, - const char *suffix) + const struct decoration_options *opts) { const struct name_decoration *decoration; const struct name_decoration *current_and_HEAD; @@ -319,10 +317,23 @@ void format_decorations_extended(struct strbuf *sb, const char *color_reset = decorate_get_color(use_color, DECORATION_NONE); + const char *prefix = " ("; + const char *suffix = ")"; + const char *separator = ", "; + decoration = get_name_decoration(&commit->object); if (!decoration) return; + if (opts) { + if (opts->prefix) + prefix = opts->prefix; + if (opts->suffix) + suffix = opts->suffix; + if (opts->separator) + separator = opts->separator; + } + current_and_HEAD = current_pointed_by_HEAD(decoration); while (decoration) { /* @@ -370,7 +381,7 @@ void show_decorations(struct rev_info *opt, struct commit *commit) } if (!opt->show_decorations) return; - format_decorations(&sb, commit, opt->diffopt.use_color); + format_decorations(&sb, commit, opt->diffopt.use_color, NULL); fputs(sb.buf, opt->diffopt.file); strbuf_release(&sb); } diff --git a/log-tree.h b/log-tree.h index bdb6432815..14898de8ac 100644 --- a/log-tree.h +++ b/log-tree.h @@ -13,17 +13,18 @@ struct decoration_filter { struct string_list *exclude_ref_config_pattern; }; +struct decoration_options { + char *prefix; + char *suffix; + char *separator; +}; + int parse_decorate_color_config(const char *var, const char *slot_name, const char *value); int log_tree_diff_flush(struct rev_info *); int log_tree_commit(struct rev_info *, struct commit *); void show_log(struct rev_info *opt); -void format_decorations_extended(struct strbuf *sb, const struct commit *commit, - int use_color, - const char *prefix, - const char *separator, - const char *suffix); -#define format_decorations(strbuf, commit, color) \ - format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")") +void format_decorations(struct strbuf *sb, const struct commit *commit, + int use_color, const struct decoration_options *opts); void show_decorations(struct rev_info *opt, struct commit *commit); void log_write_email_headers(struct rev_info *opt, struct commit *commit, const char **extra_headers_p, diff --git a/pretty.c b/pretty.c index 718530bbab..24fb82a5a2 100644 --- a/pretty.c +++ b/pretty.c @@ -1537,10 +1537,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ strbuf_addstr(sb, get_revision_mark(NULL, commit)); return 1; case 'd': - format_decorations(sb, commit, c->auto_color); + format_decorations(sb, commit, c->auto_color, NULL); return 1; case 'D': - format_decorations_extended(sb, commit, c->auto_color, "", ", ", ""); + format_decorations(sb, commit, c->auto_color, + &(struct decoration_options){.prefix = "", + .suffix = ""}); return 1; case 'S': /* tag/branch like --source */ if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources)) From patchwork Sun Aug 20 08:53:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E23A0EE49AA for ; Sun, 20 Aug 2023 09:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbjHTJAD (ORCPT ); Sun, 20 Aug 2023 05:00:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjHTJAB (ORCPT ); Sun, 20 Aug 2023 05:00:01 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC8AEE for ; Sun, 20 Aug 2023 01:54:57 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-318015ade49so2111569f8f.0 for ; Sun, 20 Aug 2023 01:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521696; x=1693126496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=O968/4XngqdSXUyum7jeMBHfaf+NuJRfQHdS2BxZ3nk=; b=gEf/ysbe9XdZlwGJvJZNNRH6IMKj2pb+UqM7NRzocNrsxT0sDSTc/7RrWvLNcZHO7k qKtkComwiizHeCF/ZVM1awRaC7hBMTqWUGqjLablkgroRuYX9d7+Jm3jAYywHoix7d8t s9ALCHdhBlnGDkSrLQX7sY1Ydhr3mYGUbDPAtvmmZShGufcvRLJ5p0uDy7joos/9rZkE yqsL2emPtvGXLh0o75n89VEtqS/ldnw0m7T0lu5YeNqAO/lu0nbgtcBpwAC4szmLiUQQ IyO/oYAWa8hwcKvlOOeY/jyJu6LBJTxyVCW1N2Ij2SQ35DfyhB99DzRvIGkUgdSdTm/Q uxRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521696; x=1693126496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O968/4XngqdSXUyum7jeMBHfaf+NuJRfQHdS2BxZ3nk=; b=cVeyq967IxR4Cga2ZHTJ6YedrsK9Cj9WXO/lfGPTITWXwRkECWZxl0xuUCQu1Ba9LP /5Np7qJFb+u1lY8NDZ1QL57N3EMP0Bcjfzf8xaqKbOCw5IAM1tG0Jru+oR9akvkdmEsN y2ct7DcR9cA96zauPL1DsRajib3NdRbRsaivIuIvQ1h/+w03cv4hrWvN7EORsye2afjx q14YkK5g3xSAXfgNLc2B6/+SUS3q8FYhyTkXG5TWyQVOu7+beSZ3pn3eevgz/wZyVoHv L65nB91crIQEw9Ia79O+5aPA/lSVhC4ZP6yf0LF9+7kGyo4PtLp9KfcZFSXmX7PzJo2J It9g== X-Gm-Message-State: AOJu0YyBzx8wgy5JCy8Dn7kKN4Wl5JCsAsVzRl4Yq+hkdmISi91VkL0J lXj3V8LIb3cAxTIYxt2u6Cg5/v6XVnzHefTm X-Google-Smtp-Source: AGHT+IEMLGxUdI7nmLwK35IqB1GzY29XMQRfBCcHitD4wH+TBylVj6DM0Pemx8wKM1TNt9MEIEMKEg== X-Received: by 2002:a05:6000:187:b0:319:6b8f:8473 with SMTP id p7-20020a056000018700b003196b8f8473mr2387868wrx.29.1692521695908; Sun, 20 Aug 2023 01:54:55 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:55 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 4/8] decorate: avoid some unnecessary color overhead Date: Sun, 20 Aug 2023 09:53:32 +0100 Message-ID: <20230820085336.8615-5-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In format_decorations(), don't obtain color sequences if there are no decorations, and don't emit color sequences around empty strings. Signed-off-by: Andy Koppe --- log-tree.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/log-tree.c b/log-tree.c index cd12c26c29..7c6d3f1ac3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -312,10 +312,7 @@ void format_decorations(struct strbuf *sb, { const struct name_decoration *decoration; const struct name_decoration *current_and_HEAD; - const char *color_commit = - diff_get_color(use_color, DIFF_COMMIT); - const char *color_reset = - decorate_get_color(use_color, DECORATION_NONE); + const char *color_commit, *color_reset; const char *prefix = " ("; const char *suffix = ")"; @@ -334,6 +331,9 @@ void format_decorations(struct strbuf *sb, separator = opts->separator; } + color_commit = diff_get_color(use_color, DIFF_COMMIT); + color_reset = decorate_get_color(use_color, DECORATION_NONE); + current_and_HEAD = current_pointed_by_HEAD(decoration); while (decoration) { /* @@ -342,9 +342,12 @@ void format_decorations(struct strbuf *sb, * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { - strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, prefix); - strbuf_addstr(sb, color_reset); + if (*prefix) { + strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, prefix); + strbuf_addstr(sb, color_reset); + } + strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); if (decoration->type == DECORATION_REF_TAG) strbuf_addstr(sb, "tag: "); @@ -364,9 +367,11 @@ void format_decorations(struct strbuf *sb, } decoration = decoration->next; } - strbuf_addstr(sb, color_commit); - strbuf_addstr(sb, suffix); - strbuf_addstr(sb, color_reset); + if (*suffix) { + strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, suffix); + strbuf_addstr(sb, color_reset); + } } void show_decorations(struct rev_info *opt, struct commit *commit) From patchwork Sun Aug 20 08:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEFA6EE49A8 for ; Sun, 20 Aug 2023 09:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjHTJAB (ORCPT ); Sun, 20 Aug 2023 05:00:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbjHTJAB (ORCPT ); Sun, 20 Aug 2023 05:00:01 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96826A2 for ; Sun, 20 Aug 2023 01:54:58 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2bcb89b4767so3118161fa.3 for ; Sun, 20 Aug 2023 01:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521697; x=1693126497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X7XFeevufjAjcE2XkTtR0tFM7aOlYpNqLsPQ1W9Wbzs=; b=RntkbZzIYRXt8WrHDk8gksoNyvOOFdH5CcPVsgP5TAnofbb2yezWaYm+jyqVLbrBB8 T9fBwVKtXuR97eIp9rvodluDaqOxLNFDEZik3UQ6tp+QMRAxWtjVQ5Et2rp+vaYN20E5 NZDTFh4/8J5Jmeq0odOLBrCMxRL0suggsN2YXEm6c3+xAyaZ/MCh9dM4fFkGzAd8rH75 xLyKlDvB/2PQhiLtGw2NF4inn9bIGVUc8hINuZifnn5bSld6b9WFNYUe0oxMvJ1KjcLR lg4yq2AEqNcWY2L8n8YhiPDwrH93KoqzIAKHJm/qAE+dX3OQIY6XhKUCWhjVq1PbuX/B aLxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521697; x=1693126497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X7XFeevufjAjcE2XkTtR0tFM7aOlYpNqLsPQ1W9Wbzs=; b=AbolgSAa4BG/zcXNEZODX/m6fFMilglyEOIJx42vQQIzMX0Cv494f/WqT5IfvbBH2O k5wqu9rsHrvLcWNBeR0ZqxUzHp5b3lg50tqqOUM5OkZUdXNCMPWGkDpC7sDXu7Tf8QI2 FSpT3gTSkRsDfzqd5OUhtXkW3EO8FW4IW3ThsaFlBhT1Z05091n9kn3bgg39yh3zTMxf 1+xWmNTCIe+gG4Rg6kP6sb+F4k6ROPWhvQLr4qeMbVNe0VnjsufocNJyvUt2WMC88AeK fdKY02EOcRYdbNHzUdW/HG/L60407bO5fZ5h0YXsg2kgxflSiG1PWHSPqHH1UtkN+bas wgcA== X-Gm-Message-State: AOJu0Yy62Mkjeq7HqfeEyVkdK+ABRIlAKgehlmuHzrHbsG+Q0GwKC4py L2De0lyDaA6pUq9T4153R0fuYyBKbOypFYb9 X-Google-Smtp-Source: AGHT+IETm5fpQRKZWPCvLKT2hMX3MnoiNaf+ZEI1RnbnQJrwALcBB6CGEHCNJwQeT42sosQynStzyg== X-Received: by 2002:a05:6512:3e9:b0:4ff:7046:984a with SMTP id n9-20020a05651203e900b004ff7046984amr2322028lfq.7.1692521696628; Sun, 20 Aug 2023 01:54:56 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:56 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 5/8] decorate: color each token separately Date: Sun, 20 Aug 2023 09:53:33 +0100 Message-ID: <20230820085336.8615-6-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Wrap "tag:" prefixes and the arrows in "HEAD -> branch" decorations in their own color sequences. Otherwise, if --graph is used, tag names or arrows can end up uncolored when %w width formatting breaks a line just before them. This is because --graph resets the color after doing its drawing at the start of a line. Amend test t4207-log-decoration-colors.sh accordingly. Signed-off-by: Andy Koppe --- log-tree.c | 14 +++++++--- t/t4207-log-decoration-colors.sh | 44 ++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/log-tree.c b/log-tree.c index 7c6d3f1ac3..44f4693567 100644 --- a/log-tree.c +++ b/log-tree.c @@ -342,26 +342,34 @@ void format_decorations(struct strbuf *sb, * appeared, skipping the entry for current. */ if (decoration != current_and_HEAD) { + const char *color = + decorate_get_color(use_color, decoration->type); + if (*prefix) { strbuf_addstr(sb, color_commit); strbuf_addstr(sb, prefix); strbuf_addstr(sb, color_reset); } - strbuf_addstr(sb, decorate_get_color(use_color, decoration->type)); - if (decoration->type == DECORATION_REF_TAG) + if (decoration->type == DECORATION_REF_TAG) { + strbuf_addstr(sb, color); strbuf_addstr(sb, "tag: "); + strbuf_addstr(sb, color_reset); + } + strbuf_addstr(sb, color); show_name(sb, decoration); + strbuf_addstr(sb, color_reset); if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { + strbuf_addstr(sb, color); strbuf_addstr(sb, " -> "); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); + strbuf_addstr(sb, color_reset); } - strbuf_addstr(sb, color_reset); prefix = separator; } diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index ded33a82e2..df804f38e2 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -53,15 +53,17 @@ cmp_filtered_decorations () { # to this test since it does not contain any decoration, hence --first-parent test_expect_success 'commit decorations colored correctly' ' cat >expect <<-EOF && - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \ -${c_reset}${c_branch}main${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B -${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A1${c_reset}${c_commit}, \ + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_HEAD} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B +${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_commit}, \ ${c_reset}${c_remoteBranch}other/main${c_reset}${c_commit})${c_reset} A1 - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_stash}refs/stash${c_reset}${c_commit})${c_reset} \ -On main: Changes to A.t - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_stash}refs/stash${c_reset}${c_commit})${c_reset} On main: Changes to A.t + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual && @@ -76,12 +78,14 @@ test_expect_success 'test coloring with replace-objects' ' git replace HEAD~1 HEAD~2 && cat >expect <<-EOF && - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \ -${c_reset}${c_branch}main${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: D${c_reset}${c_commit})${c_reset} D - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: C${c_reset}${c_commit}, \ + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_HEAD} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit})${c_reset} D + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}C${c_reset}${c_commit}, \ ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} B - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && @@ -100,13 +104,15 @@ test_expect_success 'test coloring with grafted commit' ' git replace --graft HEAD HEAD~2 && cat >expect <<-EOF && - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD -> \ -${c_reset}${c_branch}main${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: D${c_reset}${c_commit}, \ + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_HEAD} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit}, \ ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: v1.0${c_reset}${c_commit}, \ -${c_reset}${c_tag}tag: B${c_reset}${c_commit})${c_reset} B - ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_tag}tag: A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B + ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && From patchwork Sun Aug 20 08:53:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD999EE49A4 for ; Sun, 20 Aug 2023 09:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230151AbjHTJAE (ORCPT ); Sun, 20 Aug 2023 05:00:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbjHTJAB (ORCPT ); Sun, 20 Aug 2023 05:00:01 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F227C3 for ; Sun, 20 Aug 2023 01:54:59 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2bb97f2c99cso37287751fa.0 for ; Sun, 20 Aug 2023 01:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521697; x=1693126497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nlDb1U5K2a/xPp/A5ZZ4OQkHpGhsUqk1w6uwCHPZzC8=; b=mBP/o5hfazIx0jMcF+99aCnJI3hjmTf4JR5/Lt0LD2fbyjd3hZZJ8SHX0v7b/nDVLr BxSdP4E3ovuwDwO4HGJQm/rzTL8Lj0kQTzcpiHYCxRi/1PSJWEgZMb35lSGwS6uU0d0x 7Bbs69I3uVbOiwU4zJbzYT6efZW+MupbfDAF9ac4CA0K8gVm9+8bypRwNvcdBZyq+Px+ zAXLMaOCUy8cCC4SMWJct/O160KPTn3wiMgZQPzybUwE9vBhPP1MKrTLXMjtk/Dxcovq fArxXj6DPiHfWNavaCr0Vogu2RiMTVOzbzW8HyNNNV9G+wjt1NJT5NtHrtYg+9A1zVPR R6hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521697; x=1693126497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nlDb1U5K2a/xPp/A5ZZ4OQkHpGhsUqk1w6uwCHPZzC8=; b=f3VV9mHBWXVpzXHTKfnXmQQ6CyhZLnikX7opKJV9OK3w9kKZWwIuFU3+FX3qNne56u c+j2tkcqlo8LUqG9p+pUPU3HydgcebM9p2O+qABdodblb+wOmTLXMFUNRVg9osOASg6Q A4vD3grehv3HmWE1najtuSXliK5Sg9mg0l6qP/hZdG56hqaJw0uBIUYYursrOcvKXHl8 4Xv6eWW9BhAFe0YjfuEhFhVJ7Aj6aTWfKtxrPGteYOFy7X1RMIG32BGsONiUxLrdJ/0t C9VKR4aYOEBTQRwR41/ql0Bbqu+j596/KMXXThjImoaojdPI8PnPA47J+aIwE5urZjqs 5V8g== X-Gm-Message-State: AOJu0YzE+vaDwjmiRYyW2IuDJdXBEauSHFl/tHtJe8vy2M1fs5xsxQQd oQMdQ9707t5dmDO0Ylx5VsMVEvmSBDQMfWPU X-Google-Smtp-Source: AGHT+IFpMjvfN8Zp32US5eLnjolgvm72XINxUMCa1CQGVNVQwOhoHt+cswSZjWnSnQqVPOiK+MdGFg== X-Received: by 2002:a2e:9896:0:b0:2b9:e53f:e1fd with SMTP id b22-20020a2e9896000000b002b9e53fe1fdmr2973281ljj.34.1692521697390; Sun, 20 Aug 2023 01:54:57 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:57 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 6/8] pretty: add %(decorate[:]) format Date: Sun, 20 Aug 2023 09:53:34 +0100 Message-ID: <20230820085336.8615-7-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add %(decorate[:]) format that lists ref names similarly to the %d format, but which allows the otherwise fixed prefix, suffix and separator strings to be customized. Omitted options default to the strings used in %d. Rename expand_separator() function used to expand %x literal formatting codes to expand_string_arg(), as it is now used on strings other than separators. Examples: - %(decorate) is equivalent to %d. - %(decorate:prefix=,suffix=) is equivalent to %D. - %(decorate:prefix=[,suffix=],separator=%x3B) produces a list enclosed in square brackets and separated by semicolons. Test the format in t4205-log-pretty-formats.sh and document it in pretty-formats.txt. Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 10 +++++ pretty.c | 72 ++++++++++++++++++++++++++++---- t/t4205-log-pretty-formats.sh | 27 ++++++++++++ 3 files changed, 101 insertions(+), 8 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 851a9878e6..709d85af21 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -224,6 +224,16 @@ The placeholders are: linkgit:git-rev-list[1]) '%d':: ref names, like the --decorate option of linkgit:git-log[1] '%D':: ref names without the " (", ")" wrapping. +'%(decorate[:])':: +ref names with custom decorations. The `decorate` string may be followed by a +colon and zero or more comma-separated options. Option values may contain +literal formatting codes. These must be used for commas (`%x2C`) and closing +parentheses (`%x29`), due to their role in the option syntax. ++ +** 'prefix=': Shown before the list of ref names. Defaults to "{nbsp}`(`". +** 'suffix=': Shown after the list of ref names. Defaults to "`)`". +** 'separator=': Shown between ref names. Defaults to "`,`{nbsp}". + '%(describe[:])':: human-readable name, like linkgit:git-describe[1]; empty string for undescribable commits. The `describe` string may be followed by a colon and diff --git a/pretty.c b/pretty.c index 24fb82a5a2..1639efe2f8 100644 --- a/pretty.c +++ b/pretty.c @@ -1252,8 +1252,8 @@ static int format_trailer_match_cb(const struct strbuf *key, void *ud) return 0; } -static struct strbuf *expand_separator(struct strbuf *sb, - const char *argval, size_t arglen) +static struct strbuf *expand_string_arg(struct strbuf *sb, + const char *argval, size_t arglen) { char *fmt = xstrndup(argval, arglen); const char *format = fmt; @@ -1301,9 +1301,9 @@ int format_set_trailers_options(struct process_trailer_options *opts, opts->filter_data = filter_list; opts->only_trailers = 1; } else if (match_placeholder_arg_value(*arg, "separator", arg, &argval, &arglen)) { - opts->separator = expand_separator(sepbuf, argval, arglen); + opts->separator = expand_string_arg(sepbuf, argval, arglen); } else if (match_placeholder_arg_value(*arg, "key_value_separator", arg, &argval, &arglen)) { - opts->key_value_separator = expand_separator(kvsepbuf, argval, arglen); + opts->key_value_separator = expand_string_arg(kvsepbuf, argval, arglen); } 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) && @@ -1384,6 +1384,40 @@ static size_t parse_describe_args(const char *start, struct strvec *args) return arg - start; } + +static int parse_decoration_option(const char **arg, + const char *name, + char **opt) +{ + const char *argval; + size_t arglen; + + if (match_placeholder_arg_value(*arg, name, arg, &argval, &arglen)) { + struct strbuf sb = STRBUF_INIT; + + expand_string_arg(&sb, argval, arglen); + *opt = strbuf_detach(&sb, NULL); + return 1; + } + return 0; +} + +static void parse_decoration_options(const char **arg, + struct decoration_options *opts) +{ + while (parse_decoration_option(arg, "prefix", &opts->prefix) || + parse_decoration_option(arg, "suffix", &opts->suffix) || + parse_decoration_option(arg, "separator", &opts->separator)) + ; +} + +static void free_decoration_options(const struct decoration_options *opts) +{ + free(opts->prefix); + free(opts->suffix); + free(opts->separator); +} + static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ const char *placeholder, void *context) @@ -1540,10 +1574,15 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ format_decorations(sb, commit, c->auto_color, NULL); return 1; case 'D': - format_decorations(sb, commit, c->auto_color, - &(struct decoration_options){.prefix = "", - .suffix = ""}); - return 1; + { + const struct decoration_options opts = { + .prefix = "", + .suffix = "" + }; + + format_decorations(sb, commit, c->auto_color, &opts); + return 1; + } case 'S': /* tag/branch like --source */ if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources)) return 0; @@ -1640,6 +1679,23 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ return 2; } + if (skip_prefix(placeholder, "(decorate", &arg)) { + struct decoration_options opts = { NULL }; + size_t ret = 0; + + if (*arg == ':') { + arg++; + parse_decoration_options(&arg, &opts); + } + if (*arg == ')') { + format_decorations(sb, commit, c->auto_color, &opts); + ret = arg - placeholder + 1; + } + + free_decoration_options(&opts); + return ret; + } + /* For the rest we have to parse the commit header. */ if (!c->commit_header_parsed) { msg = c->message = diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index dd9035aa38..6ba399c5be 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -576,6 +576,33 @@ test_expect_success 'clean log decoration' ' test_cmp expected actual1 ' +test_expect_success 'pretty format %decorate' ' + git checkout -b foo && + git commit --allow-empty -m "new commit" && + git tag bar && + git branch qux && + + echo " (HEAD -> foo, tag: bar, qux)" >expect1 && + git log --format="%(decorate)" -1 >actual1 && + test_cmp expect1 actual1 && + + echo "HEAD -> foo, tag: bar, qux" >expect2 && + git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 && + test_cmp expect2 actual2 && + + echo "[ HEAD -> foo; tag: bar; qux ]" >expect3 && + git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B )" \ + -1 >actual3 && + test_cmp expect3 actual3 && + + # Try with a typo (in "separator"), in which case the placeholder should + # not be replaced. + echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && + git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ + -1 >actual4 && + test_cmp expect4 actual4 +' + cat >trailers < Acked-by: A U Thor From patchwork Sun Aug 20 08:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37187EE49A4 for ; Sun, 20 Aug 2023 09:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbjHTJAL (ORCPT ); Sun, 20 Aug 2023 05:00:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbjHTJAE (ORCPT ); Sun, 20 Aug 2023 05:00:04 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3E3DF5 for ; Sun, 20 Aug 2023 01:54:59 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-31c3df710bdso130062f8f.1 for ; Sun, 20 Aug 2023 01:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521698; x=1693126498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yK4dJKHnsgQTHz6D/V7urLIMYM3bYVHGa4CBQy0UjKc=; b=QeOsOi8q1055V+UGOKy0yf8uaoO24yPIkEfNd5PjYukmG1b/4/tyRUcyR5joHIKmk2 8Rz9DLWznBG8IBDQfBvaW02J8Fgjh0BWTmXZqEmHgAI14IuSqDnuFgBFh/56HtWu7Jyq mgUbPoLtajnBmi1X9CSQt1nlib5nlwsIWEk/atrl0CJDPs5rXh3TsQH9TWQhBUwSzkrG a883EFg4lFWDZ7iJ6i1d7TiTlIQQQDgTbl5zlKOdNY8PwCcmcjLbqzxNAtBtRo/Ljqnw PkzdjRmkz2F+3ltU/AEiG0STrT4GtovGcJhnYwcp2fY9JsgfwplVeyVYIJnFAZ8xJwmI 05Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521698; x=1693126498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yK4dJKHnsgQTHz6D/V7urLIMYM3bYVHGa4CBQy0UjKc=; b=K1EnayFZzSB2rQzZ6Wqsw2KCJn7v+i3nWHFPR1Ham9Nyj37gF6OsdkS9usW9KvnyNW 0sW+dK/oMnkKcJmbG9iZok4BT3GcA9+lEzh9WBhb1rgGjgGCRqEg6Aos8KNwpkP53SOX mg/uQ4cb4nhe150SLuqJ1aBi0z3ltE1SQybhfvS/w0YtzK9GotlWTvBEfd+3hxAHI+MZ WfQyVsvQ6NtKsj2ukw8dzGYRPe/LIxGm103D3ND84eAbLf2kjdqXeMp7+gqCeK+/tHo7 WdDYfOzR99F4TcXogjUQJ8NjdvykR1NDY7pX7iMEEQBIuMUC9xh4FOMxH9PmOMZTsj7L mmaA== X-Gm-Message-State: AOJu0Yzc7V+hN+qAJoP5U/NnQk0lg0tNv1uey+3IIRQklkctAthPlGZ1 U/dhlwb2vy86weWdUt7emXz+n2zrXq8wrGaS X-Google-Smtp-Source: AGHT+IGPLRPE8qe7cfUknurzsmifK+xJRuiZ6Lp2cVmnh/yNbn9LYatJBf+UbzTraer08X7EsFf7nQ== X-Received: by 2002:a5d:494c:0:b0:314:1ce9:3c86 with SMTP id r12-20020a5d494c000000b003141ce93c86mr2772105wrs.0.1692521698396; Sun, 20 Aug 2023 01:54:58 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:58 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 7/8] pretty: add pointer and tag options to %(decorate) Date: Sun, 20 Aug 2023 09:53:35 +0100 Message-ID: <20230820085336.8615-8-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add pointer and tag options to %(decorate) format, to allow to override the " -> " string used to show where HEAD points and the "tag: " string used to mark tags. Document in pretty-formats.txt and test in t4205-log-pretty-formats.sh. Signed-off-by: Andy Koppe --- Documentation/pretty-formats.txt | 9 +++++++++ log-tree.c | 12 +++++++++--- log-tree.h | 2 ++ pretty.c | 6 +++++- t/t4205-log-pretty-formats.sh | 7 ++++++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 709d85af21..d38b4ab566 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -233,6 +233,15 @@ parentheses (`%x29`), due to their role in the option syntax. ** 'prefix=': Shown before the list of ref names. Defaults to "{nbsp}`(`". ** 'suffix=': Shown after the list of ref names. Defaults to "`)`". ** 'separator=': Shown between ref names. Defaults to "`,`{nbsp}". +** 'pointer=': Shown between HEAD and the branch it points to, if any. + Defaults to "{nbsp}`->`{nbsp}". +** 'tag=': Shown before tag names. Defaults to "`tag:`{nbsp}". + ++ +For example, to produce decorations with no wrapping +or tag annotations, and spaces as separators: ++ +`%(decorate:prefix=,suffix=,tag=,separator= )` '%(describe[:])':: human-readable name, like linkgit:git-describe[1]; empty string for diff --git a/log-tree.c b/log-tree.c index 44f4693567..50b4850eda 100644 --- a/log-tree.c +++ b/log-tree.c @@ -317,6 +317,8 @@ void format_decorations(struct strbuf *sb, const char *prefix = " ("; const char *suffix = ")"; const char *separator = ", "; + const char *pointer = " -> "; + const char *tag = "tag: "; decoration = get_name_decoration(&commit->object); if (!decoration) @@ -329,6 +331,10 @@ void format_decorations(struct strbuf *sb, suffix = opts->suffix; if (opts->separator) separator = opts->separator; + if (opts->pointer) + pointer = opts->pointer; + if (opts->tag) + tag = opts->tag; } color_commit = diff_get_color(use_color, DIFF_COMMIT); @@ -351,9 +357,9 @@ void format_decorations(struct strbuf *sb, strbuf_addstr(sb, color_reset); } - if (decoration->type == DECORATION_REF_TAG) { + if (*tag && decoration->type == DECORATION_REF_TAG) { strbuf_addstr(sb, color); - strbuf_addstr(sb, "tag: "); + strbuf_addstr(sb, tag); strbuf_addstr(sb, color_reset); } @@ -364,7 +370,7 @@ void format_decorations(struct strbuf *sb, if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { strbuf_addstr(sb, color); - strbuf_addstr(sb, " -> "); + strbuf_addstr(sb, pointer); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); show_name(sb, current_and_HEAD); diff --git a/log-tree.h b/log-tree.h index 14898de8ac..41c776fea5 100644 --- a/log-tree.h +++ b/log-tree.h @@ -17,6 +17,8 @@ struct decoration_options { char *prefix; char *suffix; char *separator; + char *pointer; + char *tag; }; int parse_decorate_color_config(const char *var, const char *slot_name, const char *value); diff --git a/pretty.c b/pretty.c index 1639efe2f8..7f3abb676c 100644 --- a/pretty.c +++ b/pretty.c @@ -1407,7 +1407,9 @@ static void parse_decoration_options(const char **arg, { while (parse_decoration_option(arg, "prefix", &opts->prefix) || parse_decoration_option(arg, "suffix", &opts->suffix) || - parse_decoration_option(arg, "separator", &opts->separator)) + parse_decoration_option(arg, "separator", &opts->separator) || + parse_decoration_option(arg, "pointer", &opts->pointer) || + parse_decoration_option(arg, "tag", &opts->tag)) ; } @@ -1416,6 +1418,8 @@ static void free_decoration_options(const struct decoration_options *opts) free(opts->prefix); free(opts->suffix); free(opts->separator); + free(opts->pointer); + free(opts->tag); } static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 6ba399c5be..16626e4fe9 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -600,7 +600,12 @@ test_expect_success 'pretty format %decorate' ' echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ -1 >actual4 && - test_cmp expect4 actual4 + test_cmp expect4 actual4 && + + echo "HEAD->foo bar qux" >expect5 && + git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \ + -1 >actual5 && + test_cmp expect5 actual5 ' cat >trailers < X-Patchwork-Id: 13358717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F382EEE49A8 for ; Sun, 20 Aug 2023 09:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbjHTJAM (ORCPT ); Sun, 20 Aug 2023 05:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbjHTJAF (ORCPT ); Sun, 20 Aug 2023 05:00:05 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C3F3D2 for ; Sun, 20 Aug 2023 01:55:01 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3fe12baec61so22410985e9.2 for ; Sun, 20 Aug 2023 01:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692521700; x=1693126500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8qiqD3kvSXbgsPdz2fouf+93nbEh+ABrlnUBeqKFPJc=; b=h4p5bul2bwi89U3AqIp3dtGJqi4x0TwxHuPyosyVew2Vu/h7qYbrIm7EQAUHpIg+8m lHn3Lo8YEZVQ+UhbUocU6pN6GVZJjw9ETioV7uhlsIrz2Qken8rxUvLtenS0yTJuDArZ i3yUOFhH5g/4qf4aVWgTiYr9EAOVrx/okeAnpPoevR4bA3h/igIKmuvh623JEQuBZ9LM gfM7kOKssT6VWTHIcdG0pV7GIONPJnIouXHk7fRn2NgKJQLQiYdBEBi1OX8/ESuDCE90 6pl4dQfCVhRGHEL3Ey5LElz1o7VJbufGvDjk4ttephHnUPihTh6CFGzvKQ0lDlCfweTI aScA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692521700; x=1693126500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8qiqD3kvSXbgsPdz2fouf+93nbEh+ABrlnUBeqKFPJc=; b=GQT+IvrcZnv2gtHjdLoNUaVCbeqiMhA76JBZKKR5/we/jUlDlDxpGkVOzMcMX2IyX1 ySLwY/udClHQGN7iXyPwoXaoR0BzR87oLyZKSohU0epYppw2gbZfLcVTHSeDTu9V122q yDjjxXmQgErnfYOWXznuB7T0VhhWLpjzepSNv/ymL5wG3kmZ2Ibs0vsmv9hPcQ/Lqwh+ 3LVTwbmjUkPH5nDLPVw1URSkquV6wPNC3obIkzoNSwsS9mMSpFWgZ/JUtGBXPMLlfIbU drcH9AX9LvGgmjkHV0ZiJfA83hwPDqNByaTtvnDxmnQ3dj/LzE5x/hModLCi3oDP2bWL Xk5Q== X-Gm-Message-State: AOJu0YwngxvepjZ4I/33wX21rwdqkD1SlVsJTCxCL4aTBuKv16pARPda n7iFG4w36l7q/eO6p4kI2aCGNQ8+aWEGtqGV X-Google-Smtp-Source: AGHT+IHj9vDpmtVQoBgvlnpFi5ZXcHMMCjL/5eLmLH/eCVBXH8qswOJqwr5RcbODKrcci0b8lInjMg== X-Received: by 2002:a5d:66ce:0:b0:31a:d5fa:d710 with SMTP id k14-20020a5d66ce000000b0031ad5fad710mr2874139wrw.2.1692521699632; Sun, 20 Aug 2023 01:54:59 -0700 (PDT) Received: from localhost.localdomain (cpc105060-sgyl40-2-0-cust995.18-2.cable.virginm.net. [81.111.15.228]) by smtp.gmail.com with ESMTPSA id y15-20020adff6cf000000b0031759e6b43fsm8652539wrp.39.2023.08.20.01.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 01:54:59 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: gitster@pobox.com, glencbz@gmail.com, phillip.wood123@gmail.com, Andy Koppe Subject: [PATCH v4 8/8] decorate: use commit color for HEAD arrow Date: Sun, 20 Aug 2023 09:53:36 +0100 Message-ID: <20230820085336.8615-9-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820085336.8615-1-andy.koppe@gmail.com> References: <20230810211619.19055-1-andy.koppe@gmail.com> <20230820085336.8615-1-andy.koppe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use the commit color instead of the HEAD color for the arrow or custom symbol in "HEAD -> branch" decorations, for visual consistency with the prefix, separator and suffix symbols, which are also colored with the commit color. This change was triggered by the possibility that one could choose to use the same symbol for the pointer and the separator options in %(decorate), in which case they ought to be the same color. A related precedent is 'ls -l', where the arrow for symlinks gets the default color rather than that of the symlink name. Amend test t4207-log-decoration-colors.sh accordingly. Signed-off-by: Andy Koppe --- log-tree.c | 2 +- t/t4207-log-decoration-colors.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/log-tree.c b/log-tree.c index 50b4850eda..504da6b519 100644 --- a/log-tree.c +++ b/log-tree.c @@ -369,7 +369,7 @@ void format_decorations(struct strbuf *sb, if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { - strbuf_addstr(sb, color); + strbuf_addstr(sb, color_commit); strbuf_addstr(sb, pointer); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index df804f38e2..21986a866d 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -54,7 +54,7 @@ cmp_filtered_decorations () { test_expect_success 'commit decorations colored correctly' ' cat >expect <<-EOF && ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ -${c_HEAD} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ +${c_commit} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ ${c_reset}${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_commit}, \ ${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_commit})${c_reset} B ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ @@ -79,7 +79,7 @@ test_expect_success 'test coloring with replace-objects' ' cat >expect <<-EOF && ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ -${c_HEAD} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ +${c_commit} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ ${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit})${c_reset} D ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\ ${c_tag}tag: ${c_reset}${c_tag}C${c_reset}${c_commit}, \ @@ -105,7 +105,7 @@ test_expect_success 'test coloring with grafted commit' ' cat >expect <<-EOF && ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}${c_HEAD}HEAD${c_reset}\ -${c_HEAD} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ +${c_commit} -> ${c_reset}${c_branch}main${c_reset}${c_commit}, \ ${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_commit}, \ ${c_reset}${c_grafted}replaced${c_reset}${c_commit})${c_reset} D ${c_commit}COMMIT_ID${c_reset}${c_commit} (${c_reset}\