Skip to content

Commit 1f67290

Browse files
stefanbellergitster
authored andcommitted
sideband: color lines with keyword only
When bf1a11f (sideband: highlight keywords in remote sideband output, 2018-08-07) was introduced, it was carefully considered which strings would be highlighted. However 59a255a (sideband: do not read beyond the end of input, 2018-08-18) brought in a regression that the original did not test for. A line containing only the keyword and nothing else ("SUCCESS") should still be colored. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 59a255a commit 1f67290

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

sideband.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
8787
struct keyword_entry *p = keywords + i;
8888
int len = strlen(p->keyword);
8989

90-
if (n <= len)
90+
if (n < len)
9191
continue;
9292
/*
9393
* Match case insensitively, so we colorize output from existing
9494
* servers regardless of the case that they use for their
9595
* messages. We only highlight the word precisely, so
9696
* "successful" stays uncolored.
9797
*/
98-
if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
98+
if (!strncasecmp(p->keyword, src, len) &&
99+
(len == n || !isalnum(src[len]))) {
99100
strbuf_addstr(dest, p->color);
100101
strbuf_add(dest, src, len);
101102
strbuf_addstr(dest, GIT_COLOR_RESET);

t/t5409-colorize-remote-messages.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
1717
echo " " "error: leading space"
1818
echo " "
1919
echo Err
20+
echo SUCCESS
2021
exit 0
2122
EOF
2223
echo 1 >file &&
@@ -35,6 +36,7 @@ test_expect_success 'keywords' '
3536
grep "<BOLD;RED>error<RESET>: error" decoded &&
3637
grep "<YELLOW>hint<RESET>:" decoded &&
3738
grep "<BOLD;GREEN>success<RESET>:" decoded &&
39+
grep "<BOLD;GREEN>SUCCESS<RESET>" decoded &&
3840
grep "<BOLD;YELLOW>warning<RESET>:" decoded
3941
'
4042

0 commit comments

Comments
 (0)