From: "Robert Estelle via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Robert Estelle <robert.estelle@gmail.com>,
Robert Estelle <robertestelle@gmail.com>
Subject: [PATCH 3/3] blame: support multiple values in blame.coloring
Date: Thu, 02 Feb 2023 19:16:46 +0000 [thread overview]
Message-ID: <e33ae071e27faf16f90f4a71e80840c7f3897b50.1675365406.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1449.git.git.1675365406.gitgitgadget@gmail.com>
From: Robert Estelle <robertestelle@gmail.com>
`blame.coloring` is now parsed as a comma-separated list, so that both
colorizers ("by age" and "by repeated lines") can be enabled via
configuration. Previously, they could be specified together on the
command line via --color-by-age and --color-lines, but not by config.
Signed-off-by: Robert Estelle <robertestelle@gmail.com>
---
Documentation/config/blame.txt | 1 +
builtin/blame.c | 47 +++++++++++++++++++++++++---------
t/t8012-blame-colors.sh | 8 ++++++
3 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/Documentation/config/blame.txt b/Documentation/config/blame.txt
index 4d047c17908..8624c4dc5d4 100644
--- a/Documentation/config/blame.txt
+++ b/Documentation/config/blame.txt
@@ -6,6 +6,7 @@ blame.coloring::
This determines the coloring scheme to be applied to blame
output. It can be 'repeatedLines', 'highlightRecent',
or 'none' which is the default.
+ Multiple values may be separated by commas.
blame.date::
Specifies the format used to output dates in linkgit:git-blame[1].
diff --git a/builtin/blame.c b/builtin/blame.c
index 71f925e456c..eea1418d209 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -685,6 +685,39 @@ static const char *add_prefix(const char *prefix, const char *path)
return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
}
+static unsigned parse_blame_coloring_mode(const char *arg)
+{
+ int ret = 0;
+ struct string_list l = STRING_LIST_INIT_DUP;
+ struct string_list_item *i;
+
+ string_list_split(&l, arg, ',', -1);
+
+ for_each_string_list_item(i, &l) {
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_addstr(&sb, i->string);
+ strbuf_trim(&sb);
+
+ if (!strcmp(sb.buf, "none")) {
+ ret = 0;
+ } else if (!strcmp(sb.buf, "repeatedLines")) {
+ ret |= OUTPUT_COLOR_LINE;
+ } else if (!strcmp(sb.buf, "highlightRecent")) {
+ ret |= OUTPUT_SHOW_AGE_WITH_COLOR;
+ } else {
+ warning(_("invalid value for '%s': '%s'"),
+ "blame.coloring", sb.buf);
+ ret = 0;
+ }
+
+ strbuf_release(&sb);
+ }
+
+ string_list_clear(&l, 0);
+
+ return ret;
+}
+
static int git_blame_config(const char *var, const char *value, void *cb)
{
if (!strcmp(var, "blame.showroot")) {
@@ -739,18 +772,8 @@ static int git_blame_config(const char *var, const char *value, void *cb)
}
if (!strcmp(var, "blame.coloring")) {
- if (!strcmp(value, "repeatedLines")) {
- coloring_mode |= OUTPUT_COLOR_LINE;
- } else if (!strcmp(value, "highlightRecent")) {
- coloring_mode |= OUTPUT_SHOW_AGE_WITH_COLOR;
- } else if (!strcmp(value, "none")) {
- coloring_mode &= ~(OUTPUT_COLOR_LINE |
- OUTPUT_SHOW_AGE_WITH_COLOR);
- } else {
- warning(_("invalid value for '%s': '%s'"),
- "blame.coloring", value);
- return 0;
- }
+ coloring_mode = parse_blame_coloring_mode(value);
+ return 0;
}
if (git_diff_heuristic_config(var, value, cb) < 0)
diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh
index 820f86c3aed..051f734ea03 100755
--- a/t/t8012-blame-colors.sh
+++ b/t/t8012-blame-colors.sh
@@ -89,6 +89,14 @@ test_expect_success 'blame color by age and lines' '
hello.c \
>actual.raw &&
+ git \
+ -c color.blame.repeatedLines=blue \
+ -c color.blame.highlightRecent="yellow,1 month ago, cyan" \
+ -c blame.coloring=highlightRecent,repeatedLines \
+ blame hello.c \
+ >actual.raw.2 &&
+ test_cmp actual.raw actual.raw.2 &&
+
test_decode_color <actual.raw >actual &&
normalize_color_decoded_blame <actual >actual.norm &&
--
gitgitgadget
prev parent reply other threads:[~2023-02-02 19:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 19:16 [PATCH 0/3] blame: allow blame.coloring to specify both --color-lines and --color-by-age Robert Estelle via GitGitGadget
2023-02-02 19:16 ` [PATCH 1/3] blame: add test for --color-lines + --color-by-age Robert Estelle via GitGitGadget
2023-02-02 19:16 ` [PATCH 2/3] blame: document --color-{lines,by-age} config Robert Estelle via GitGitGadget
2023-02-02 19:16 ` Robert Estelle via GitGitGadget [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e33ae071e27faf16f90f4a71e80840c7f3897b50.1675365406.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=robert.estelle@gmail.com \
--cc=robertestelle@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).