From patchwork Tue Oct 3 20:54:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13408000 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 A43D6E8FDB3 for ; Tue, 3 Oct 2023 20:55:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241100AbjJCUzt (ORCPT ); Tue, 3 Oct 2023 16:55:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241091AbjJCUzs (ORCPT ); Tue, 3 Oct 2023 16:55:48 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B42BCAB for ; Tue, 3 Oct 2023 13:55:43 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-3247d69ed2cso1416417f8f.0 for ; Tue, 03 Oct 2023 13:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696366542; x=1696971342; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/Qyi2YiFyKIkoJDv/HVA774MkrfXAnkcE6ASof/Q4wo=; b=d4IYZcvrwi1InU6HfuRDhJflmLtZZTS7LO3zmV9T9PqVYYQda+4t8EWbJ6RobP7Rta osMi2NB/Dk3VL83DWZ39JqzjzsQ/IClpTJ42s2mULLYzkt0FMJSo1FlZOvW6d0oojJjW SaYmRUhflzfBRsIRywILFZbSVRhs+7Hbgvbl6HEhnHV6vdVfy7eYGqxOxNCxDDnAA+b1 tLtqeMpfGy6ByYoHpnSGxvqdS6evYrNGtVHSDYZyXxCDU13127tmy8m/GKOmdA71FdSL s3QxiQ/8/jhOaS78JMR3V5/4n1a3tYK9neAaMMVhl7BHDg3n19aH0Ky1ZNrqOHV7egMM 9Zuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696366542; x=1696971342; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/Qyi2YiFyKIkoJDv/HVA774MkrfXAnkcE6ASof/Q4wo=; b=GKm3YCcYrBjbbwkOTD/iyjpm0wdyvEy3rPvpZZY8N10FnFwKJ6uTgTlPv3Td3PkvF2 bUdvn3jUhjFG7M5hM2DIWiXXZ2YFtcXLLyu2WnXlrg3CoP5OOVpbewQgytwxxxEQl+PU RVSK152K0W3tiEpkbpkgpWFQ77oGmjv6oFGrIQyDvfimV/u+/RrdDB1VDBkWTwXWYdb3 jIzlzV80c73w9YMg5Ol2h+NevR1kGGWmg131YJbRCX5UuXFN4YPJXZzRP2pAacqGKDbb kpeLlkkauV2W0t3a0nQccjbAr3eCVm+/Y7UZKHtnc3FHSSAJ0YenWLfWBM3CeyXTxCn9 nZAQ== X-Gm-Message-State: AOJu0Yy9CikoJdRbv3w2byR8hEJ2riADNrfp6It9ePXc8JBqtq8sO+Ks ZabhW2NcLrKP+QzNPeC0rigoeWDWlrDtqw== X-Google-Smtp-Source: AGHT+IHUj8AxfPRjFn9YFmG8Q8LryAuwOfsz7qLNevhjFuvi1XP2aeAsA+YMj8u9ZpRMzrPqT6VA1g== X-Received: by 2002:a05:6000:104a:b0:31a:d2f9:7372 with SMTP id c10-20020a056000104a00b0031ad2f97372mr337197wrx.29.1696366541894; Tue, 03 Oct 2023 13:55:41 -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 g10-20020adfe40a000000b0030ae53550f5sm2355517wrm.51.2023.10.03.13.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 13:55:41 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: derrickstolee@github.com, Andy Koppe Subject: [PATCH] decorate: add color.decorate.symbols config option Date: Tue, 3 Oct 2023 21:54:42 +0100 Message-ID: <20231003205442.22963-1-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add new 'color.decorate.symbols' config option for determining the color of the prefix, suffix, separator and arrow symbols used in --decorate output and related log format placeholders, to allow them to be colored differently from commit hashes. For backward compatibility, fall back to the commit hash color that can be specified with the 'color.diff.commit' option if the new option is not provided. Add the setting to the color.decorate. documentation, rewording that a bit to try to improve readability. Amend t4207-log-decoration-colors.sh to test the option. Signed-off-by: Andy Koppe --- Documentation/config/color.txt | 7 ++-- commit.h | 1 + log-tree.c | 15 ++++++--- t/t4207-log-decoration-colors.sh | 58 +++++++++++++++++--------------- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/Documentation/config/color.txt b/Documentation/config/color.txt index 1795b2d16b..5d3612ff09 100644 --- a/Documentation/config/color.txt +++ b/Documentation/config/color.txt @@ -75,9 +75,10 @@ color.diff.:: color.decorate.:: Use customized color for 'git log --decorate' output. `` is one - of `branch`, `remoteBranch`, `tag`, `stash` or `HEAD` for local - branches, remote-tracking branches, tags, stash and HEAD, respectively - and `grafted` for grafted commits. + of `HEAD` for the current HEAD ref, `branch` for local branches, + `remoteBranch` for remote-tracking branches, `tag` for tags, `stash` + for the top stash entry, `grafted` for grafted commits, and `symbols` + for the punctuation surrounding the other elements. color.grep:: When set to `always`, always highlight matches. When `false` (or diff --git a/commit.h b/commit.h index 28928833c5..cefcb7c490 100644 --- a/commit.h +++ b/commit.h @@ -56,6 +56,7 @@ enum decoration_type { DECORATION_REF_STASH, DECORATION_REF_HEAD, DECORATION_GRAFTED, + DECORATION_SYMBOLS, }; void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); diff --git a/log-tree.c b/log-tree.c index 504da6b519..a5dd4292fc 100644 --- a/log-tree.c +++ b/log-tree.c @@ -41,6 +41,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */ GIT_COLOR_BOLD_CYAN, /* REF_HEAD */ GIT_COLOR_BOLD_BLUE, /* GRAFTED */ + GIT_COLOR_NIL, /* SYMBOLS */ }; static const char *color_decorate_slots[] = { @@ -50,6 +51,7 @@ static const char *color_decorate_slots[] = { [DECORATION_REF_STASH] = "stash", [DECORATION_REF_HEAD] = "HEAD", [DECORATION_GRAFTED] = "grafted", + [DECORATION_SYMBOLS] = "symbols", }; static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) @@ -312,7 +314,7 @@ void format_decorations(struct strbuf *sb, { const struct name_decoration *decoration; const struct name_decoration *current_and_HEAD; - const char *color_commit, *color_reset; + const char *color_symbols, *color_reset; const char *prefix = " ("; const char *suffix = ")"; @@ -337,7 +339,10 @@ void format_decorations(struct strbuf *sb, tag = opts->tag; } - color_commit = diff_get_color(use_color, DIFF_COMMIT); + color_symbols = decorate_get_color(use_color, DECORATION_SYMBOLS); + if (color_is_nil(color_symbols)) + color_symbols = diff_get_color(use_color, DIFF_COMMIT); + color_reset = decorate_get_color(use_color, DECORATION_NONE); current_and_HEAD = current_pointed_by_HEAD(decoration); @@ -352,7 +357,7 @@ void format_decorations(struct strbuf *sb, decorate_get_color(use_color, decoration->type); if (*prefix) { - strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, color_symbols); strbuf_addstr(sb, prefix); strbuf_addstr(sb, color_reset); } @@ -369,7 +374,7 @@ void format_decorations(struct strbuf *sb, if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { - strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, color_symbols); strbuf_addstr(sb, pointer); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); @@ -382,7 +387,7 @@ void format_decorations(struct strbuf *sb, decoration = decoration->next; } if (*suffix) { - strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, color_symbols); strbuf_addstr(sb, suffix); strbuf_addstr(sb, color_reset); } diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index 21986a866d..663ae49d34 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -18,6 +18,7 @@ test_expect_success setup ' git config color.decorate.tag "reverse bold yellow" && git config color.decorate.stash magenta && git config color.decorate.grafted black && + git config color.decorate.symbols white && git config color.decorate.HEAD cyan && c_reset="" && @@ -29,6 +30,7 @@ test_expect_success setup ' c_stash="" && c_HEAD="" && c_grafted="" && + c_symbols="" && test_commit A && git clone . other && @@ -53,17 +55,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_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}\ -${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: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_symbols} -> ${c_reset}${c_branch}main${c_reset}${c_symbols}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_symbols}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_symbols})${c_reset} B +${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_symbols}, \ +${c_reset}${c_remoteBranch}other/main${c_reset}${c_symbols})${c_reset} A1 + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_stash}refs/stash${c_reset}${c_symbols})${c_reset} On main: Changes to A.t + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbols})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual && @@ -78,14 +80,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_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}, \ -${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: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_symbols} -> ${c_reset}${c_branch}main${c_reset}${c_symbols}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_symbols})${c_reset} D + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}C${c_reset}${c_symbols}, \ +${c_reset}${c_grafted}replaced${c_reset}${c_symbols})${c_reset} B + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbols})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && @@ -104,15 +106,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_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}\ -${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 + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_symbols} -> ${c_reset}${c_branch}main${c_reset}${c_symbols}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_symbols}, \ +${c_reset}${c_grafted}replaced${c_reset}${c_symbols})${c_reset} D + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_symbols}, \ +${c_reset}${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_symbols})${c_reset} B + ${c_commit}COMMIT_ID${c_reset}${c_symbols} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbols})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && From patchwork Thu Oct 19 19:39: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: 13429763 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8184D19440 for ; Thu, 19 Oct 2023 19:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aLaB48M9" Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34299FA for ; Thu, 19 Oct 2023 12:39:46 -0700 (PDT) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-66d12b3b479so618916d6.1 for ; Thu, 19 Oct 2023 12:39:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697744385; x=1698349185; darn=vger.kernel.org; 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=TAkoeCjTOE+20TgEESJjQDJvFdoOVG8zsbfAyTj65zw=; b=aLaB48M9iKCb6BHko0xdUp5DFUYwdSP929GqJuWwlIsl1M36j1JGXGRar9YYmHDP3y jS0dUxGxqAEq+PjOz26YtPeBWgTjJgJ2LaZcm1qoofcyoUcb5LG05xFxUtzVn32aFXt4 aWRvVTnPMOzqGCy5OSct/GdMyMbM33d0Fls6XRGyByVNMC7ml0v3evXcnjdLcjJus3YD TPKZMJQa6PMYRJe8tefQYxaoxEn+/wwFSccP8n0YTuDkLg+5d3u7gvvEdvVBaZhCKFJM nDTahJ7mtabdhuPoIvQo85IxO4lkGxH/zFBuVqd4WUuXDa4T5TCnU9tO5xqbQqJeq0jg yvpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697744385; x=1698349185; 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=TAkoeCjTOE+20TgEESJjQDJvFdoOVG8zsbfAyTj65zw=; b=poCPO4hE3O5rkD/ElUk247iQeqvd8aIV4kHRaf6EnmD7NVWht6K2Td1T9Vlr8NJ8dH bBpDPzo4Us86yt0bL4jd4SCKm5XToLwUV+1ymuXFpLZrmmDfci7+HCx/rTL/8CdpCdNN xQwEB+nBTOlgZJU05mPeI2pEKDLLy/AtejaNP/sRkHQVNlqAsw+5diH818KT4vVO7F7n 8Oz1cXupKvXKXyDIOZy/4WL3u3EADMy7dpOe3LdyAEaYeEp8NoQFiBVA/PnKYPOzO7e8 1LPPoYk3JrJhutqckWv3kcpN3nnrvHQG9Y40zRFrbSWoOLBtDaXnYhy8pCtVWgfIkyPS KDwQ== X-Gm-Message-State: AOJu0YzH2lp8UyDLS67TZwHf6VqnnXzj7vJKOsSpfWrMuu7OHOiIJ2KW OLO4RONO07fIp++9AVeLkxXTxCdW1Es= X-Google-Smtp-Source: AGHT+IHb+FvdRB/hr7sK9wwQA07Hk7xpZyDaTAIbvJZMd6nnXUR19DWnKwesQUGxn6rZg0WB+vly9w== X-Received: by 2002:a0c:a9d7:0:b0:66d:3548:9c1a with SMTP id c23-20020a0ca9d7000000b0066d35489c1amr3125113qvb.54.1697744385239; Thu, 19 Oct 2023 12:39:45 -0700 (PDT) Received: from u.ad.analog.com (cpc99472-lich12-2-0-cust1752.3-2.cable.virginm.net. [80.2.214.217]) by smtp.gmail.com with ESMTPSA id ph5-20020a0562144a4500b0066d0ab215b5sm99940qvb.13.2023.10.19.12.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:39:44 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH 2/7] log: use designated inits for decoration_colors Date: Thu, 19 Oct 2023 20:39:06 +0100 Message-ID: <20231019193911.1669705-3-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT In-Reply-To: <20231003205442.22963-1-andy.koppe@gmail.com> References: <20231003205442.22963-1-andy.koppe@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use designated initializers instead of comments to denote the slots in the decoration_colors array for holding color settings, to reduce the likelihood of mistakes when extending the array. Signed-off-by: Andy Koppe --- log-tree.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/log-tree.c b/log-tree.c index 504da6b519e..8bdf889f022 100644 --- a/log-tree.c +++ b/log-tree.c @@ -34,13 +34,13 @@ static int decoration_loaded; static int decoration_flags; static char decoration_colors[][COLOR_MAXLEN] = { - GIT_COLOR_RESET, - GIT_COLOR_BOLD_GREEN, /* REF_LOCAL */ - GIT_COLOR_BOLD_RED, /* REF_REMOTE */ - GIT_COLOR_BOLD_YELLOW, /* REF_TAG */ - GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */ - GIT_COLOR_BOLD_CYAN, /* REF_HEAD */ - GIT_COLOR_BOLD_BLUE, /* GRAFTED */ + [DECORATION_NONE] = GIT_COLOR_RESET, + [DECORATION_REF_LOCAL] = GIT_COLOR_BOLD_GREEN, + [DECORATION_REF_REMOTE] = GIT_COLOR_BOLD_RED, + [DECORATION_REF_TAG] = GIT_COLOR_BOLD_YELLOW, + [DECORATION_REF_STASH] = GIT_COLOR_BOLD_MAGENTA, + [DECORATION_REF_HEAD] = GIT_COLOR_BOLD_CYAN, + [DECORATION_GRAFTED] = GIT_COLOR_BOLD_BLUE, }; static const char *color_decorate_slots[] = { From patchwork Thu Oct 19 19:39: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: 13429764 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B89D13C68A for ; Thu, 19 Oct 2023 19:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="meoi0li6" Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8DE111B for ; Thu, 19 Oct 2023 12:39:48 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3b2e330033fso67553b6e.3 for ; Thu, 19 Oct 2023 12:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697744388; x=1698349188; darn=vger.kernel.org; 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=/4wO8x1fM/JwN4oD+3FoqZoKDlwF6cRU4SS8EVE8m/Y=; b=meoi0li6valAZfTnb6evd/Wx/avMhcakY7fPDu7nE+5+poHNyOoyaqmEGBOId+Ndaq 3JqTiDPrioYynXk6ekhZWG2pYAPDEZSgC8XuBvvXSH6r54D6vf+yCyhDZme1qisK+3OQ gjV8F/zXtW89l3qwopSjnIcEnJGUHqw108xVbspSCeh2+bV2QmUP9AEjKLemBj32YT09 vZCHbaIyUwdpLrf4wWshFUaXDfkJKmBAOAoJtkIorkIQzIPUYwM20x4BLWDwGdN6XaBL WL+jKx5wxVzk1f4AOcVYY8zuQSpT9TlBnu3JiOipjI16OiOsOvNFeuOULN8DVh5/BkaB /zkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697744388; x=1698349188; 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=/4wO8x1fM/JwN4oD+3FoqZoKDlwF6cRU4SS8EVE8m/Y=; b=EyohG7FdwFmxZEAl77j4guBjrYMzSBoW09NmUwR9aQfeSJ3bpg4JTA6lscKl45qPWN 6T3zevl0gODP6eFdmrly+L4bcsPH5gNyulk9ZDsKq1b4dww/trz3agtFckyPF9lVBzIY Bq8nlxMJWAqoGbfDg/yPP4G11XH4ORw7+tawjuYz4CK55fq5LS3u90ygOwO7OsoCI1ot 5ANMBGquYFldlAUcOCMV5iZ5UdGDmEsY9Kd/rFlgmp6ckUvdI3fto/kEghSDnTiWTd1I mOMX8hG6tAkshlFOo7St4mjuRvREkqD6v3NADFHZqy7ubP7NTs8Fw2nXlkUHqYtWldAe l4eA== X-Gm-Message-State: AOJu0Yw1xc2nETVQtmAlsB2qE1j5EM6yJvcK04IDRXDH3YeHNaAqiCWW ZBqNlK3Bw9TOcUezMwkP46HHyBGd60c= X-Google-Smtp-Source: AGHT+IHSK3HhKBJ7ZhSEC/Yk6cuiIDRsNaPhkGxTvZ19QH1w/kNEzUgOLPhNlAaLOMSnJzJs4UtSwg== X-Received: by 2002:a54:4018:0:b0:3ac:a4ec:e136 with SMTP id x24-20020a544018000000b003aca4ece136mr3107967oie.51.1697744388022; Thu, 19 Oct 2023 12:39:48 -0700 (PDT) Received: from u.ad.analog.com (cpc99472-lich12-2-0-cust1752.3-2.cable.virginm.net. [80.2.214.217]) by smtp.gmail.com with ESMTPSA id ph5-20020a0562144a4500b0066d0ab215b5sm99940qvb.13.2023.10.19.12.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:39:47 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH 3/7] log: add color.decorate.symbol config option Date: Thu, 19 Oct 2023 20:39:07 +0100 Message-ID: <20231019193911.1669705-4-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT In-Reply-To: <20231003205442.22963-1-andy.koppe@gmail.com> References: <20231003205442.22963-1-andy.koppe@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add new 'color.decorate.symbol' config option for determining the color of the prefix, suffix, separator and arrow symbols used in --decorate output and related log format placeholders, to allow them to be colored differently from commit hashes. For backward compatibility, fall back to the commit hash color that can be specified with the 'color.diff.commit' option if the new option is not provided. Add the setting to the color.decorate. documentation. Amend t4207-log-decoration-colors.sh to test it. Put ${c_reset} elements in the expected output at the end of lines for consistency. Signed-off-by: Andy Koppe --- Documentation/config/color.txt | 2 ++ commit.h | 1 + log-tree.c | 15 ++++++--- t/t4207-log-decoration-colors.sh | 58 +++++++++++++++++--------------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/Documentation/config/color.txt b/Documentation/config/color.txt index b0e2eccad95..ba9f56885e3 100644 --- a/Documentation/config/color.txt +++ b/Documentation/config/color.txt @@ -92,6 +92,8 @@ color.decorate.:: the stash ref `grafted`;; grafted commits (used to implement shallow clones) +`symbol`;; + punctuation surrounding the other elements -- color.grep:: diff --git a/commit.h b/commit.h index 28928833c54..cb13e4d5baa 100644 --- a/commit.h +++ b/commit.h @@ -56,6 +56,7 @@ enum decoration_type { DECORATION_REF_STASH, DECORATION_REF_HEAD, DECORATION_GRAFTED, + DECORATION_SYMBOL, }; void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); diff --git a/log-tree.c b/log-tree.c index 8bdf889f022..890024f205b 100644 --- a/log-tree.c +++ b/log-tree.c @@ -41,6 +41,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { [DECORATION_REF_STASH] = GIT_COLOR_BOLD_MAGENTA, [DECORATION_REF_HEAD] = GIT_COLOR_BOLD_CYAN, [DECORATION_GRAFTED] = GIT_COLOR_BOLD_BLUE, + [DECORATION_SYMBOL] = GIT_COLOR_NIL, }; static const char *color_decorate_slots[] = { @@ -50,6 +51,7 @@ static const char *color_decorate_slots[] = { [DECORATION_REF_STASH] = "stash", [DECORATION_REF_HEAD] = "HEAD", [DECORATION_GRAFTED] = "grafted", + [DECORATION_SYMBOL] = "symbol", }; static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix) @@ -312,7 +314,7 @@ void format_decorations(struct strbuf *sb, { const struct name_decoration *decoration; const struct name_decoration *current_and_HEAD; - const char *color_commit, *color_reset; + const char *color_symbol, *color_reset; const char *prefix = " ("; const char *suffix = ")"; @@ -337,7 +339,10 @@ void format_decorations(struct strbuf *sb, tag = opts->tag; } - color_commit = diff_get_color(use_color, DIFF_COMMIT); + color_symbol = decorate_get_color(use_color, DECORATION_SYMBOL); + if (color_is_nil(color_symbol)) + color_symbol = diff_get_color(use_color, DIFF_COMMIT); + color_reset = decorate_get_color(use_color, DECORATION_NONE); current_and_HEAD = current_pointed_by_HEAD(decoration); @@ -352,7 +357,7 @@ void format_decorations(struct strbuf *sb, decorate_get_color(use_color, decoration->type); if (*prefix) { - strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, color_symbol); strbuf_addstr(sb, prefix); strbuf_addstr(sb, color_reset); } @@ -369,7 +374,7 @@ void format_decorations(struct strbuf *sb, if (current_and_HEAD && decoration->type == DECORATION_REF_HEAD) { - strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, color_symbol); strbuf_addstr(sb, pointer); strbuf_addstr(sb, color_reset); strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type)); @@ -382,7 +387,7 @@ void format_decorations(struct strbuf *sb, decoration = decoration->next; } if (*suffix) { - strbuf_addstr(sb, color_commit); + strbuf_addstr(sb, color_symbol); strbuf_addstr(sb, suffix); strbuf_addstr(sb, color_reset); } diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index 21986a866df..f4173b61141 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -18,6 +18,7 @@ test_expect_success setup ' git config color.decorate.tag "reverse bold yellow" && git config color.decorate.stash magenta && git config color.decorate.grafted black && + git config color.decorate.symbol white && git config color.decorate.HEAD cyan && c_reset="" && @@ -29,6 +30,7 @@ test_expect_success setup ' c_stash="" && c_HEAD="" && c_grafted="" && + c_symbol="" && test_commit A && git clone . other && @@ -53,17 +55,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_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}\ -${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: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_symbol} -> ${c_reset}${c_branch}main${c_reset}${c_symbol}, ${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_symbol}, ${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_symbol})${c_reset} B +${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_symbol}, ${c_reset}\ +${c_remoteBranch}other/main${c_reset}${c_symbol})${c_reset} A1 + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_stash}refs/stash${c_reset}${c_symbol})${c_reset} On main: Changes to A.t + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual && @@ -78,14 +80,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_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}, \ -${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: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_symbol} -> ${c_reset}${c_branch}main${c_reset}${c_symbol}, ${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_symbol})${c_reset} D + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}C${c_reset}${c_symbol}, ${c_reset}\ +${c_grafted}replaced${c_reset}${c_symbol})${c_reset} B + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && @@ -104,15 +106,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_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}\ -${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 + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}${c_HEAD}HEAD${c_reset}\ +${c_symbol} -> ${c_reset}${c_branch}main${c_reset}${c_symbol}, ${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}D${c_reset}${c_symbol}, ${c_reset}\ +${c_grafted}replaced${c_reset}${c_symbol})${c_reset} D + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_symbol}, ${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_symbol})${c_reset} B + ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol})${c_reset} A EOF git log --first-parent --no-abbrev --decorate --oneline --color=always HEAD >actual && From patchwork Thu Oct 19 19:39: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: 13429765 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ED9C3C6A0 for ; Thu, 19 Oct 2023 19:39:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cdHE/pOh" Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3ABFA for ; Thu, 19 Oct 2023 12:39:50 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-d9ac31cb051so63150276.3 for ; Thu, 19 Oct 2023 12:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697744389; x=1698349189; darn=vger.kernel.org; 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=e1J7bjU/KPb/7aUQIjSXiJwC9DN/I87KB+lEhYCd9Og=; b=cdHE/pOhOM9Tpu2m2yCd6egmUziURRJM7AmEvAS3cuWOESFCkKURdEp9wfn4nl8ZFU YgT7/POiPTtx2OKTm6ZjzjqG4fRekbaPuFnfcjz/hJlRbMz5kA3lC4ngt1JH92zJ6w2T YBSJvuNJ7uIM18PBKLnZkQDkQS0O8hFuhobGMfGMYQv16ChcY/5ikHtrlQenfXp6afXM NlAxS8aUmuSTRgZ+m4mWpHDcs99qoc2WXhaKIWrD1m/9nMqqivxg/NrRxRGzIQdVNrmk AdEPoh4xrg4aCjFqroK4aaO//k5GBc+eiobFdbo0Eg6QN/jqvFrddnpfNPyrbsCRNLeB 4n7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697744389; x=1698349189; 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=e1J7bjU/KPb/7aUQIjSXiJwC9DN/I87KB+lEhYCd9Og=; b=UA8rfX963CP+ikdVLWcEMtL2Hsg3Tk1T7iX6SCfc0ml4PMZmLgq/1LPkcD0dmb5Vpe YhEWHe7KEThYJUVKwKffnMhLzk06keFNi2MiIIVvOk8wA2YL+GrOwA9jg9tuyAeqhOSu Ta/x/ccISGMvroukuq/iQaIx4e38U5vRd+CoxhVoRyTq/UkeZRYuGptiFZcw1d0p8dQv 4B8Ugfecyu2jqpJjiwhAHEzqyrHsN1OtdVWgc6Gwfpz4Ldct+onghBYWDpRNAeeWevsF oaewPiQ9VNWfs+p5gCcPZEljPgqlNA81pBTypVKsxaiSJRf47lCh3JbAHjSHjiDu7qTe dzaw== X-Gm-Message-State: AOJu0Yx0xjmy2LbB7p++A0cFGDpCAAD4/vM4IzJggenf5AbJghP6SgOu e4EI0n3rH58LlaH82RpNoUhh+XQ5jcE= X-Google-Smtp-Source: AGHT+IFqcAMCO5nYVRpopHPj7Av7QHwI5OBErcnJoVoH5dA/UO3ZnnNV2gMisX/I/IxTMAr/IR0JCw== X-Received: by 2002:a25:324b:0:b0:d7f:d6a7:d57d with SMTP id y72-20020a25324b000000b00d7fd6a7d57dmr3222090yby.27.1697744389277; Thu, 19 Oct 2023 12:39:49 -0700 (PDT) Received: from u.ad.analog.com (cpc99472-lich12-2-0-cust1752.3-2.cable.virginm.net. [80.2.214.217]) by smtp.gmail.com with ESMTPSA id ph5-20020a0562144a4500b0066d0ab215b5sm99940qvb.13.2023.10.19.12.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:39:48 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH 4/7] refs: separate decoration type from default filter Date: Thu, 19 Oct 2023 20:39:08 +0100 Message-ID: <20231019193911.1669705-5-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT In-Reply-To: <20231003205442.22963-1-andy.koppe@gmail.com> References: <20231003205442.22963-1-andy.koppe@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add 'include' bit to struct ref_namespace_info to determine whether a ref namespace is to be included in the default decoration filters, instead of using the decoration type for the purpose. This is to allow adding ref namespaces that do have a decoration type but that are not shown by default. Signed-off-by: Andy Koppe --- builtin/log.c | 6 ++---- refs.c | 6 ++++++ refs.h | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index ba775d7b5cf..25d73c25697 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -227,10 +227,8 @@ static void set_default_decoration_filter(struct decoration_filter *decoration_f * populate with sensible defaults. */ for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) { - if (!ref_namespace[i].decoration) - continue; - - string_list_append(include, ref_namespace[i].ref); + if (ref_namespace[i].include) + string_list_append(include, ref_namespace[i].ref); } } diff --git a/refs.c b/refs.c index fcae5dddc60..416c35f0c2f 100644 --- a/refs.c +++ b/refs.c @@ -70,14 +70,17 @@ struct ref_namespace_info ref_namespace[] = { .ref = "HEAD", .decoration = DECORATION_REF_HEAD, .exact = 1, + .include = 1, }, [NAMESPACE_BRANCHES] = { .ref = "refs/heads/", .decoration = DECORATION_REF_LOCAL, + .include = 1, }, [NAMESPACE_TAGS] = { .ref = "refs/tags/", .decoration = DECORATION_REF_TAG, + .include = 1, }, [NAMESPACE_REMOTE_REFS] = { /* @@ -87,6 +90,7 @@ struct ref_namespace_info ref_namespace[] = { */ .ref = "refs/remotes/", .decoration = DECORATION_REF_REMOTE, + .include = 1, }, [NAMESPACE_STASH] = { /* @@ -96,6 +100,7 @@ struct ref_namespace_info ref_namespace[] = { .ref = "refs/stash", .exact = 1, .decoration = DECORATION_REF_STASH, + .include = 1, }, [NAMESPACE_REPLACE] = { /* @@ -107,6 +112,7 @@ struct ref_namespace_info ref_namespace[] = { */ .ref = "refs/replace/", .decoration = DECORATION_GRAFTED, + .include = 1, }, [NAMESPACE_NOTES] = { /* diff --git a/refs.h b/refs.h index 23211a5ea1c..4b054d30fe5 100644 --- a/refs.h +++ b/refs.h @@ -987,10 +987,14 @@ struct ref_namespace_info { * If 'exact' is true, then we must match the 'ref' exactly. * Otherwise, use a prefix match. * + * If 'include' is true, the namespace is included in the + * default decoration filters. + * * 'ref_updated' is for internal use. It represents whether the * 'ref' value was replaced from its original literal version. */ unsigned exact:1, + include:1, ref_updated:1; }; From patchwork Thu Oct 19 19:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13429766 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E78CD3C685 for ; Thu, 19 Oct 2023 19:39:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BdB+xfIy" Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62EC5CA for ; Thu, 19 Oct 2023 12:39:51 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-d9b0f27dea5so88578276.0 for ; Thu, 19 Oct 2023 12:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697744390; x=1698349190; darn=vger.kernel.org; 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=5Fubabbserzgwdw6jgqIHKJr9vN5zVCzKfzC5+UUHhk=; b=BdB+xfIyHvI5pMFC53PJ/phJK22AEd1EY0liuKqnRlj+IhGnuovNSG0FDZ8zPeLiPc vWa4M78hMe7bklIE9ZoKdoiBg6CWMhXHZr1n+Wz5yqWz+/FlZkLjdSe3mT8bTLDR2ITn fQWUzYaTSi4bLn2+oyNeuFdsy3Q9w3LBvy6Ga5kklxW4C+OxucEEW0VaqTJWqeULoAsp n5qjaSXqHiKJW0+v8jakhL7NBGqmweJfOedfQS1Zxv9tgE4srVyopUpcVcdA6aqsAdNG AO3OMioLHVGzmFu02mIuUO5LQI3jNxGRyc+Tw3udnIHr3Qz751FvPUYUGMcCb1f6wS9X 3e5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697744390; x=1698349190; 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=5Fubabbserzgwdw6jgqIHKJr9vN5zVCzKfzC5+UUHhk=; b=UMKiDF4z2ShuYId/qrZrcDxmqZMwLQo6pq/AIn/XDMz4CywCFG4lPEm8+Po1eud2nI kNpAZ1sDCa0dEZQ64LVJDD49yTGd2KZt3oXdzjr4r3yl0LJlWE4Ueb/MWI5LI2Nh7gtg MW1hlxz3BB5fHHC36MyB0x8+/768zDyo+ifySXIGMk7HEKl6xwyN3TTxDuxFoMxFP/hl CG2+fFwH2alrftW4tSaasWZtJ2VPHfCueiAeT6iYodVifQirY83969TTLLhdxCst1DqW cafjRN944Q/LmrXXsbA7bW3uGR+ZuLc+cB6Qp0RfLxfzaTUUxZgph5i/K1/bDAXxv5JS rD0Q== X-Gm-Message-State: AOJu0YyjuUDEzbCgwJFEUSf0tbstpjLWSHqC9S873kIJqb5FUSv0dVEv kNm2LY9J+wYqRQubK/GSAw2zN+D34+k= X-Google-Smtp-Source: AGHT+IGcnP6Qgk2rBmlkTyLN0H4doC73vk32GLLbrkXuOzlGFO91EEJktqM/Az5l2DQomuqhT8tdNQ== X-Received: by 2002:a25:8041:0:b0:d9a:d894:7b51 with SMTP id a1-20020a258041000000b00d9ad8947b51mr3462235ybn.57.1697744390531; Thu, 19 Oct 2023 12:39:50 -0700 (PDT) Received: from u.ad.analog.com (cpc99472-lich12-2-0-cust1752.3-2.cable.virginm.net. [80.2.214.217]) by smtp.gmail.com with ESMTPSA id ph5-20020a0562144a4500b0066d0ab215b5sm99940qvb.13.2023.10.19.12.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:39:50 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH 5/7] log: add color.decorate.ref option for other refs Date: Thu, 19 Oct 2023 20:39:09 +0100 Message-ID: <20231019193911.1669705-6-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT In-Reply-To: <20231003205442.22963-1-andy.koppe@gmail.com> References: <20231003205442.22963-1-andy.koppe@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Refs other than those with builtin special meaning do not appear in log decorations by default, but they can be made to appear using the decoration filter options. However, they would do so without coloring. Add config option color.decorate.ref to address this, defaulting to bold magenta, which is the same as refs/stash. To implement this, add NAMESPACE_REF with pattern "refs/", but do not set its .include bit, so as to leave it out of the default decoration filter. Document the color.decorate slot on the git-config page and amend t4207-log-decoration-colors.sh to test it. Signed-off-by: Andy Koppe --- Documentation/config/color.txt | 3 +++ commit.h | 1 + log-tree.c | 2 ++ refs.c | 7 +++++++ refs.h | 1 + t/t4207-log-decoration-colors.sh | 9 +++++++-- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Documentation/config/color.txt b/Documentation/config/color.txt index ba9f56885e3..086efebbe5d 100644 --- a/Documentation/config/color.txt +++ b/Documentation/config/color.txt @@ -92,6 +92,9 @@ color.decorate.:: the stash ref `grafted`;; grafted commits (used to implement shallow clones) +`ref`;; + any other refs (not shown unless enabled with one of the decoration + filter options such as `--decorate-refs=`) `symbol`;; punctuation surrounding the other elements -- diff --git a/commit.h b/commit.h index cb13e4d5baa..f6b2125fc42 100644 --- a/commit.h +++ b/commit.h @@ -54,6 +54,7 @@ enum decoration_type { DECORATION_REF_REMOTE, DECORATION_REF_TAG, DECORATION_REF_STASH, + DECORATION_REF, DECORATION_REF_HEAD, DECORATION_GRAFTED, DECORATION_SYMBOL, diff --git a/log-tree.c b/log-tree.c index 890024f205b..fd99eb88d95 100644 --- a/log-tree.c +++ b/log-tree.c @@ -39,6 +39,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { [DECORATION_REF_REMOTE] = GIT_COLOR_BOLD_RED, [DECORATION_REF_TAG] = GIT_COLOR_BOLD_YELLOW, [DECORATION_REF_STASH] = GIT_COLOR_BOLD_MAGENTA, + [DECORATION_REF] = GIT_COLOR_BOLD_MAGENTA, [DECORATION_REF_HEAD] = GIT_COLOR_BOLD_CYAN, [DECORATION_GRAFTED] = GIT_COLOR_BOLD_BLUE, [DECORATION_SYMBOL] = GIT_COLOR_NIL, @@ -49,6 +50,7 @@ static const char *color_decorate_slots[] = { [DECORATION_REF_REMOTE] = "remoteBranch", [DECORATION_REF_TAG] = "tag", [DECORATION_REF_STASH] = "stash", + [DECORATION_REF] = "ref", [DECORATION_REF_HEAD] = "HEAD", [DECORATION_GRAFTED] = "grafted", [DECORATION_SYMBOL] = "symbol", diff --git a/refs.c b/refs.c index 416c35f0c2f..b03cccab909 100644 --- a/refs.c +++ b/refs.c @@ -142,6 +142,13 @@ struct ref_namespace_info ref_namespace[] = { */ .ref = "refs/rewritten/", }, + [NAMESPACE_REFS] = { + /* + * Catch-all for any other refs. + */ + .ref = "refs/", + .decoration = DECORATION_REF, + }, }; void update_ref_namespace(enum ref_namespace namespace, char *ref) diff --git a/refs.h b/refs.h index 4b054d30fe5..82aecd37a2b 100644 --- a/refs.h +++ b/refs.h @@ -1008,6 +1008,7 @@ enum ref_namespace { NAMESPACE_NOTES, NAMESPACE_PREFETCH, NAMESPACE_REWRITTEN, + NAMESPACE_REFS, /* Must be last */ NAMESPACE__COUNT diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index f4173b61141..4b51e34f8b2 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -17,6 +17,7 @@ test_expect_success setup ' git config color.decorate.remoteBranch red && git config color.decorate.tag "reverse bold yellow" && git config color.decorate.stash magenta && + git config color.decorate.ref blue && git config color.decorate.grafted black && git config color.decorate.symbol white && git config color.decorate.HEAD cyan && @@ -28,11 +29,13 @@ test_expect_success setup ' c_remoteBranch="" && c_tag="" && c_stash="" && + c_ref="" && c_HEAD="" && c_grafted="" && c_symbol="" && test_commit A && + git update-ref refs/foo A && git clone . other && ( cd other && @@ -65,10 +68,12 @@ ${c_remoteBranch}other/main${c_reset}${c_symbol})${c_reset} A1 ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ ${c_stash}refs/stash${c_reset}${c_symbol})${c_reset} On main: Changes to A.t ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ -${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol})${c_reset} A +${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol}, ${c_reset}\ +${c_ref}refs/foo${c_reset}${c_symbol})${c_reset} A EOF - git log --first-parent --no-abbrev --decorate --oneline --color=always --all >actual && + git log --first-parent --no-abbrev --decorate --clear-decorations \ + --oneline --color=always --all >actual && cmp_filtered_decorations ' From patchwork Thu Oct 19 19:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13429767 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9C213CCE1 for ; Thu, 19 Oct 2023 19:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HhKLaL9C" Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AA01E8 for ; Thu, 19 Oct 2023 12:39:52 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-d9c687f83a2so62357276.3 for ; Thu, 19 Oct 2023 12:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697744391; x=1698349191; darn=vger.kernel.org; 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=rup1w+DXVFmdQqXBRU+RjsWXvyUo9UCqcLXgchIh6KQ=; b=HhKLaL9C/TdOfPmzzC4tnohapLyLugj/b9b60tTnI9ZmsRNdQATVVYNVi5QksxZI9Z MhlMZYrUjSQVieMwH4r9NWKpb/pYAzvrRdmwkE2nmTM+OJ1uAoBgyAUtlBYhR3CPQVji obq+wOfYvaL3mQm+kBg6FiVlvU1fv+dOW5jyDJp0ALXiIGOiPBHtBIwqsz3ViQbOx8jE BzSiGTgfgL12SRAII2T5Rhdd76c8K93EruFCXQtquF9QlG7UQs4JhUhMzVaPCSCoFxah vY3hWcupQiRPzj97gZGo0HGFXaLSfQyH7ABgX8qjtSlgE6QSo5soJC7my9L8WiXCz9Hd //TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697744391; x=1698349191; 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=rup1w+DXVFmdQqXBRU+RjsWXvyUo9UCqcLXgchIh6KQ=; b=H0gp3o6P/WscmgMHa+S7MSMBi4hV42GiZoEUE/FYnnnUm/8L9GK6Be/IJgj3mvu8OO JgrCXS+tUgD6m7ZT2Nt5JJOq6pPGiYT3eyk7e3yuEsdEdKnCtyD4jyYsTEpPcZxuH8Aw KFeTr91Pdzmcc7G6eVRYz2kps5MMD5RTUTHLZXHyivCnlOiL9/Gt3lpQIJ/DDN793/NC ShQmAYRDK6Cc4rm6lwtyYafrjgyHwZMSpsoUi/O8ZlBVJ8RJaExDEU5JJrEO+03T7IYc 8L3cMBTqAOsQ7nABTmbYIDekgUQbfZsbGz8jrIF/ixJlokSC2AF03cBPIGrLjt4Gg+xK SyOw== X-Gm-Message-State: AOJu0Yy8G93OwvSd47N42kNEi3wWwi62yHIKnko280h9OipB6ooQw6kH dfnWx4ubveCbZtUnvzVVAdzDIXpr3vM= X-Google-Smtp-Source: AGHT+IEI4KAzofRFXU1YgNt5IvQ/u5lND4ME0M3blq4I6f5ycoaRoAbz1KH8oHEOkqfvsgR+Uw+odg== X-Received: by 2002:a05:6902:ca:b0:d9a:da03:e72a with SMTP id i10-20020a05690200ca00b00d9ada03e72amr3242733ybs.18.1697744391696; Thu, 19 Oct 2023 12:39:51 -0700 (PDT) Received: from u.ad.analog.com (cpc99472-lich12-2-0-cust1752.3-2.cable.virginm.net. [80.2.214.217]) by smtp.gmail.com with ESMTPSA id ph5-20020a0562144a4500b0066d0ab215b5sm99940qvb.13.2023.10.19.12.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:39:51 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH 6/7] refs: exempt pseudoref patterns from prefixing Date: Thu, 19 Oct 2023 20:39:10 +0100 Message-ID: <20231019193911.1669705-7-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT In-Reply-To: <20231003205442.22963-1-andy.koppe@gmail.com> References: <20231003205442.22963-1-andy.koppe@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In normalize_glob_ref(), don't prefix patterns that look like pseudorefs with "refs/". This is in preparation for showing pseudorefs such as ORIG_HEAD in log decorations, as they are not matched as intended in decoration filters otherwise. Use existing function is_pseudoref_syntax() to do this, declaring it in refs.h to make it available to normalize_glob_ref() and anything else that might need it. As the function returns true for HEAD as well, the special case for that is no longer needed. Signed-off-by: Andy Koppe --- refs.c | 8 ++------ refs.h | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/refs.c b/refs.c index b03cccab909..492b9f7d4e5 100644 --- a/refs.c +++ b/refs.c @@ -564,12 +564,8 @@ void normalize_glob_ref(struct string_list_item *item, const char *prefix, if (prefix) strbuf_addstr(&normalized_pattern, prefix); else if (!starts_with(pattern, "refs/") && - strcmp(pattern, "HEAD")) + !is_pseudoref_syntax(pattern)) strbuf_addstr(&normalized_pattern, "refs/"); - /* - * NEEDSWORK: Special case other symrefs such as REBASE_HEAD, - * MERGE_HEAD, etc. - */ strbuf_addstr(&normalized_pattern, pattern); strbuf_strip_suffix(&normalized_pattern, "/"); @@ -840,7 +836,7 @@ int is_per_worktree_ref(const char *refname) starts_with(refname, "refs/rewritten/"); } -static int is_pseudoref_syntax(const char *refname) +int is_pseudoref_syntax(const char *refname) { const char *c; diff --git a/refs.h b/refs.h index 82aecd37a2b..b77691d787a 100644 --- a/refs.h +++ b/refs.h @@ -123,6 +123,8 @@ int should_autocreate_reflog(const char *refname); int is_branch(const char *refname); +int is_pseudoref_syntax(const char *refname); + int refs_init_db(struct strbuf *err); /* From patchwork Thu Oct 19 19:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Koppe X-Patchwork-Id: 13429768 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FDAA3DFF7 for ; Thu, 19 Oct 2023 19:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xb1V0II9" Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184DFFA for ; Thu, 19 Oct 2023 12:39:54 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-66d17bdabe1so777076d6.0 for ; Thu, 19 Oct 2023 12:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697744393; x=1698349193; darn=vger.kernel.org; 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=/zGvx/vTx2PJBWIw2qIv/v+/wtygGLw25nG8QRsnkB8=; b=Xb1V0II9ajr0cPbwWmTY1/cxiZ700fxSUi0rjMabWJCn1BxuOQNHwK9o2G+/lcziPU 2Ra+cvbK5F8zb+lQfTXVlySDuj8SyEEJWYaehhiNATB6pQQH2TWeKQyZlqoRZZsUrkpd J/yb8TpFzAwfnrTUHQycWR9woWkbjxgWxb5NUxx247aMOVVdZnIC+o7IfdBt57fh85N2 hzPBF3xL/cFqHMotgdwYYd/9Z53AeFiE6DHrIkl+tIczGOBSNf0PbMxualFy3+Cd8n2C aIsNBWeJBnDev0UahUb335/8m5d75nLf6++Z1m7IC2qXjJAaPBFdPGjLGBDTGKAxMSng VtIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697744393; x=1698349193; 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=/zGvx/vTx2PJBWIw2qIv/v+/wtygGLw25nG8QRsnkB8=; b=CrzBeLjvNr6eDnrrzJiJGXXHj8ATsN22+RxxLGnVxziCHQ2+SfjexQ6YH3RS8ngKHJ F8KoqZEr6P6Spi3QDzZqkwG5fzKanG8/mYFLcmkOBljCQhkgsi1sqhP1R1fhUaIVn1eK Cj+uf9/UeMTHLHcrnJ8ONAyX6u3uOsxe8QH87gC3Lurm7vJFkESnyc31HRTB4FekOIhz yyrpUt9rQoVhqDHmnNJpbrgj84bOTTtw7CJkQu6qMQlQLrDKWVoyKRDRGehzaAg1bWSM kDBhq6nrnH/4bg1Z6YVtdw/d0D4lChWvb1Fw3yw8DMbB5LbyiCxct8tvb3+KDJz8wZvi mnAA== X-Gm-Message-State: AOJu0YyMkIzLRBsE1AID44PHfwnQ4xLzKniZW1FSDmf9XTbBizsqp+fH Eo58d4puKw4jW3sYSwcbEpIrSdyBi1w= X-Google-Smtp-Source: AGHT+IEJUE4H1zF0cq+KwJjKUcy5YS0jPFUrTL4jGICO2n0HNRfIRc+kcfSILXunQel+Y5pTv6Lj0A== X-Received: by 2002:a0c:b396:0:b0:656:3352:831e with SMTP id t22-20020a0cb396000000b006563352831emr3168782qve.31.1697744393082; Thu, 19 Oct 2023 12:39:53 -0700 (PDT) Received: from u.ad.analog.com (cpc99472-lich12-2-0-cust1752.3-2.cable.virginm.net. [80.2.214.217]) by smtp.gmail.com with ESMTPSA id ph5-20020a0562144a4500b0066d0ab215b5sm99940qvb.13.2023.10.19.12.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:39:52 -0700 (PDT) From: Andy Koppe To: git@vger.kernel.org Cc: Andy Koppe Subject: [PATCH 7/7] log: show pseudorefs in decorations Date: Thu, 19 Oct 2023 20:39:11 +0100 Message-ID: <20231019193911.1669705-8-andy.koppe@gmail.com> X-Mailer: git-send-email 2.42.GIT In-Reply-To: <20231003205442.22963-1-andy.koppe@gmail.com> References: <20231003205442.22963-1-andy.koppe@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Show various pseudorefs in log decorations. This includes pseudorefs for ongoing operations such as MERGE_HEAD and REBASE_HEAD, as well as ORIG_HEAD for the HEAD position before any "drastic" operations. Do not include FETCH_HEAD in the default decoration filter though, because it would appear a lot in user's logs, often right alongside HEAD, while providing little value as usually a remote-tracking branch already points at what's been fetched. To implement this, introduce decoration type DECORATION_REF_PSEUDO with corresponding color.decorate.pseudoref setting that defaults to bold blue. (This makes it similar to but not the same as HEAD, which defaults to bold cyan.) Add entries for each pseudoref to the ref_namespace array in refs.c. Process them in new function add_pseudoref_decorations(). They also get picked up by set_default_decoration_filter(). Document the showing of pseudorefs on the git-log page and the color.decorate.pseudoref setting on the git-config page. Amend t4207-log-decoration-colors.sh to test color.decorate.pseudoref, and tweak various other tests to reflect the appearance of ORIG_HEAD in decorations. Signed-off-by: Andy Koppe --- Documentation/config/color.txt | 2 + Documentation/git-log.txt | 7 ++-- commit.h | 1 + log-tree.c | 29 +++++++++++++ refs.c | 41 +++++++++++++++++++ refs.h | 7 ++++ t/t4013/diff.log_--decorate=full_--all | 2 +- ..._--decorate=full_--clear-decorations_--all | 4 +- t/t4013/diff.log_--decorate_--all | 2 +- ...f.log_--decorate_--clear-decorations_--all | 4 +- t/t4202-log.sh | 23 ++++++----- t/t4207-log-decoration-colors.sh | 13 ++++-- 12 files changed, 113 insertions(+), 22 deletions(-) diff --git a/Documentation/config/color.txt b/Documentation/config/color.txt index 086efebbe5d..139fb90498a 100644 --- a/Documentation/config/color.txt +++ b/Documentation/config/color.txt @@ -95,6 +95,8 @@ color.decorate.:: `ref`;; any other refs (not shown unless enabled with one of the decoration filter options such as `--decorate-refs=`) +`pseudoref`;; + pseudorefs such as ORIG_HEAD or MERGE_HEAD `symbol`;; punctuation surrounding the other elements -- diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 2a66cf88807..f217d16c439 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -52,9 +52,10 @@ OPTIONS the decorations, but an explicit `--decorate-refs` pattern will override a match in `log.excludeDecoration`. + -If none of these options or config settings are given, then references are -used as decoration if they match `HEAD`, `refs/heads/`, `refs/remotes/`, -`refs/stash/`, or `refs/tags/`. +If none of these options or config settings are given, then refs matching +`refs/heads/`, `refs/remotes/`, `refs/stash/`, or `refs/tags/`, as well as +the `HEAD` ref and the pseudorefs `ORIG_HEAD`, `MERGE_HEAD`, `REBASE_HEAD`, +`CHERRY_PICK_HEAD`, `REVERT_HEAD` and `BISECT_HEAD` are shown. --clear-decorations:: When specified, this option clears all previous `--decorate-refs` diff --git a/commit.h b/commit.h index f6b2125fc42..44dd3ce19b4 100644 --- a/commit.h +++ b/commit.h @@ -56,6 +56,7 @@ enum decoration_type { DECORATION_REF_STASH, DECORATION_REF, DECORATION_REF_HEAD, + DECORATION_REF_PSEUDO, DECORATION_GRAFTED, DECORATION_SYMBOL, }; diff --git a/log-tree.c b/log-tree.c index fd99eb88d95..eae288599d0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -41,6 +41,7 @@ static char decoration_colors[][COLOR_MAXLEN] = { [DECORATION_REF_STASH] = GIT_COLOR_BOLD_MAGENTA, [DECORATION_REF] = GIT_COLOR_BOLD_MAGENTA, [DECORATION_REF_HEAD] = GIT_COLOR_BOLD_CYAN, + [DECORATION_REF_PSEUDO] = GIT_COLOR_BOLD_BLUE, [DECORATION_GRAFTED] = GIT_COLOR_BOLD_BLUE, [DECORATION_SYMBOL] = GIT_COLOR_NIL, }; @@ -52,6 +53,7 @@ static const char *color_decorate_slots[] = { [DECORATION_REF_STASH] = "stash", [DECORATION_REF] = "ref", [DECORATION_REF_HEAD] = "HEAD", + [DECORATION_REF_PSEUDO] = "pseudoref", [DECORATION_GRAFTED] = "grafted", [DECORATION_SYMBOL] = "symbol", }; @@ -146,6 +148,32 @@ static int ref_filter_match(const char *refname, return 1; } +static void add_pseudoref_decorations(const struct decoration_filter *filter) +{ + struct ref_store *store = get_main_ref_store(the_repository); + int i; + + for (i = 0; i < ARRAY_SIZE(ref_namespace); i++) { + struct object_id oid; + struct object *obj; + enum object_type objtype; + const struct ref_namespace_info *info = &ref_namespace[i]; + + if (info->decoration != DECORATION_REF_PSEUDO || + !refs_resolve_ref_unsafe(store, info->ref, + RESOLVE_REF_READING, &oid, NULL) || + (filter && !ref_filter_match(info->ref, filter))) + continue; + + objtype = oid_object_info(the_repository, &oid, NULL); + if (objtype < 0) + continue; + + obj = lookup_object_by_type(the_repository, &oid, objtype); + add_name_decoration(DECORATION_REF_PSEUDO, info->ref, obj); + } +} + static int add_ref_decoration(const char *refname, const struct object_id *oid, int flags UNUSED, void *cb_data) @@ -236,6 +264,7 @@ void load_ref_decorations(struct decoration_filter *filter, int flags) decoration_loaded = 1; decoration_flags = flags; for_each_ref(add_ref_decoration, filter); + add_pseudoref_decorations(filter); head_ref(add_ref_decoration, filter); for_each_commit_graft(add_graft_decoration, filter); } diff --git a/refs.c b/refs.c index 492b9f7d4e5..d960997aed1 100644 --- a/refs.c +++ b/refs.c @@ -149,6 +149,47 @@ struct ref_namespace_info ref_namespace[] = { .ref = "refs/", .decoration = DECORATION_REF, }, + [NAMESPACE_ORIG_HEAD] = { + .ref = "ORIG_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + .include = 1, + }, + [NAMESPACE_MERGE_HEAD] = { + .ref = "MERGE_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + .include = 1, + }, + [NAMESPACE_REBASE_HEAD] = { + .ref = "REBASE_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + .include = 1, + }, + [NAMESPACE_CHERRY_PICK_HEAD] = { + .ref = "CHERRY_PICK_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + .include = 1, + }, + [NAMESPACE_REVERT_HEAD] = { + .ref = "REVERT_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + .include = 1, + }, + [NAMESPACE_BISECT_HEAD] = { + .ref = "BISECT_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + .include = 1, + }, + [NAMESPACE_FETCH_HEAD] = { + .ref = "FETCH_HEAD", + .exact = 1, + .decoration = DECORATION_REF_PSEUDO, + }, }; void update_ref_namespace(enum ref_namespace namespace, char *ref) diff --git a/refs.h b/refs.h index b77691d787a..5ac1f308d07 100644 --- a/refs.h +++ b/refs.h @@ -1011,6 +1011,13 @@ enum ref_namespace { NAMESPACE_PREFETCH, NAMESPACE_REWRITTEN, NAMESPACE_REFS, + NAMESPACE_ORIG_HEAD, + NAMESPACE_MERGE_HEAD, + NAMESPACE_REBASE_HEAD, + NAMESPACE_CHERRY_PICK_HEAD, + NAMESPACE_REVERT_HEAD, + NAMESPACE_BISECT_HEAD, + NAMESPACE_FETCH_HEAD, /* Must be last */ NAMESPACE__COUNT diff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all index 6b0b334a5d6..9ebdd9b14fa 100644 --- a/t/t4013/diff.log_--decorate=full_--all +++ b/t/t4013/diff.log_--decorate=full_--all @@ -39,7 +39,7 @@ Date: Mon Jun 26 00:03:00 2006 +0000 Side -commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 (ORIG_HEAD) Author: A U Thor Date: Mon Jun 26 00:02:00 2006 +0000 diff --git a/t/t4013/diff.log_--decorate=full_--clear-decorations_--all b/t/t4013/diff.log_--decorate=full_--clear-decorations_--all index 1c030a6554e..7d16978e7f6 100644 --- a/t/t4013/diff.log_--decorate=full_--clear-decorations_--all +++ b/t/t4013/diff.log_--decorate=full_--clear-decorations_--all @@ -33,13 +33,13 @@ Date: Mon Jun 26 00:04:00 2006 +0000 Merge branch 'side' -commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side) +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (FETCH_HEAD, refs/heads/side) Author: A U Thor Date: Mon Jun 26 00:03:00 2006 +0000 Side -commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 (ORIG_HEAD) Author: A U Thor Date: Mon Jun 26 00:02:00 2006 +0000 diff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all index c7df1f58141..46dde03cffa 100644 --- a/t/t4013/diff.log_--decorate_--all +++ b/t/t4013/diff.log_--decorate_--all @@ -39,7 +39,7 @@ Date: Mon Jun 26 00:03:00 2006 +0000 Side -commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 (ORIG_HEAD) Author: A U Thor Date: Mon Jun 26 00:02:00 2006 +0000 diff --git a/t/t4013/diff.log_--decorate_--clear-decorations_--all b/t/t4013/diff.log_--decorate_--clear-decorations_--all index 88be82cce31..4f9be50ce02 100644 --- a/t/t4013/diff.log_--decorate_--clear-decorations_--all +++ b/t/t4013/diff.log_--decorate_--clear-decorations_--all @@ -33,13 +33,13 @@ Date: Mon Jun 26 00:04:00 2006 +0000 Merge branch 'side' -commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side) +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (FETCH_HEAD, side) Author: A U Thor Date: Mon Jun 26 00:03:00 2006 +0000 Side -commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 (ORIG_HEAD) Author: A U Thor Date: Mon Jun 26 00:02:00 2006 +0000 diff --git a/t/t4202-log.sh b/t/t4202-log.sh index af4a123cd22..ea048cb4a29 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -927,7 +927,7 @@ test_expect_success 'multiple decorate-refs' ' test_expect_success 'decorate-refs-exclude with glob' ' cat >expect.decorate <<-\EOF && Merge-tag-reach (HEAD -> main) - Merge-tags-octopus-a-and-octopus-b + Merge-tags-octopus-a-and-octopus-b (ORIG_HEAD) seventh (tag: seventh) octopus-b (tag: octopus-b) octopus-a (tag: octopus-a) @@ -944,7 +944,7 @@ test_expect_success 'decorate-refs-exclude with glob' ' test_expect_success 'decorate-refs-exclude without globs' ' cat >expect.decorate <<-\EOF && Merge-tag-reach (HEAD -> main) - Merge-tags-octopus-a-and-octopus-b + Merge-tags-octopus-a-and-octopus-b (ORIG_HEAD) seventh (tag: seventh) octopus-b (tag: octopus-b, octopus-b) octopus-a (tag: octopus-a, octopus-a) @@ -961,7 +961,7 @@ test_expect_success 'decorate-refs-exclude without globs' ' test_expect_success 'multiple decorate-refs-exclude' ' cat >expect.decorate <<-\EOF && Merge-tag-reach (HEAD -> main) - Merge-tags-octopus-a-and-octopus-b + Merge-tags-octopus-a-and-octopus-b (ORIG_HEAD) seventh (tag: seventh) octopus-b (tag: octopus-b) octopus-a (tag: octopus-a) @@ -1022,10 +1022,12 @@ test_expect_success 'decorate-refs-exclude and simplify-by-decoration' ' EOF git log -n6 --decorate=short --pretty="tformat:%f%d" \ --decorate-refs-exclude="*octopus*" \ + --decorate-refs-exclude="ORIG_HEAD" \ --simplify-by-decoration >actual && test_cmp expect.decorate actual && - git -c log.excludeDecoration="*octopus*" log \ - -n6 --decorate=short --pretty="tformat:%f%d" \ + git -c log.excludeDecoration="*octopus*" \ + -c log.excludeDecoration="ORIG_HEAD" \ + log -n6 --decorate=short --pretty="tformat:%f%d" \ --simplify-by-decoration >actual && test_cmp expect.decorate actual ' @@ -1067,9 +1069,10 @@ test_expect_success 'decorate-refs and simplify-by-decoration without output' ' test_cmp expect actual ' -test_expect_success 'decorate-refs-exclude HEAD' ' +test_expect_success 'decorate-refs-exclude HEAD ORIG_HEAD' ' git log --decorate=full --oneline \ - --decorate-refs-exclude="HEAD" >actual && + --decorate-refs-exclude="HEAD" \ + --decorate-refs-exclude="ORIG_HEAD" >actual && ! grep HEAD actual ' @@ -1082,7 +1085,7 @@ test_expect_success 'decorate-refs focus from default' ' test_expect_success '--clear-decorations overrides defaults' ' cat >expect.default <<-\EOF && Merge-tag-reach (HEAD -> refs/heads/main) - Merge-tags-octopus-a-and-octopus-b + Merge-tags-octopus-a-and-octopus-b (ORIG_HEAD) seventh (tag: refs/tags/seventh) octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b) octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a) @@ -1107,7 +1110,7 @@ test_expect_success '--clear-decorations overrides defaults' ' cat >expect.all <<-\EOF && Merge-tag-reach (HEAD -> refs/heads/main) - Merge-tags-octopus-a-and-octopus-b + Merge-tags-octopus-a-and-octopus-b (ORIG_HEAD) seventh (tag: refs/tags/seventh) octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b) octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a) @@ -1139,7 +1142,7 @@ test_expect_success '--clear-decorations clears previous exclusions' ' cat >expect.all <<-\EOF && Merge-tag-reach (HEAD -> refs/heads/main) reach (tag: refs/tags/reach, refs/heads/reach) - Merge-tags-octopus-a-and-octopus-b + Merge-tags-octopus-a-and-octopus-b (ORIG_HEAD) octopus-b (tag: refs/tags/octopus-b, refs/heads/octopus-b) octopus-a (tag: refs/tags/octopus-a, refs/heads/octopus-a) seventh (tag: refs/tags/seventh) diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index 4b51e34f8b2..0b32e0bb8e9 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -18,6 +18,7 @@ test_expect_success setup ' git config color.decorate.tag "reverse bold yellow" && git config color.decorate.stash magenta && git config color.decorate.ref blue && + git config color.decorate.pseudoref "bold cyan" && git config color.decorate.grafted black && git config color.decorate.symbol white && git config color.decorate.HEAD cyan && @@ -30,6 +31,7 @@ test_expect_success setup ' c_tag="" && c_stash="" && c_ref="" && + c_pseudoref="" && c_HEAD="" && c_grafted="" && c_symbol="" && @@ -46,7 +48,10 @@ test_expect_success setup ' test_commit B && git tag v1.0 && echo >>A.t && - git stash save Changes to A.t + git stash save Changes to A.t && + git reset other/main && + git reset ORIG_HEAD && + git revert --no-commit @~ ' cmp_filtered_decorations () { @@ -63,17 +68,19 @@ ${c_symbol} -> ${c_reset}${c_branch}main${c_reset}${c_symbol}, ${c_reset}\ ${c_tag}tag: ${c_reset}${c_tag}v1.0${c_reset}${c_symbol}, ${c_reset}\ ${c_tag}tag: ${c_reset}${c_tag}B${c_reset}${c_symbol})${c_reset} B ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_pseudoref}ORIG_HEAD${c_reset}${c_symbol}, ${c_reset}\ ${c_tag}tag: ${c_reset}${c_tag}A1${c_reset}${c_symbol}, ${c_reset}\ ${c_remoteBranch}other/main${c_reset}${c_symbol})${c_reset} A1 ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ ${c_stash}refs/stash${c_reset}${c_symbol})${c_reset} On main: Changes to A.t ${c_commit}COMMIT_ID${c_reset}${c_symbol} (${c_reset}\ +${c_pseudoref}REVERT_HEAD${c_reset}${c_symbol}, ${c_reset}\ ${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_symbol}, ${c_reset}\ ${c_ref}refs/foo${c_reset}${c_symbol})${c_reset} A EOF - git log --first-parent --no-abbrev --decorate --clear-decorations \ - --oneline --color=always --all >actual && + git log --first-parent --no-abbrev --decorate --color=always \ + --decorate-refs-exclude=FETCH_HEAD --oneline --all >actual && cmp_filtered_decorations '