* [PATCH 1/2] Document git config getter return value. @ 2018-07-30 12:18 Han-Wen Nienhuys 2018-07-30 12:18 ` [PATCH 2/2] Highlight keywords in remote sideband output Han-Wen Nienhuys 0 siblings, 1 reply; 7+ messages in thread From: Han-Wen Nienhuys @ 2018-07-30 12:18 UTC (permalink / raw) To: git; +Cc: Han-Wen Nienhuys --- config.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index b95bb7649..d39256eb1 100644 --- a/config.h +++ b/config.h @@ -178,11 +178,16 @@ struct config_set { }; extern void git_configset_init(struct config_set *cs); -extern int git_configset_add_file(struct config_set *cs, const char *filename); -extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value); + extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key); extern void git_configset_clear(struct config_set *cs); + +/* + * The int return values in these functions is 1 if not found, 0 if found, leaving + * the found value in the 'dest' pointer. + */ +extern int git_configset_add_file(struct config_set *cs, const char *filename); +extern int git_configset_get_value(struct config_set *cs, const char *key, const char **dest); extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest); extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest); extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest); -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] Highlight keywords in remote sideband output. 2018-07-30 12:18 [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys @ 2018-07-30 12:18 ` Han-Wen Nienhuys 0 siblings, 0 replies; 7+ messages in thread From: Han-Wen Nienhuys @ 2018-07-30 12:18 UTC (permalink / raw) To: git; +Cc: Han-Wen Nienhuys The highlighting is done on the client-side. Supported keywords are "error", "warning", "hint" and "success". The colorization is controlled with the config setting "color.remote". Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Change-Id: I090412a1288bc2caef0916447e28c2d0199da47d --- sideband.c | 79 +++++++++++++++++++++++++---- t/t5409-colorize-remote-messages.sh | 34 +++++++++++++ 2 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 t/t5409-colorize-remote-messages.sh diff --git a/sideband.c b/sideband.c index 325bf0e97..15213a7c1 100644 --- a/sideband.c +++ b/sideband.c @@ -1,6 +1,63 @@ #include "cache.h" #include "pkt-line.h" #include "sideband.h" +#include "color.h" + +static int sideband_use_color = -1; + +/* + * Optionally highlight some keywords in remote output if they appear at the + * start of the line. + */ +void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n) +{ + if (sideband_use_color < 0) { + const char *key = "color.remote"; + char *value = NULL; + if (!git_config_get_string(key, &value)) + sideband_use_color = git_config_colorbool(key, value); + } + + int want_color = want_color_stderr(sideband_use_color); + int i; + + if (!want_color) { + strbuf_add(dest, src, n); + return; + } + + struct kwtable { + const char *keyword; + const char *color; + } keywords[] = { + {"hint", GIT_COLOR_YELLOW}, + {"warning", GIT_COLOR_BOLD_YELLOW}, + {"success", GIT_COLOR_BOLD_GREEN}, + {"error", GIT_COLOR_BOLD_RED}, + }; + + while (isspace(*src)) { + strbuf_addch(dest, *src); + src++; + n--; + } + + for (i = 0; i < ARRAY_SIZE(keywords); i++) { + struct kwtable* p = keywords + i; + int len = strlen(p->keyword); + if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) { + strbuf_addstr(dest, p->color); + strbuf_add(dest, src, len); + strbuf_addstr(dest, GIT_COLOR_RESET); + n -= len; + src += len; + break; + } + } + + strbuf_add(dest, src, n); +} + /* * Receive multiplexed output stream over git native protocol. @@ -48,8 +105,10 @@ int recv_sideband(const char *me, int in_stream, int out) len--; switch (band) { case 3: - strbuf_addf(&outbuf, "%s%s%s", outbuf.len ? "\n" : "", - DISPLAY_PREFIX, buf + 1); + strbuf_addf(&outbuf, "%s%s", outbuf.len ? "\n" : "", + DISPLAY_PREFIX); + maybe_colorize_sideband(&outbuf, buf + 1, len); + retval = SIDEBAND_REMOTE_ERROR; break; case 2: @@ -69,20 +128,22 @@ int recv_sideband(const char *me, int in_stream, int out) if (!outbuf.len) strbuf_addstr(&outbuf, DISPLAY_PREFIX); if (linelen > 0) { - strbuf_addf(&outbuf, "%.*s%s%c", - linelen, b, suffix, *brk); - } else { - strbuf_addch(&outbuf, *brk); + maybe_colorize_sideband(&outbuf, b, linelen); + strbuf_addstr(&outbuf, suffix); } + + strbuf_addch(&outbuf, *brk); xwrite(2, outbuf.buf, outbuf.len); strbuf_reset(&outbuf); b = brk + 1; } - if (*b) - strbuf_addf(&outbuf, "%s%s", outbuf.len ? - "" : DISPLAY_PREFIX, b); + if (*b) { + strbuf_addstr(&outbuf, outbuf.len ? + "" : DISPLAY_PREFIX); + maybe_colorize_sideband(&outbuf, b, strlen(b)); + } break; case 1: write_or_die(out, buf + 1, len); diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh new file mode 100644 index 000000000..1620cffbe --- /dev/null +++ b/t/t5409-colorize-remote-messages.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +test_description='remote messages are colorized on the client' + +. ./test-lib.sh + +test_expect_success 'setup' ' + mkdir .git/hooks && + cat << EOF > .git/hooks/update && +#!/bin/sh +echo error: error +echo hint: hint +echo success: success +echo warning: warning +exit 0 +EOF + chmod +x .git/hooks/update && + echo 1 >file && + git add file && + git commit -m 1 && + git clone . child && + cd child && + echo 2 > file && + git commit -a -m 2 +' + +test_expect_success 'push' 'git -c color.remote push origin HEAD:refs/heads/newbranch 2>output && + test_decode_color < output > decoded && + test_i18ngrep "<BOLD;RED>error<RESET>:" decoded && + test_i18ngrep "<YELLOW>hint<RESET>:" decoded && + test_i18ngrep "<BOLD;GREEN>success<RESET>:" decoded && + test_i18ngrep "<BOLD;YELLOW>warning<RESET>:" decoded' + +test_done -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 1/2] Document git config getter return value. @ 2018-07-30 12:26 Han-Wen Nienhuys 2018-07-30 18:48 ` Eric Sunshine 0 siblings, 1 reply; 7+ messages in thread From: Han-Wen Nienhuys @ 2018-07-30 12:26 UTC (permalink / raw) To: git; +Cc: Han-Wen Nienhuys --- config.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index b95bb7649..d39256eb1 100644 --- a/config.h +++ b/config.h @@ -178,11 +178,16 @@ struct config_set { }; extern void git_configset_init(struct config_set *cs); -extern int git_configset_add_file(struct config_set *cs, const char *filename); -extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value); + extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key); extern void git_configset_clear(struct config_set *cs); + +/* + * The int return values in these functions is 1 if not found, 0 if found, leaving + * the found value in the 'dest' pointer. + */ +extern int git_configset_add_file(struct config_set *cs, const char *filename); +extern int git_configset_get_value(struct config_set *cs, const char *key, const char **dest); extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest); extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest); extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest); -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Document git config getter return value. 2018-07-30 12:26 [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys @ 2018-07-30 18:48 ` Eric Sunshine 2018-07-30 20:03 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Eric Sunshine @ 2018-07-30 18:48 UTC (permalink / raw) To: Han-Wen Nienhuys; +Cc: Git List On Mon, Jul 30, 2018 at 8:26 AM Han-Wen Nienhuys <hanwen@google.com> wrote: > --- > config.h | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) Missing sign-off. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Document git config getter return value. 2018-07-30 18:48 ` Eric Sunshine @ 2018-07-30 20:03 ` Junio C Hamano 0 siblings, 0 replies; 7+ messages in thread From: Junio C Hamano @ 2018-07-30 20:03 UTC (permalink / raw) To: Eric Sunshine; +Cc: Han-Wen Nienhuys, Git List Eric Sunshine <sunshine@sunshineco.com> writes: > On Mon, Jul 30, 2018 at 8:26 AM Han-Wen Nienhuys <hanwen@google.com> wrote: >> --- >> config.h | 10 ++++++++-- >> 1 file changed, 8 insertions(+), 2 deletions(-) > > Missing sign-off. Besides, the patch is corrupt in that it miscounts both preimage and postimage lines and claims it applies to a 11-line block even though there are only 10 lines there. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 0/2 v3] Highlight keywords in remote sideband output. @ 2018-07-31 17:36 Han-Wen Nienhuys 2018-07-31 17:36 ` [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys 0 siblings, 1 reply; 7+ messages in thread From: Han-Wen Nienhuys @ 2018-07-31 17:36 UTC (permalink / raw) To: gitster; +Cc: git, Han-Wen Nienhuys squash in Duy's patch Han-Wen Nienhuys (2): Document git config getter return value. Highlight keywords in remote sideband output. Documentation/config.txt | 9 +++ config.h | 10 ++- help.c | 1 + help.h | 1 + sideband.c | 113 +++++++++++++++++++++++++--- t/t5409-colorize-remote-messages.sh | 47 ++++++++++++ 6 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 t/t5409-colorize-remote-messages.sh -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] Document git config getter return value. 2018-07-31 17:36 [PATCH 0/2 v3] Highlight keywords in remote sideband output Han-Wen Nienhuys @ 2018-07-31 17:36 ` Han-Wen Nienhuys 2018-08-01 8:24 ` Eric Sunshine 0 siblings, 1 reply; 7+ messages in thread From: Han-Wen Nienhuys @ 2018-07-31 17:36 UTC (permalink / raw) To: gitster; +Cc: git, Han-Wen Nienhuys --- config.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index b95bb7649..d39256eb1 100644 --- a/config.h +++ b/config.h @@ -178,10 +178,16 @@ struct config_set { }; extern void git_configset_init(struct config_set *cs); -extern int git_configset_add_file(struct config_set *cs, const char *filename); -extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value); + extern const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key); extern void git_configset_clear(struct config_set *cs); + +/* + * The int return values in the functions is 1 if not found, 0 if found, leaving + * the found value in teh 'dest' pointer. + */ +extern int git_configset_add_file(struct config_set *cs, const char *filename); +extern int git_configset_get_value(struct config_set *cs, const char *key, const char **dest); extern int git_configset_get_string_const(struct config_set *cs, const char *key, const char **dest); extern int git_configset_get_string(struct config_set *cs, const char *key, char **dest); extern int git_configset_get_int(struct config_set *cs, const char *key, int *dest); -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] Document git config getter return value. 2018-07-31 17:36 ` [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys @ 2018-08-01 8:24 ` Eric Sunshine 0 siblings, 0 replies; 7+ messages in thread From: Eric Sunshine @ 2018-08-01 8:24 UTC (permalink / raw) To: Han-Wen Nienhuys; +Cc: Junio C Hamano, Git List On Tue, Jul 31, 2018 at 1:37 PM Han-Wen Nienhuys <hanwen@google.com> wrote: > diff --git a/config.h b/config.h > @@ -178,10 +178,16 @@ struct config_set { > +/* > + * The int return values in the functions is 1 if not found, 0 if found, leaving > + * the found value in teh 'dest' pointer. > + */ "teh"? Instead of talking about "the int return values", simpler would be to say "returns 1 if ...; else 0". Not worth a re-roll, though. > +extern int git_configset_add_file(struct config_set *cs, const char *filename); > +extern int git_configset_get_value(struct config_set *cs, const char *key, const char **dest); ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-08-01 8:24 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-07-30 12:18 [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys 2018-07-30 12:18 ` [PATCH 2/2] Highlight keywords in remote sideband output Han-Wen Nienhuys -- strict thread matches above, loose matches on Subject: below -- 2018-07-30 12:26 [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys 2018-07-30 18:48 ` Eric Sunshine 2018-07-30 20:03 ` Junio C Hamano 2018-07-31 17:36 [PATCH 0/2 v3] Highlight keywords in remote sideband output Han-Wen Nienhuys 2018-07-31 17:36 ` [PATCH 1/2] Document git config getter return value Han-Wen Nienhuys 2018-08-01 8:24 ` Eric Sunshine
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).