sideband: color lines with keyword only
Whenmaintbf1a11f0a1
(sideband: highlight keywords in remote sideband output, 2018-08-07) was introduced, it was carefully considered which strings would be highlighted. However59a255aef0
(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>
parent
59a255aef0
commit
1f67290450
|
@ -87,7 +87,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
|
||||||
struct keyword_entry *p = keywords + i;
|
struct keyword_entry *p = keywords + i;
|
||||||
int len = strlen(p->keyword);
|
int len = strlen(p->keyword);
|
||||||
|
|
||||||
if (n <= len)
|
if (n < len)
|
||||||
continue;
|
continue;
|
||||||
/*
|
/*
|
||||||
* Match case insensitively, so we colorize output from existing
|
* Match case insensitively, so we colorize output from existing
|
||||||
|
@ -95,7 +95,8 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
|
||||||
* messages. We only highlight the word precisely, so
|
* messages. We only highlight the word precisely, so
|
||||||
* "successful" stays uncolored.
|
* "successful" stays uncolored.
|
||||||
*/
|
*/
|
||||||
if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
|
if (!strncasecmp(p->keyword, src, len) &&
|
||||||
|
(len == n || !isalnum(src[len]))) {
|
||||||
strbuf_addstr(dest, p->color);
|
strbuf_addstr(dest, p->color);
|
||||||
strbuf_add(dest, src, len);
|
strbuf_add(dest, src, len);
|
||||||
strbuf_addstr(dest, GIT_COLOR_RESET);
|
strbuf_addstr(dest, GIT_COLOR_RESET);
|
||||||
|
|
|
@ -17,6 +17,7 @@ test_expect_success 'setup' '
|
||||||
echo " " "error: leading space"
|
echo " " "error: leading space"
|
||||||
echo " "
|
echo " "
|
||||||
echo Err
|
echo Err
|
||||||
|
echo SUCCESS
|
||||||
exit 0
|
exit 0
|
||||||
EOF
|
EOF
|
||||||
echo 1 >file &&
|
echo 1 >file &&
|
||||||
|
@ -35,6 +36,7 @@ test_expect_success 'keywords' '
|
||||||
grep "<BOLD;RED>error<RESET>: error" decoded &&
|
grep "<BOLD;RED>error<RESET>: error" decoded &&
|
||||||
grep "<YELLOW>hint<RESET>:" decoded &&
|
grep "<YELLOW>hint<RESET>:" decoded &&
|
||||||
grep "<BOLD;GREEN>success<RESET>:" decoded &&
|
grep "<BOLD;GREEN>success<RESET>:" decoded &&
|
||||||
|
grep "<BOLD;GREEN>SUCCESS<RESET>" decoded &&
|
||||||
grep "<BOLD;YELLOW>warning<RESET>:" decoded
|
grep "<BOLD;YELLOW>warning<RESET>:" decoded
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue