|
19 | 19 | #include "sigchain.h" |
20 | 20 | #include "transport-internal.h" |
21 | 21 | #include "object-store.h" |
| 22 | +#include "color.h" |
| 23 | + |
| 24 | +static int transport_use_color = -1; |
| 25 | +static char transport_colors[][COLOR_MAXLEN] = { |
| 26 | + GIT_COLOR_RESET, |
| 27 | + GIT_COLOR_RED /* REJECTED */ |
| 28 | +}; |
| 29 | + |
| 30 | +enum color_transport { |
| 31 | + TRANSPORT_COLOR_RESET = 0, |
| 32 | + TRANSPORT_COLOR_REJECTED = 1 |
| 33 | +}; |
| 34 | + |
| 35 | +static int transport_color_config(void) |
| 36 | +{ |
| 37 | + const char *keys[] = { |
| 38 | + "color.transport.reset", |
| 39 | + "color.transport.rejected" |
| 40 | + }, *key = "color.transport"; |
| 41 | + char *value; |
| 42 | + int i; |
| 43 | + static int initialized; |
| 44 | + |
| 45 | + if (initialized) |
| 46 | + return 0; |
| 47 | + initialized = 1; |
| 48 | + |
| 49 | + if (!git_config_get_string(key, &value)) |
| 50 | + transport_use_color = git_config_colorbool(key, value); |
| 51 | + |
| 52 | + if (!want_color_stderr(transport_use_color)) |
| 53 | + return 0; |
| 54 | + |
| 55 | + for (i = 0; i < ARRAY_SIZE(keys); i++) |
| 56 | + if (!git_config_get_string(keys[i], &value)) { |
| 57 | + if (!value) |
| 58 | + return config_error_nonbool(keys[i]); |
| 59 | + if (color_parse(value, transport_colors[i]) < 0) |
| 60 | + return -1; |
| 61 | + } |
| 62 | + |
| 63 | + return 0; |
| 64 | +} |
| 65 | + |
| 66 | +static const char *transport_get_color(enum color_transport ix) |
| 67 | +{ |
| 68 | + if (want_color_stderr(transport_use_color)) |
| 69 | + return transport_colors[ix]; |
| 70 | + return ""; |
| 71 | +} |
22 | 72 |
|
23 | 73 | static void set_upstreams(struct transport *transport, struct ref *refs, |
24 | 74 | int pretend) |
@@ -339,7 +389,13 @@ static void print_ref_status(char flag, const char *summary, |
339 | 389 | else |
340 | 390 | fprintf(stdout, "%s\n", summary); |
341 | 391 | } else { |
342 | | - fprintf(stderr, " %c %-*s ", flag, summary_width, summary); |
| 392 | + const char *red = "", *reset = ""; |
| 393 | + if (push_had_errors(to)) { |
| 394 | + red = transport_get_color(TRANSPORT_COLOR_REJECTED); |
| 395 | + reset = transport_get_color(TRANSPORT_COLOR_RESET); |
| 396 | + } |
| 397 | + fprintf(stderr, " %s%c %-*s%s ", red, flag, summary_width, |
| 398 | + summary, reset); |
343 | 399 | if (from) |
344 | 400 | fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name)); |
345 | 401 | else |
@@ -488,6 +544,9 @@ void transport_print_push_status(const char *dest, struct ref *refs, |
488 | 544 | char *head; |
489 | 545 | int summary_width = transport_summary_width(refs); |
490 | 546 |
|
| 547 | + if (transport_color_config() < 0) |
| 548 | + warning(_("could not parse transport.color.* config")); |
| 549 | + |
491 | 550 | head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL); |
492 | 551 |
|
493 | 552 | if (verbose) { |
@@ -554,6 +613,9 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re |
554 | 613 | struct send_pack_args args; |
555 | 614 | int ret; |
556 | 615 |
|
| 616 | + if (transport_color_config() < 0) |
| 617 | + return -1; |
| 618 | + |
557 | 619 | if (!data->got_remote_heads) { |
558 | 620 | struct ref *tmp_refs; |
559 | 621 | connect_setup(transport, 1); |
@@ -998,6 +1060,9 @@ int transport_push(struct transport *transport, |
998 | 1060 | *reject_reasons = 0; |
999 | 1061 | transport_verify_remote_names(refspec_nr, refspec); |
1000 | 1062 |
|
| 1063 | + if (transport_color_config() < 0) |
| 1064 | + return -1; |
| 1065 | + |
1001 | 1066 | if (transport->vtable->push_refs) { |
1002 | 1067 | struct ref *remote_refs; |
1003 | 1068 | struct ref *local_refs = get_local_heads(); |
|
0 commit comments