Skip to contentSkip to conversation

sideband: highlight keywords in remote sideband output

PATCH Superseded Han-Wen Nienhuys 5 participants 10 messages Aug 2, 2018 – Aug 6, 2018 Documentation

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover sideband: highlight keywords in remote sideband output

Address Eric Sunshine's comments.

Han-Wen Nienhuys (2):
config: document git config getter return value.
sideband: highlight keywords in remote sideband output

 Documentation/config.txt            |   9 +++
 config.h                            |  10 ++-
 help.c                              |   1 +
 help.h                              |   1 +
 sideband.c                          | 119 +++++++++++++++++++++++++---
 t/t5409-colorize-remote-messages.sh |  47 +++++++++++
 6 files changed, 176 insertions(+), 11 deletions(-)
 create mode 100644 t/t5409-colorize-remote-messages.sh

--
2.18.0.597.ga71716f1ad-goog

#1 lore raw

PATCH v4 1/2 config: document git config getter return value.

---
 config.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
config.h +8 -2
index b95bb7649..41700f40b 100644
@@ -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);
+
+/*
+ * These functions return 1 if not found, and 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);
Signature · 1 line
2.18.0.597.ga71716f1ad-goog
#2 lore raw

Re: [PATCH 1/2] config: document git config getter return value.

Quoted 4 lines · Han-Wen Nienhuys
config.h +0 -1
@@ -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);

config.h struct config_set { · line 187

Quoted 10 lines
config.h +6 -1
-extern int git_configset_get_value(struct config_set *cs, const char *key, const char **value);
+/*
+ * These functions return 1 if not found, and 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);

It doesn't seem like git_configset_add_file() fits in this group. It's neither searching for something (thus won't return "found" / "not found"), nor is it returning 0 or 1. (It returns 0 on success and -1 on failure.)

Reviewed-by on v4 1/2
#3 lore raw

Re: [PATCH 1/2] config: document git config getter return value.

In reply to Han-Wen Nienhuys

(cc-ing peff, config whiz)
Hi,

Quoted 1 line · Han-Wen Nienhuys

Subject: config: document git config getter return value.

micronit: no period at the end of subject line

Quoted 3 lines
---
 config.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

May we forge your sign-off? See Documentation/SubmittingPatches section [[sign-off]] for what this means.

config.h struct config_set { · line 181

Quoted 12 lines
config.h +1 -2
index b95bb7649..41700f40b 100644
@@ -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);
+

nit: this blank line feels out of place (though I don't particularly mind it and wouldn't reroll just for that)

config.h struct config_set { · line 189

Quoted 8 lines
config.h +6 -0
 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);
+
+/*
+ * These functions return 1 if not found, and 0 if found, leaving the found
+ * value in the 'dest' pointer.
+ */
+extern int git_configset_add_file(struct config_set *cs, const char *filename);

This function doesn't take a 'dest' argument. Is the comment meant to apply to it? If not, can the comment go below it?

config.h struct config_set { · line 193

Quoted 4 lines
config.h +1 -0
+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);

With a sign-off and whatever subset of the above suggestions makes sense to you,

Thanks.

#4 lore raw

Re: [PATCH 1/2] config: document git config getter return value.

Quoted 1 line · Jonathan Nieder

(cc-ing peff, config whiz)

Actually, this is all about the configset caching layer, which I never really worked on. This is mostly from Tanay Abhra <[email protected]>, who was a GSoC student mentored by Matthieu Moy <[email protected]>.

That said...

Quoted 9 lines

