git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sunshine@sunshineco.com,
	Stefan Beller <sbeller@google.com>
Subject: [PATCH 3/3] builtin/blame: add new coloring scheme config
Date: Mon, 23 Apr 2018 17:09:00 -0700	[thread overview]
Message-ID: <20180424000900.175235-4-sbeller@google.com> (raw)
In-Reply-To: <20180424000900.175235-1-sbeller@google.com>

Add a config option that allows selecting the default color scheme for
blame. The command line still takes precedence over the configuration.

It is to be seen, how color.ui will integrate with blame coloring.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/config.txt |  5 +++++
 builtin/blame.c          | 18 ++++++++++++++++++
 t/t8012-blame-colors.sh  |  4 ++++
 3 files changed, 27 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1496fa4917..c03e20cf23 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1240,6 +1240,11 @@ everything older than one year blue, recent changes between one month and
 one year old are kept white, and lines introduced within the last month are
 colored red.
 
+blame.coloring::
+	This determines the coloring scheme to be applied to blame
+	output. It can be 'repeatedLines', 'highlightRecent',
+	or 'none' which is the default.
+
 color.ui::
 	This variable determines the default value for variables such
 	as `color.diff` and `color.grep` that control the use of color
diff --git a/builtin/blame.c b/builtin/blame.c
index d1d469c0b5..fede1cf1e3 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -49,6 +49,7 @@ static int abbrev = -1;
 static int no_whole_file_rename;
 static int show_progress;
 static char repeated_meta_color[COLOR_MAXLEN];
+static int coloring_mode;
 
 static struct date_mode blame_date_mode = { DATE_ISO8601 };
 static size_t blame_date_width;
@@ -702,6 +703,20 @@ static int git_blame_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 
+	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 blame.coloring"));
+			return 0;
+		}
+	}
+
 	if (git_diff_heuristic_config(var, value, cb) < 0)
 		return -1;
 	if (userdiff_config(var, value) < 0)
@@ -1046,6 +1061,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 
 	blame_coalesce(&sb);
 
+	if (!(output_option & (OUTPUT_COLOR_LINE | OUTPUT_SHOW_AGE_WITH_COLOR)))
+		output_option |= coloring_mode;
+
 	if (!(output_option & OUTPUT_PORCELAIN)) {
 		find_alignment(&sb, &output_option);
 		if (!*repeated_meta_color &&
diff --git a/t/t8012-blame-colors.sh b/t/t8012-blame-colors.sh
index ae9aa79d4e..ed38f74de9 100755
--- a/t/t8012-blame-colors.sh
+++ b/t/t8012-blame-colors.sh
@@ -8,6 +8,8 @@ PROG='git blame -c'
 
 test_expect_success 'colored blame colors contiguous lines' '
 	git -c color.blame.repeatedLines=yellow blame --color-lines --abbrev=12 hello.c >actual.raw &&
+	git -c color.blame.repeatedLines=yellow -c blame.coloring=repeatedLines blame --abbrev=12 hello.c >actual.raw.2 &&
+	test_cmp actual.raw actual.raw.2 &&
 	test_decode_color <actual.raw >actual &&
 	grep "<YELLOW>" <actual >darkened &&
 	grep "(F" darkened > F.expect &&
@@ -18,6 +20,8 @@ test_expect_success 'colored blame colors contiguous lines' '
 
 test_expect_success 'color by age consistently colors old code' '
 	git blame --color-by-age hello.c >actual.raw &&
+	git -c blame.coloring=highlightRecent blame hello.c >actual.raw.2 &&
+	test_cmp actual.raw actual.raw.2 &&
 	test_decode_color <actual.raw >actual &&
 	grep "<BLUE>" <actual >colored &&
 	test_line_count = 10 colored
-- 
2.17.0.441.gb46fe60e1d-goog


  parent reply	other threads:[~2018-04-24  0:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-24  0:08 [PATCH 0/3] Colorful blame output Stefan Beller
2018-04-24  0:08 ` [PATCH 1/3] builtin/blame: dim uninteresting metadata lines Stefan Beller
2018-04-24  0:08 ` [PATCH 2/3] builtin/blame: highlight recently changed lines Stefan Beller
2018-04-24  0:09 ` Stefan Beller [this message]
2018-04-24  2:09 ` [PATCH 0/3] Colorful blame output Junio C Hamano
2018-04-24 18:05   ` Stefan Beller

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180424000900.175235-4-sbeller@google.com \
    --to=sbeller@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).