From patchwork Sun Aug 20 18:50:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358874 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 1D9FFEE4996 for ; Sun, 20 Aug 2023 18:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231598AbjHTSz5 (ORCPT ); Sun, 20 Aug 2023 14:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjHTSz5 (ORCPT ); Sun, 20 Aug 2023 14:55:57 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6E31E2 for ; Sun, 20 Aug 2023 11:50:54 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3fee87dd2a4so8626305e9.3 for ; Sun, 20 Aug 2023 11:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557453; x=1693162253; 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=SA/TaXUZE2TOeEBCGWSnn1NLG2ebCuhMaYGyBNe/zJZnOCEAlDTvy03XcUkIdn0Ng2 rmgM4a9SAR9ysEKWQMHgrgxuhu78Spwn/bxat5jzk76ftc/C1vRqFqj0ItG8+94RUl3e ZCNrV6Aqe1mtUcLWt1rb/doMojriutwkzyM+XHkAU59vBofRICQIL0X9S4g6RhthIkkb GpRCugRPSWaS6oOD2gxlPhTxvDS7pagoC4Ixpb+9+NKW/gwKX6ymBXQrPk5rpxhIJ+qS 3k20TXTo3F3j3LHuz8e2hTkq95d0fWAyoSCziuv1JpAyvGPxza2bAoX1UtBrH4JYCFjY /UCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557453; x=1693162253; 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=A8KVOD53BGHGXw+8G1s+OoXQqckfSERkfhRSET+oW2FxKYpG1453MBHhkH9RKDPWB+ wq12kyOAvdI2b15U3OLWFam5+B0SP9ZjA+b5HbgPDYE3NanQtcelXXxC8S/hJl6VI4Ao Y4Ipqd2KTCREbPz7Bog/SW5qlH0aUykybXBsYH2bCiLI/pPeLEOe8UdUUDllJ0ezRW5F ALNV/LgB8fj62VE0o/DTcP7dHlGBlAOOGGxQpAqrFeTVF1m1hy0sHHf9kq7Sh3VNlGVk dglxp/yWZAZGgjU2jqmwmbWnpwsxc9Hhs9uB4uNXEueTy8HAuUkhfGzfY4ONLyplouAH 5cuw== X-Gm-Message-State: AOJu0YwfY6lWRkBauym8FcPdC2wGS6aqEBLvWohW0waDBI94HgaAbnro 6N+8X/hFqvcaU/XxZ0NFM6FT+oSUnWVCjEkZ X-Google-Smtp-Source: AGHT+IEOMw7AhYIsYw97JQe091LOY1zSj+LGvHxDmGL297PMmCHvq0ZEQWaaZBu5msJmwzUxfJ9q1g== X-Received: by 2002:a7b:c7c3:0:b0:3f9:b748:ff37 with SMTP id z3-20020a7bc7c3000000b003f9b748ff37mr3648313wmk.20.1692557452785; Sun, 20 Aug 2023 11:50:52 -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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50:52 -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 v5 1/8] pretty-formats: define "literal formatting code" Date: Sun, 20 Aug 2023 19:50:02 +0100 Message-ID: <20230820185009.20095-2-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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 18:50:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358875 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 C6DD9EE49A6 for ; Sun, 20 Aug 2023 18:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbjHTSz6 (ORCPT ); Sun, 20 Aug 2023 14:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231520AbjHTSz5 (ORCPT ); Sun, 20 Aug 2023 14:55:57 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50AD1E6 for ; Sun, 20 Aug 2023 11:50:55 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3feddbb670cso14255315e9.3 for ; Sun, 20 Aug 2023 11:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557454; x=1693162254; 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=9lYFoyOUm0uyLgBBlBq5zA6dXDXi78CA769sfDWRkz0=; b=OvO+JR9na5Z3AMgsf4Bm+kOeWu53Ykb+l0pQ4APeCv+Io1o4BGNO8dvrUQlboPsruz Xx+cqikGmQekTYfh8AwWD68NfL48Xf425a0dxxTgGDzI1aAnQPuJcWxREgZFLrnx3e74 qFCdA5twuVlrJu8iJAT/fTE/8vGIuVbvJgZ29q007Lt7tHjbbhY4PmQAL4EAa9EwGfg1 qOEBLHc71HUb+1olF7+DQ8yg7kShlOulMMD0094kmTOZbz6YBPflfJD8cVNWpt+A6yEC E4nhLzAQr35z4HkCYLiu6/9qkrB/K2kslN9W4el3zNQax6O6oxTkwMsw7KMTHmeqGyoY 0VoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557454; x=1693162254; 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=9lYFoyOUm0uyLgBBlBq5zA6dXDXi78CA769sfDWRkz0=; b=Bp9XxRTcJgaEtyEU4pSIIdt+Z1ZEW5L83MNVFxwE0pAFMqtZ+HwIERPZFH5W4gzTof /G35UGlzXquZ3OOGqYVY+hCAEIFbKyCpi9GDUAZRlcH+bCk7hKFchXDBePUlAkt5ewlX CU9YUelJ0mS/jHLVCJXBIdttL5v//C+quWUnIobNVv6oqU3gifYmMPIZ3uQ/1SwfKKSH ANcLnSDD5oIUpSPFQmdghyW4zbZsu6K33ODujt8GD0HWFWOkE7SbPtz8N+m0Io143kad cPItFCBMo9d+nyHImSmgtyxTlDVhEJr6q20H/ylAgj8+AgNQUqjICUBcojkHB6kRHv2F Rb+w== X-Gm-Message-State: AOJu0YxYsRHYEtSrI/qjy97KfEVdDp6TUKuPrQE0hHxJa61hmKZQpMjF YtEFLljfK3lanX2+rxJx2P8tKgSBs/FmfXBn X-Google-Smtp-Source: AGHT+IEH2i2UKZ4lp0TEac/+8JgvqbS+Otrknkck1lO68s8GLMNeDVrLCFpEaKGhh4blI5dghUaQwg== X-Received: by 2002:a05:600c:2218:b0:3fe:2b8c:9f07 with SMTP id z24-20020a05600c221800b003fe2b8c9f07mr3426152wml.1.1692557453689; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 2/8] pretty-formats: enclose options in angle brackets Date: Sun, 20 Aug 2023 19:50:03 +0100 Message-ID: <20230820185009.20095-3-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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 documentation of 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 brackets 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 18:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358878 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 E58D2EE49AA for ; Sun, 20 Aug 2023 18:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231621AbjHTS4D (ORCPT ); Sun, 20 Aug 2023 14:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231603AbjHTSz6 (ORCPT ); Sun, 20 Aug 2023 14:55:58 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AE86E7 for ; Sun, 20 Aug 2023 11:50:56 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fe4cdb727cso25495385e9.0 for ; Sun, 20 Aug 2023 11:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557454; x=1693162254; 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=CrOMVlxSS+hsD2nF+STVoNfumEi0IMk1DCzOKFnrsRg=; b=JOyvJ8/hNSAnHZMY3v+O5/PT75N/Qo0kmP5O6Fmb3ysfMDIF6Q80EFINkASJ04+QL0 7UlB6fyIZQI8I12R80Z8mRR14Yzyg8BG7OoeArTz0PzXkpidWDzP9PIdjFyUB7r6sI/c oSGCYdtdnN69g21tU9q8ELWOnPkFFbB+ubmDOgF95uifPAIPKjSJAEqRWcV4OGuqp1MV dKKuCXeCP3CUtT5dnbsH+wlN538JF+K+HFrfWrPB9qeBLNtUXRwC5eLK+iXRGur8ZSg0 n3B/sPCWzjHQ6QSpg70kIkBHv+6Kg3M2yTg8cgQeN+6qEsyx0/ehJcSSa0EgHth4hsCm o21A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557454; x=1693162254; 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=CrOMVlxSS+hsD2nF+STVoNfumEi0IMk1DCzOKFnrsRg=; b=KZ2ptT8m6DUZivF9MoSe4CQPKZHTVzbnJQiR77wCvq557HpHv+QENyGwfQLU+vLOh9 KIQaywxPse6ovSFeyr0kivkSk+EucMECH2vNUbaPpMOTtx/sv2NGxP4n8wLpLF2X1J2X ehabQHoPO/Nm8f8paAxehn7rGhY51Pa85yt6LL6W75ASJaSTYBpX2XrrJU7wk0DQLYH2 9T4W5VqBrcpyV1eUVJAuBHCqk+ViDaCAYnZf3hB4ecuSYZ+OLjW3re6/IIV4fzAy7Ydk CcOybqiTQnlNj1UUsQRd0ND+xk10YhD72mGhtFdqPwOmn7P8xOskysr8xtfSJM/VQw7z JPLg== X-Gm-Message-State: AOJu0Yxn4ygYtWCYgKQZLrgSNLSAuQX/HZaRGLXZLgIpjnVshj1RR9SV fYzocbySHgppSoeNF6Pi2yyZhTfkecV192zI X-Google-Smtp-Source: AGHT+IEuKID/MYbukr3rk57uMsVRL2jtRDQz6t1bYQv0T2MKOmU3AHvSLAnGY9anAukF4DOtDmT3vQ== X-Received: by 2002:a05:600c:21cc:b0:3fb:b530:a4e4 with SMTP id x12-20020a05600c21cc00b003fbb530a4e4mr3856554wmj.8.1692557454370; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 3/8] decorate: refactor format_decorations() Date: Sun, 20 Aug 2023 19:50:04 +0100 Message-ID: <20230820185009.20095-4-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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 | 13 ++++++++++--- 3 files changed, 35 insertions(+), 16 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..69b6db3340 100644 --- a/pretty.c +++ b/pretty.c @@ -1537,11 +1537,18 @@ 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, "", ", ", ""); - 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; From patchwork Sun Aug 20 18:50:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358876 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 C074DEE49A5 for ; Sun, 20 Aug 2023 18:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231627AbjHTS4G (ORCPT ); Sun, 20 Aug 2023 14:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231520AbjHTSz7 (ORCPT ); Sun, 20 Aug 2023 14:55:59 -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 D752BEB for ; Sun, 20 Aug 2023 11:50:56 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fe2ba3e260so26151475e9.2 for ; Sun, 20 Aug 2023 11:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557455; x=1693162255; 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=YMuwgpc7feNX+p9pmPbLiKqjS3CBf0ITm2L1fN9w0uX6F5OF06YP7DGPSxew2l/+hw UGdWBSKT0xmQQn/egHEE4qbyQxrviLEPcB/7JqC3MY7Hc/mlMmS6AIBkmBXxdAgrYH6c MtYMCX5XiVPRoOXuPuKMFUwUdFRO46M1ed24Kc2vIg858gluYb6axy8SQY/DahjUt3dF VdYygtrYxuiRNZ1FA4UKb+kXjgkEDrSY39zRRDz2P+qZHeDHmYDA3NLk6HoWCjEzMZ8H Flf3mLv8IDM2FFwR2HNEIdxRi7+sx1R6pvQLND1+QDtg9Z+rOHqwj6dHpuFjYG7SMxAm Wbmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557455; x=1693162255; 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=Uz08ZUN0QSUY5Jglj8pnWWzIVwPwxGa9XVqmtXafPH72ED3CDg9cCOJAVZYtLI4oto f9e0kIR3a/TaJ4b5EuTAjP/9pdMgFo/DJ97zK1f+GDy5KTtIabHAHO0W0dAQRxdTWdB1 w+gdVUd23LtSHols4qu6o9fdRhHZUelCkpp8tOpO15LOMONGkymBbXz88acJleOeG5nB medpegumUYwwbx4irvpiT8lisNUGfdNeU50UgKojQdZoRyMmscGq51xME33kADtu6LM6 Dv6cnjW72uQ+vAbwCkAGytGXHd2Y9Tn65jIJnSdlMf9QzS9rkzYbQWOiwErzgF6apmAf BToA== X-Gm-Message-State: AOJu0YzqOhZGvtg5QnpwQHQZsCeDfaGaIx9P4uylkxYDmsDL4tgxvXmZ C1U4PJcWZ+7GnV1mawPxlCpyN3N6RPDQcR7H X-Google-Smtp-Source: AGHT+IEfIbghxK17bQN9TwGotLrBw8i58dAakxOU9u7KFqiXqc2NkmHsRyhiwrF0fUduhfaOW2tpMg== X-Received: by 2002:a05:600c:2807:b0:3fd:30f7:2be1 with SMTP id m7-20020a05600c280700b003fd30f72be1mr3247284wmb.39.1692557455091; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 4/8] decorate: avoid some unnecessary color overhead Date: Sun, 20 Aug 2023 19:50:05 +0100 Message-ID: <20230820185009.20095-5-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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 18:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358877 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 A9339EE4996 for ; Sun, 20 Aug 2023 18:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbjHTS4E (ORCPT ); Sun, 20 Aug 2023 14:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231605AbjHTSz7 (ORCPT ); Sun, 20 Aug 2023 14:55:59 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B242EE for ; Sun, 20 Aug 2023 11:50:57 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fee51329feso7029225e9.0 for ; Sun, 20 Aug 2023 11:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557456; x=1693162256; 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=WEPn/dI/imrvm8s78VpFdxRVTtUQZfF17aJrxknxQHSoYg80W07usvrCJUNLgK0u0R nP4+I98/ljdZNI8x/tjRxQiA1HcBszuMV0PL5hJMFvmNjXBxAhpyJl/do3Q2StPbPtGA ATxc3Jt984jEM+k7zat5ohyCzcSMafvXt6EMI01P1zNnIjJHsfJDW0FSZScq2I1n84X/ d6qh5ZYkdz9Ng+MNJFcBce06qpJpqCFV3JPwT6EdWrO+D5vHamUAmVMpDmBTGcioJVtG 0CGR/yqEJf/89xpA4SQouG9/bZFUg0lglYfaIi8iAt9MqHrP+lZtAjw7Rfz5fb74IAQz qiag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557456; x=1693162256; 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=WuWfch7cAZ96NWwUy9K/UrWO3joL0Kym7mi7FIz/9iGwYsS7eXtz4b6fqRFyxwdXQo DoO37so3XQV8lEKMndio/Nijahtim2oy60lqxH+A0APaqcNYe9VkgboZleGw3SzmwC4b aAbX9a6corL7QbmKV0c1NcDLyac2t6ScjLGx9zltEOZreIwaUpe9Sg4ZRCNYUNpVaPg6 4hDt3cOGXlJNWD/EoatQ+1oHLqAbSwmK/OyWWFra56AyuJzpidftO6E3Hm55J5Yjzu7K 2dNtbDKkoBqYQN3Ief7l0An2Qwz8KfVRrjA6JntnFVIG3K2GEoGeQUs194U5af1Q3wzw O8Gw== X-Gm-Message-State: AOJu0YyLYV0pYl98nsK8FddEckizU98CwVYdntKaXIwWJmb1LdMKqaRl Pysr/8su0idnHOIOiNtqjxYY/AVe1f02niNO X-Google-Smtp-Source: AGHT+IFBWLi18O7NWRkwEYHNweBnUo6VRuVJjszW4hBcGPoJbrlWoJftfF95+ibFUTihTBh+OJNG8g== X-Received: by 2002:a7b:c38a:0:b0:3fe:215e:44a0 with SMTP id s10-20020a7bc38a000000b003fe215e44a0mr3630716wmj.18.1692557455744; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 5/8] decorate: color each token separately Date: Sun, 20 Aug 2023 19:50:06 +0100 Message-ID: <20230820185009.20095-6-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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 18:50:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358880 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 CFEFEEE49A8 for ; Sun, 20 Aug 2023 18:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231625AbjHTS4F (ORCPT ); Sun, 20 Aug 2023 14:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231610AbjHTS4A (ORCPT ); Sun, 20 Aug 2023 14:56:00 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B67FF0 for ; Sun, 20 Aug 2023 11:50:58 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fe9c20f449so25032665e9.3 for ; Sun, 20 Aug 2023 11:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557456; x=1693162256; 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=j0fiMko5ylii7u2eXPnj2epzyNgneMAvv4Jp67l+SM4=; b=lofbjLjcS3hjr9eHicjFHbf60/2+qXIy4mpwbfW27S8sCg0ilFqN5qmWAK4YHOptZk A8ywEsoFI+lTl/fo9llNVAMbCeAYInbJQ9J8Q9K8EBpj0lEy3DkwMEDoKx7rlX3MmaOc kh1B7jbddK7kR8gqFL0EJqyHYqKJSV2vnsHz5gBkBasZ/qdYtGemhV7GZQsK9f1vBfXg GwskJHsA82awQtvITP0hDRUKpy2tFzw/v/iUn6L63fsht1PZUFbftnu4vipwAyYpudNu DVFPO58G7bk3SD8rz4VR5YQHia2LaJLeBS5C2tTjb0z1iAmUwpfgYwcfO/FGZZraHonW 9iRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557456; x=1693162256; 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=j0fiMko5ylii7u2eXPnj2epzyNgneMAvv4Jp67l+SM4=; b=l4bI9smLV6ouh1JKjWLNBCp8uwAKXipru0/ZVLHSKe7qoI9bjQ8d9vcyj2Cb7ekEao ATwzTj5YbQyQ7+pklc3jCw9CzES/3T3kmFobV15HTU0AVTJ/MbunpB5p19XTETj0X794 c5bydHL0N7TBpWfEUB4W3TuU7DKaX9QTluFemDj65lCMdQBiRj/yW1dRo8BxXQ0im/VG DZ3djj3MG8P4frRWndAV0n7OGgWRpWWeZmw/tCAW1OkwUXLYCUI5oO0BT9GXal3Tymoq uEQcNmkcF+ro0M5agqKP/59jAnQpiz579///t4A4irtLt27GoJDN4rqR4tu3jrlOr88c X/aQ== X-Gm-Message-State: AOJu0YxQz/KRnhicsrOxghxrzX+vZKc5PYCIZp71qA3Si4iEHhYkeX4B oFa+KgXbwZfbx+lthYqQmTtoe3PDdf1aFtE4 X-Google-Smtp-Source: AGHT+IGenZkh69nNxGcAto73m1fzGGT1Wy9v+4cEgZ0mqc7tPE8hejbe4wF2zovyEqwluxUw0ep10w== X-Received: by 2002:a05:600c:3799:b0:3fe:5053:1a0b with SMTP id o25-20020a05600c379900b003fe50531a0bmr3690392wmr.11.1692557456577; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 6/8] pretty: add %(decorate[:]) format Date: Sun, 20 Aug 2023 19:50:07 +0100 Message-ID: <20230820185009.20095-7-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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 | 59 +++++++++++++++++++++++++++++--- t/t4205-log-pretty-formats.sh | 27 +++++++++++++++ 3 files changed, 92 insertions(+), 4 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 69b6db3340..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) @@ -1645,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 18:50:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13358881 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 811ACEE4996 for ; Sun, 20 Aug 2023 18:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231636AbjHTS4J (ORCPT ); Sun, 20 Aug 2023 14:56:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231611AbjHTS4B (ORCPT ); Sun, 20 Aug 2023 14:56:01 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8D4FF1 for ; Sun, 20 Aug 2023 11:50:58 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fe2fb9b4d7so24838445e9.1 for ; Sun, 20 Aug 2023 11:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557457; x=1693162257; 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=BPNhiybuEcbX16mkc/0Jr6AqHADO9qRfvG1MVNwISS6uqhrnoA1vx2TlJnDhx96Lki kfAqYZ9slZ25rrfzDVkne9Od/Nad2IZHwKBjhRcG7rJPyWhh1snZlKPndxd/D3KIg/rY s3ddX/tQymVFOhseTWp8alFyTC2ObMnrnWobqhzB5qhnhiRj/AGp8TyA1HYZ3UB27kkJ H31bbRYGz9AEsoqdbPP9gNCt4OxSzT9Q/zZdSoRM1jD5nHunrxj+EMykU7wDyd8IeYUY ot+M+iXLRbu3iJ1KagIsGkRNtJd0N1x/w9cP+ypl9euBPKMl4tJOCbc94rOy34YMiQdD Z/aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557457; x=1693162257; 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=SAu3kXtbriWdU1ODrpxD5CqgHH+9DalTRCMbHViVhwP34/nu+VJzwKSc1x2spker/Q eb5VDa9GIc+VQ+5Mxl8ufkiS6X7PLvFASsxoS49OD7KsUOBRnO9ifG+XEoLG3BfMcyNJ E/YQ4vtD3eGWMIHuCRof2NIHcReJzKCtk/+DJckU+Xp2JDeJGwcARpnuvwfPNk6iDbFM odJ0sQJbODkQIJZIWxFc5VMZ/IS3PtYgFLPq/s+CKvb7xW6uFew0DugkNqmuno6sQUP7 WowJKgpI7otN0bM4qQA1xhJIkM8C2KAbZ1Yat/1ifcB2eUxrk0TX+ldsdKdbFnlVXPXD 6U1Q== X-Gm-Message-State: AOJu0YzV9pBwSlEwPEPHM7t5H0Ggu5IeO/B7vqq3Thl4Y97TWO3WZETm ZfFc12xtulFC+Z5gtEuPTyavgxTA74+AvmFQ X-Google-Smtp-Source: AGHT+IGu6HAvhIzGTM07uAWO7hzkUKZ9kreD6LCRzbLCsznnF3810SMhQUx9/nld1r+tuu/s8UMoHA== X-Received: by 2002:a1c:6a16:0:b0:3fb:ff57:1750 with SMTP id f22-20020a1c6a16000000b003fbff571750mr3647127wmc.32.1692557457230; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 7/8] pretty: add pointer and tag options to %(decorate) Date: Sun, 20 Aug 2023 19:50:08 +0100 Message-ID: <20230820185009.20095-8-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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: 13358879 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 D910DEE49AB for ; Sun, 20 Aug 2023 18:56:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbjHTS4I (ORCPT ); Sun, 20 Aug 2023 14:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjHTS4D (ORCPT ); Sun, 20 Aug 2023 14:56:03 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC06F7 for ; Sun, 20 Aug 2023 11:50:59 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fee87dd251so8329655e9.2 for ; Sun, 20 Aug 2023 11:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692557458; x=1693162258; 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=HjvCjvPV6LQ2RDQB1/3hrRtrn7MriWSyd4l6LA77Z/+DA++413P/CqstaJqcgvGxlG NnPiBidZQrgj/KgLf7Y5knkLpapPvmWuFRxmgGlYLTXJMOtAbPzpmcTPQ/EtF3ReisN8 0AP7NWD+mztkOwHYZkJVJ5rKskj4HFGTQRDdG2jt0FXi7qjeuwgT4Wc6HD8FPdBenDOO 1ktjlKNgcs0JSz31EP2tImshS980ToVbPHwbEvGHUkyBaL/pSQoBv/1mCaDokVQVEO8r oSIRNPneeL0Q1q3f6M/Zbo1YaVa3vt1h8W9w8v4Cj9sncrE3SqWf8dDEB5fTxP4/ydEQ jREA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692557458; x=1693162258; 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=ksiynRGm+VIQ4L6NcPonJRepZWyh3rh8qnO+aZUONFpZVjpmkONNkED/VnzOlx1/fm bOXBaiWoZddmji+Hme7kN+Aq9ZRft0UFf5yWHovyracXR30JRD7dUNTt75fYw1ifkKXZ ms2QezWjA/FfmTec8jzWiOpChcCTwYLoFiem/0hMp12Qk9wN8sgLa+YglcUpHGSJ+gsZ Z956q0wp9sZfGkObIfiLWJsOB7KbayHR6coOGkwB4IMkKtPmqC0XyzC1dj+UPm7/AFug wx1SKW8Ekws+gfREiHzLvJUSG3fhKmibC3e9EJNV3kDfA+5RMhiejq+2cbz+vLhj/868 jQvQ== X-Gm-Message-State: AOJu0YzijpRjQeeuHV5nh6324wILLjEv4RW8VDBEl9pYLqS9OqFjLfCT H7Mh8AZE5WrQ6YuXvlEHSbVf8VlQISUl//Ou X-Google-Smtp-Source: AGHT+IH51uvo3zcaijTmuPifiz3y+c78+gjKtJAU5jycGGtBawiq6oSk3Z3Zr7gbndNRR3xHN53w/w== X-Received: by 2002:a1c:7707:0:b0:3fe:179d:d42e with SMTP id t7-20020a1c7707000000b003fe179dd42emr3706189wmi.23.1692557457902; Sun, 20 Aug 2023 11:50: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 26-20020a05600c021a00b003fa95f328afsm13603604wmi.29.2023.08.20.11.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 11:50: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 v5 8/8] decorate: use commit color for HEAD arrow Date: Sun, 20 Aug 2023 19:50:09 +0100 Message-ID: <20230820185009.20095-9-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.0-rc1 In-Reply-To: <20230820185009.20095-1-andy.koppe@gmail.com> References: <20230820085336.8615-1-andy.koppe@gmail.com> <20230820185009.20095-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}\