config.h struct config_set { · line 189

Quoted 6 lines
config.h +6 -0
+
+/*
+ * These functions return 1 if not found, and 0 if found, leaving the found
+ * value in the 'dest' pointer.
+ */
+extern int git_configset_add_file(struct config_set *cs, const char *filename);

This function doesn't take a 'dest' argument. Is the comment meant to apply to it? If not, can the comment go below it?

This is returning the value of git_config_from_file(), which is 0/-1. I think it should be left where it is in the original, and not part of this block of functions.

Other than that, the patch seems sane to me (I think the 0/1 return value from these "get" functions is unnecessarily inconsistent with the rest of Git, but changing it would be a pain. Documenting it is at least a step forward).

-Peff

#5 lore raw

Re: [PATCH 1/2] config: document git config getter return value.

Quoted 8 lines · Jeff King

This is returning the value of git_config_from_file(), which is 0/-1. I think it should be left where it is in the original, and not part of this block of functions.

Other than that, the patch seems sane to me (I think the 0/1 return value from these "get" functions is unnecessarily inconsistent with the rest of Git, but changing it would be a pain. Documenting it is at least a step forward).

I do not think changing it would be in the scope of this series.

It makes sense to document (1) that zero is success, non-zero is failure, to help those who are reading the current callers and adding new callers, and (2) that we are aware that the exact "non-zero" value chosen for these are not in line with the rest of the system. The latter can just be a "NEEDSWORK" comment.

#6 lore raw

PATCH v4 2/2 sideband: highlight keywords in remote sideband output

In reply to Han-Wen Nienhuys

The colorization is controlled with the config setting "color.remote".

Supported keywords are "error", "warning", "hint" and "success". They are highlighted if they appear at the start of the line, which is common in error messages, eg.

ERROR: commit is missing Change-Id

The rationale for this change is that Gerrit does server-side processing to create or update code reviews, and actionable error messages (eg. missing Change-Id) must be communicated back to the user during the push. User research has shown that new users have trouble seeing these messages.

The Git push process itself prints lots of non-actionable messages (eg. bandwidth statistics, object counters for different phases of the process), and my hypothesis is that these obscure the actionable error messages that our server sends back. Highlighting keywords in the draws more attention to actionable messages.

The highlighting is done on the client rather than server side, so servers don't have to grow capabilities to understand terminal escape codes and terminal state. It also consistent with the current state where Git is control of the local display (eg. prefixing messages with "remote: ").

Finally, this solution is backwards compatible: many servers already prefix their messages with "error", and they will benefit from this change without requiring a server update. By contrast, a server-side solution would likely require plumbing the TERM variable through the git protocol, so it would require changes to both server and client.

---
 Documentation/config.txt            |   9 +++
 help.c                              |   1 +
 help.h                              |   1 +
 sideband.c                          | 119 +++++++++++++++++++++++++---
 t/t5409-colorize-remote-messages.sh |  47 +++++++++++
 5 files changed, 168 insertions(+), 9 deletions(-)
 create mode 100644 t/t5409-colorize-remote-messages.sh
Documentation/config.txt +9 -0
index 43b2de7b5..0783323be 100644
@@ -1229,6 +1229,15 @@ color.push::
 color.push.error::
 	Use customized color for push errors.
 
+color.remote::
+	A boolean to enable/disable colored remote output. If unset,
+	then the value of `color.ui` is used (`auto` by default).
+
+color.remote.<slot>::
+	Use customized color for each remote keywords. `<slot>` may be
+	`hint`, `warning`, `success` or `error` which match the
+	corresponding keyword.
+
 color.showBranch::
 	A boolean to enable/disable color in the output of
 	linkgit:git-show-branch[1]. May be set to `always`,
help.c +1 -0
index 3ebf0568d..b6cafcfc0 100644
@@ -425,6 +425,7 @@ void list_config_help(int for_human)
 		{ "color.diff", "<slot>", list_config_color_diff_slots },
 		{ "color.grep", "<slot>", list_config_color_grep_slots },
 		{ "color.interactive", "<slot>", list_config_color_interactive_slots },
+		{ "color.remote", "<slot>", list_config_color_sideband_slots },
 		{ "color.status", "<slot>", list_config_color_status_slots },
 		{ "fsck", "<msg-id>", list_config_fsck_msg_ids },
 		{ "receive.fsck", "<msg-id>", list_config_fsck_msg_ids },
help.h +1 -0
index f8b15323a..9eab6a3f8 100644
@@ -83,6 +83,7 @@ void list_config_color_diff_slots(struct string_list *list, const char *prefix);
 void list_config_color_grep_slots(struct string_list *list, const char *prefix);
 void list_config_color_interactive_slots(struct string_list *list, const char *prefix);
 void list_config_color_status_slots(struct string_list *list, const char *prefix);
+void list_config_color_sideband_slots(struct string_list *list, const char *prefix);
 void list_config_fsck_msg_ids(struct string_list *list, const char *prefix);
 
 #endif /* HELP_H */
sideband.c +110 -9

144 lines not on this page · raw message

t/t5409-colorize-remote-messages.sh new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.18.0.597.ga71716f1ad-goog
#7 lore raw
Quoted 1 line · Han-Wen Nienhuys

[PATCH 2/2] sideband: highlight keywords in remote sideband output

The -v option of git-format-patch makes it easy to let reviewers know that this is a new version of a previously-submitted patch series. This (I think) is the second attempt; if you need to send again, you could use "git format-patch -v3 ...", which would result in "[PATCH v3 2/2] ...".

Quoted 6 lines

The colorization is controlled with the config setting "color.remote".

Supported keywords are "error", "warning", "hint" and "success". They are highlighted if they appear at the start of the line, which is common in error messages, eg.

Quoted 8 lines

ERROR: commit is missing Change-Id

The rationale for this change is that Gerrit does server-side processing to create or update code reviews, and actionable error messages (eg. missing Change-Id) must be communicated back to the user during the push. User research has shown that new users have trouble seeing these messages.
[...snip...]

Thanks, this commit message is much more helpful than the previous one.

If you end up re-rolling, you might consider swapping the order of these paragraphs around a bit to first explain the problem the patch is solving (i.e. the justification), then the solution and relevant details. Documentation/SubmittingPatches has good advice about this.

Using Gerrit as the sole rationale is underselling this otherwise general improvement. Instead, the commit message could sell the change on its own merits and can then use Gerrit as an example.

Quoted 5 lines

The Git push process itself prints lots of non-actionable messages (eg. bandwidth statistics, object counters for different phases of the process), and my hypothesis is that these obscure the actionable error messages that our server sends back. Highlighting keywords in the draws more attention to actionable messages.

So, for instance, you might want to use a rewrite of this paragraph to open the commit message. Something like this, perhaps:

A remote Git operation can print many non-actionable messages (e.g. bandwidth statistics, object counters for different phases of the process, etc.) and such noise can obscure genuine actionable messages, such as warnings and outright errors.

As an example, Gerrit does server-side processing to create or update code reviews, and actionable error messages (such as "ERROR: commit is missing Change-Id") must be communicated back to the user during a push operation, but new users often have trouble spotting these error messages amid the noise.

Address this problem by upgrading 'sideband' to draw attention to these messages by highlighting them with color.

[...and so forth...]

sideband.c line 6

Quoted 10 lines

---

sideband.c +6 -0
@@ -1,6 +1,103 @@
+struct kwtable {
+       /*
+        * We use keyword as config key so it can't contain funny chars like
+        * spaces. When we do that, we need a separate field for slot name in
+        * load_sideband_colors().
+        */

This comment is outdated; load_sideband_colors() does not exist in this patch.

I get what the first sentence of this comment is saying, but I'm having trouble understanding what the second sentence is all about.

sideband.c line 25

Quoted 12 lines
sideband.c +12 -0
+       const char *keyword;
+       char color[COLOR_MAXLEN];
+};
+
+static struct kwtable keywords[] = {
+       { "hint",       GIT_COLOR_YELLOW },
+       { "warning",    GIT_COLOR_BOLD_YELLOW },
+       { "success",    GIT_COLOR_BOLD_GREEN },
+       { "error",      GIT_COLOR_BOLD_RED },
+};
+
+// Returns a color setting (GIT_COLOR_NEVER, etc).

Use /* old-style C comments */ in this codebase, not // C++ or new-style C.

sideband.c line 39

Quoted 10 lines
sideband.c +10 -0
+static int use_sideband_colors(void)
+{
+       static int use_sideband_colors_cached = -1;
+       const char *key = "color.remote";
+
+       if (use_sideband_colors_cached >= 0)
+               return use_sideband_colors_cached;
+
+       if (!git_config_get_string(key, &value))
+               use_sideband_colors_cached = git_config_colorbool(key, value);

So, if "color.remote" exists, then 'use_sideband_colors_cached' is assigned. However, if "color.remote" does not exist, then it's never assigned. Is this intended behavior? It seems like you'd want to fall back to some other value rather than leaving it unassigned.

Which leads to the next question: The documentation says that this falls back to "color.ui" if "color.remote" does not exist, however, where is this fallback happening? Am I overlooking something obvious?

sideband.c line 47

Quoted 7 lines
sideband.c +7 -0
+       for (i = 0; i < ARRAY_SIZE(keywords); i++) {
+               strbuf_reset(&sb);
+               strbuf_addf(&sb, "%s.%s", key, keywords[i].keyword);
+               if (git_config_get_string(sb.buf, &value))
+                       continue;
+               if (color_parse(value, keywords[i].color))
+                       die(_("expecting a color: %s"), value);

This error message would be much more helpful if it also told the user the name of the config key from which 'value' came.

sideband.c line 36

Quoted 1 line
sideband.c +1 -0
+       }

Do you need to be doing the work in the above for-loop if, after computing 'use_sideband_colors_cached', it is determined that you won't be using color?

Quoted 5 lines
sideband.c +3 -0
+       strbuf_release(&sb);
+       return use_sideband_colors_cached;
+}

t/t5409-colorize-remote-messages.sh line 9

Quoted 9 lines
t/t5409-colorize-remote-messages.sh +9 -0
@@ -0,0 +1,47 @@
+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
+echo prefixerror: error

I addition to checking other cases, such as "ERROR", as Junio suggested, I'd think you'd also want to test:

hinting: hint

to verify that it doesn't get colored.

Quoted 2 lines
t/t5409-colorize-remote-messages.sh +2 -0
+exit 0
+EOF
#8 lore raw
In reply to Han-Wen Nienhuys

Hi,

Quoted 7 lines · Han-Wen Nienhuys

The colorization is controlled with the config setting "color.remote".

Supported keywords are "error", "warning", "hint" and "success". They are highlighted if they appear at the start of the line, which is common in error messages, eg.

ERROR: commit is missing Change-Id

A few questions:

- should this be documented somewhere in Documentation/technical/*protocol*? That way, server implementors can know to take advantage of it.

- how does this interact with (future) internationalization of server messages? If my server knows that the client speaks French, should they send "ERROR:" anyway and rely on the client to translate it? Or are we deferring that question to a later day?

[...]

Quoted 5 lines

The Git push process itself prints lots of non-actionable messages (eg. bandwidth statistics, object counters for different phases of the process), and my hypothesis is that these obscure the actionable error messages that our server sends back. Highlighting keywords in the draws more attention to actionable messages.

I'd be interested in ways to minimize Git's contribution to this as well. E.g. can we make more use of \r to make client-produced progress messages take less screen real estate? Should some of the servers involved (e.g., Gerrit) do so as well?

Quoted 5 lines

The highlighting is done on the client rather than server side, so servers don't have to grow capabilities to understand terminal escape codes and terminal state. It also consistent with the current state where Git is control of the local display (eg. prefixing messages with "remote: ").

As a strawman idea, what would you think of a way to allow the server to do some coloration by using color tags like

<red>Erreur</red>: ...

?

As an advantage, this would give the server more control. As a disadvantage, it is not so useful as "semantic markup", meaning it is harder to figure out how to present to accessibility tools in a meaningful way. Plus, there's the issue of usefulness with existing servers you mentioned:

Quoted 3 lines

Finally, this solution is backwards compatible: many servers already prefix their messages with "error", and they will benefit from this change without requiring a server update.

Yes, this seems like a compelling reason to follow this approach.

[...]

Quoted 4 lines
Documentation/config.txt +0 -0
@@ -1229,6 +1229,15 @@ color.push::
 color.push.error::

Documentation/config.txt color.push:: · line 1239

Quoted 10 lines
Documentation/config.txt +8 -0
 	Use customized color for push errors.
 
+color.remote::
+	A boolean to enable/disable colored remote output. If unset,
+	then the value of `color.ui` is used (`auto` by default).
+
+color.remote.<slot>::
+	Use customized color for each remote keywords. `<slot>` may be
+	`hint`, `warning`, `success` or `error` which match the
+	corresponding keyword.

What positions in a remote message are matched? If a server prints a message about something being discouraged because it is error-prone, would the "error" in error-prone turn red?

[...]

sideband.c line 8

Quoted 11 lines
sideband.c +5 -0
@@ -1,6 +1,103 @@
 #include "cache.h"
+#include "color.h"
+#include "config.h"
 #include "pkt-line.h"
 #include "sideband.h"
+#include "help.h"
+
+struct kwtable {

nit: perhaps kwtable_entry?

Quoted 11 lines
sideband.c +11 -0
+	/*
+	 * We use keyword as config key so it can't contain funny chars like
+	 * spaces. When we do that, we need a separate field for slot name in
+	 * load_sideband_colors().
+	 */
+	const char *keyword;
+	char color[COLOR_MAXLEN];
+};
+
+static struct kwtable keywords[] = {
+	{ "hint",	GIT_COLOR_YELLOW },

[...]

Quoted 1 line

+// Returns a color setting (GIT_COLOR_NEVER, etc).

nit: Git uses C89-style /* */ comments.

Quoted 1 line

+static int use_sideband_colors(void)

Makes sense.

[...]

sideband.c line 59

Quoted 7 lines
sideband.c +7 -0
+void list_config_color_sideband_slots(struct string_list *list, const char *prefix)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(keywords); i++)
+		list_config_item(list, prefix, keywords[i].keyword);
+}

