static int transport_color_config(void) { const char *keys[] = { "color.transport.reset", "color.transport.rejected" }, *key = "color.transport"; char *value; int i; static int initialized; if (initialized) return 0; initialized = 1; if (!git_config_get_string(key, &value)) transport_use_color = git_config_colorbool(key, value); if (!want_color_stderr(transport_use_color)) return 0; for (i = 0; i < ARRAY_SIZE(keys); i++) if (!git_config_get_string(keys[i], &value)) { if (!value) return config_error_nonbool(keys[i]); if (color_parse(value, transport_colors[i]) < 0) return -1; } return 0; }
/* * Optionally highlight one keyword in remote output if it appears at the start * of the line. This should be called for a single line only, which is * passed as the first N characters of the SRC array. * * NEEDSWORK: use "size_t n" instead for clarity. */ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n) { int i; if (!want_color_stderr(use_sideband_colors())) { strbuf_add(dest, src, n); return; } while (0 < n && isspace(*src)) { strbuf_addch(dest, *src); src++; n--; } for (i = 0; i < ARRAY_SIZE(keywords); i++) { struct keyword_entry *p = keywords + i; int len = strlen(p->keyword); if (n < len) continue; /* * 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 * "successful" stays uncolored. */ if (!strncasecmp(p->keyword, src, len) && (len == n || !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); }
static const char *transport_get_color(enum color_transport ix) { if (want_color_stderr(transport_use_color)) return transport_colors[ix]; return ""; }
static const char *push_get_color(enum color_push ix) { if (want_color_stderr(push_use_color)) return push_colors[ix]; return ""; }