Not about this patch: I wonder if we can eliminate this boilerplate some time in the future.

[...]

sideband.c line 65

Quoted 5 lines
sideband.c +5 -0
+/*
+ * Optionally highlight some keywords in remote output if they appear at the
+ * start of the line. This should be called for a single line only.
+ */
+void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)

Can this be static?

What does 'n' represent? Can the comment say? (Or if it's the length of src, can it be renamed to srclen?)

Super-pedantic nit: even if there are multiple special words at the start, this will only highlight one. :) So it could say something like "Optionally check if the first word on the line is a keyword and highlight it if so."

sideband.c line 68

Quoted 3 lines
sideband.c +3 -0
+{
+	int i;
+ 	if (!want_color_stderr(use_sideband_colors())) {

nit: whitespace damage (you can check for this with "git show --check"). There's a bit more elsewhere.

sideband.c line 80

Quoted 12 lines
sideband.c +12 -0
+		strbuf_add(dest, src, n);
+		return;
+	}
+
+	while (isspace(*src)) {
+		strbuf_addch(dest, *src);
+		src++;
+		n--;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(keywords); i++) {
+		struct kwtable* p = keywords + i;

nit: * should attach to the variable, C-style.

You can use "make style" to do some automatic formatting (though this is a bit experimental, so do double-check the results).

Quoted 5 lines
sideband.c +5 -0
+		int len = strlen(p->keyword);
+                /*
+                 * Match case insensitively, so we colorize output from existing
+                 * servers regardless of the case that they use for their
+                 * messages. We only highlight the word precisely, so

sideband.c line 95

Quoted 10 lines
sideband.c +10 -0
+                 * "successful" stays uncolored.
+                 */
+		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;
+		}

Sensible.

[...]

Quoted 17 lines
sideband.c +4 -2
@@ -48,8 +145,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 +168,22 @@ int recv_sideband(const char *me, int in_stream, int out)
 				if (!outbuf.len)
 					strbuf_addstr(&outbuf, DISPLAY_PREFIX);
 				if (linelen > 0) {

sideband.c int recv_sideband(const char *me, int in_stream, int out) · line 176

Quoted 10 lines
sideband.c +4 -4
-					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);

Nice. This looks cleaner than what was there before, which is always a good sign.

[...]

t/t5409-colorize-remote-messages.sh

Quoted 2 lines
t/t5409-colorize-remote-messages.sh new file +0 -0

Thanks for these. It may make sense to have a test with some leading whitespace as well.

[...]

t/t5409-colorize-remote-messages.sh line 18

Quoted 12 lines
t/t5409-colorize-remote-messages.sh new file +12 -0
+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
+echo prefixerror: error
+exit 0
+EOF
+	chmod +x .git/hooks/update &&

Please use write_script for this, since on esoteric platforms it picks an appropriate shell.

If you use <<-\EOF instead of <<EOF, that has two advantages:
- it lets you indent the script
- it saves the reviewer from having to look for $ escapes inside the script body

t/t5409-colorize-remote-messages.sh line 21

Quoted 3 lines
t/t5409-colorize-remote-messages.sh new file +3 -0
+	echo 1 >file &&
+	git add file &&
+	git commit -m 1 &&

This can use test_commit. See t/README for details.

[...]

Quoted 8 lines
t/t5409-colorize-remote-messages.sh new file +8 -0
+test_expect_success 'push' '
+	git -c color.remote=always push -f origin HEAD:refs/heads/newbranch 2>output &&
+	test_decode_color <output >decoded &&
+	grep "<BOLD;RED>error<RESET>:" decoded &&
+	grep "<YELLOW>hint<RESET>:" decoded &&
+	grep "<BOLD;GREEN>success<RESET>:" decoded &&
+	grep "<BOLD;YELLOW>warning<RESET>:" decoded &&
+	grep "prefixerror: error" decoded

t/t5409-colorize-remote-messages.sh line 45

Quoted 10 lines
t/t5409-colorize-remote-messages.sh new file +10 -0
+'
+
+test_expect_success 'push with customized color' '
+	git -c color.remote=always -c color.remote.error=white push -f origin HEAD:refs/heads/newbranch2 2>output &&
+	test_decode_color <output >decoded &&
+	grep "<WHITE>error<RESET>:" decoded &&
+	grep "<YELLOW>hint<RESET>:" decoded &&
+	grep "<BOLD;GREEN>success<RESET>:" decoded &&
+	grep "<BOLD;YELLOW>warning<RESET>:" decoded
+'

Nice.

Thanks and hope that helps,
Jonathan

#9 lore raw
Quoted 11 lines · Jonathan Nieder

Hi,

Quoted 6 lines · Han-Wen Nienhuys

The colorization is controlled with the config setting "color.remote".

Supported keywords are "error", "warning", "hint" and "success". They are highlighted if they appear at the start of the line, which is common in error messages, eg.

Quoted 6 lines
Quoted 1 line

ERROR: commit is missing Change-Id

A few questions:

- should this be documented somewhere in Documentation/technical/*protocol*? That way, server implementors can know to take advantage of it.

The protocol docs seem to work on a much different level. Maybe there should be a "best practices" document or similar?

Quoted 4 lines

- how does this interact with (future) internationalization of server messages? If my server knows that the client speaks French, should they send "ERROR:" anyway and rely on the client to translate it? Or are we deferring that question to a later day?

It doesn't, and we are deferring that question.

Quoted 11 lines

[...]

Quoted 5 lines

The Git push process itself prints lots of non-actionable messages (eg. bandwidth statistics, object counters for different phases of the process), and my hypothesis is that these obscure the actionable error messages that our server sends back. Highlighting keywords in the draws more attention to actionable messages.

I'd be interested in ways to minimize Git's contribution to this as well. E.g. can we make more use of \r to make client-produced progress messages take less screen real estate? Should some of the servers involved (e.g., Gerrit) do so as well?

Yes, I'm interested in this too, but I fear it would veer into a territory that is prone to bikeshedding.

Gerrit should definitely also send less noise.

Quoted 13 lines
Quoted 3 lines

Finally, this solution is backwards compatible: many servers already prefix their messages with "error", and they will benefit from this change without requiring a server update.

Yes, this seems like a compelling reason to follow this approach.

[...]

Quoted 6 lines
Documentation/config.txt +0 -0
@@ -1229,6 +1229,15 @@ color.push::
 color.push.error::
      Use customized color for push errors.
 
Quoted 12 lines

Documentation/config.txt color.push:: · line 1239

Quoted 8 lines
Documentation/config.txt +8 -0
+color.remote::
+     A boolean to enable/disable colored remote output. If unset,
+     then the value of `color.ui` is used (`auto` by default).
+
+color.remote.<slot>::
+     Use customized color for each remote keywords. `<slot>` may be
+     `hint`, `warning`, `success` or `error` which match the
+     corresponding keyword.

What positions in a remote message are matched? If a server prints a message about something being discouraged because it is error-prone, would the "error" in error-prone turn red?

yes, if it happened to occur after a line-break.

We could decide that we will only highlight

<sp*><keyword>':' rest of line

or

<sp*><keyword>'\n'

that would work for the Gerrit case, and would be useful forcing function to uniformize remote error messages.

Quoted 3 lines

Documentation/config.txt color.push:: · line 1240

Quoted 1 line
Documentation/config.txt +1 -0
+struct kwtable {

nit: perhaps kwtable_entry?

done.

Quoted 7 lines

Documentation/config.txt color.push::

Quoted 5 lines
Documentation/config.txt +5 -0
+/*
+ * Optionally highlight some keywords in remote output if they appear at the
+ * start of the line. This should be called for a single line only.
+ */
+void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)

Can this be static?

Done.

Quoted 2 lines

What does 'n' represent? Can the comment say? (Or if it's the length of src, can it be renamed to srclen?)

Added comment.

Quoted 4 lines

Super-pedantic nit: even if there are multiple special words at the start, this will only highlight one. :) So it could say something like "Optionally check if the first word on the line is a keyword and highlight it if so."

Super pedantic answer: if people care about it that much, they can read the 20 lines of code below :-)

Quoted 6 lines

Documentation/config.txt

Quoted 3 lines
Documentation/config.txt +3 -0
+{
+     int i;
+     if (!want_color_stderr(use_sideband_colors())) {

nit: whitespace damage (you can check for this with "git show --check"). There's a bit more elsewhere.

ran tabify on whole file.

Quoted 4 lines

Documentation/config.txt

Quoted 2 lines
Documentation/config.txt +2 -0
+     for (i = 0; i < ARRAY_SIZE(keywords); i++) {
+             struct kwtable* p = keywords + i;

nit: * should attach to the variable, C-style.

Done.

Quoted 2 lines

You can use "make style" to do some automatic formatting (though this is a bit experimental, so do double-check the results).

sad panda:

hanwen@han-wen:~/vc/git$ make style
git clang-format --style file --diff --extensions c,h
Traceback (most recent call last):
  File "/usr/bin/git-clang-format", line 580, in <module>
    main()
  File "/usr/bin/git-clang-format", line 62, in main
    config = load_git_config()
  File "/usr/bin/git-clang-format", line 195, in load_git_config
    name, value = entry.split('\n', 1)
ValueError: need more than 1 value to unpack
Makefile:2663: recipe for target 'style' failed
make: *** [style] Error 1
Quoted 32 lines

[...]

Quoted 17 lines
Documentation/config.txt +4 -2
@@ -48,8 +145,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 +168,22 @@ int recv_sideband(const char *me, int in_stream, int out)
                              if (!outbuf.len)
                                      strbuf_addstr(&outbuf, DISPLAY_PREFIX);
                              if (linelen > 0) {

Documentation/config.txt int recv_sideband(const char *me, int in_stream, int out) · line 176

Quoted 10 lines
Documentation/config.txt +4 -4
-                                     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);

Nice. This looks cleaner than what was there before, which is always a good sign.

Quoted 6 lines

[...]

t/t5409-colorize-remote-messages.sh

Quoted 2 lines
t/t5409-colorize-remote-messages.sh new file +0 -0

Thanks for these. It may make sense to have a test with some leading whitespace as well.

Done.

Quoted 9 lines
Quoted 1 line

+ chmod +x .git/hooks/update &&

Please use write_script for this, since on esoteric platforms it picks an appropriate shell.

If you use <<-\EOF instead of <<EOF, that has two advantages:
- it lets you indent the script
- it saves the reviewer from having to look for $ escapes inside the script body

Done (#TIL).

Quoted 5 lines

t/t5409-colorize-remote-messages.sh line 21

Quoted 3 lines
t/t5409-colorize-remote-messages.sh new file +3 -0
+     echo 1 >file &&
+     git add file &&
+     git commit -m 1 &&

This can use test_commit. See t/README for details.

Done.

--
Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado