|
20 | 20 | #include "transport-internal.h" |
21 | 21 | #include "protocol.h" |
22 | 22 | #include "object-store.h" |
| 23 | +#include "color.h" |
| 24 | + |
| 25 | +static int transport_use_color = -1; |
| 26 | +static char transport_colors[][COLOR_MAXLEN] = { |
| 27 | + GIT_COLOR_RESET, |
| 28 | + GIT_COLOR_RED /* REJECTED */ |
| 29 | +}; |
| 30 | + |
| 31 | +enum color_transport { |
| 32 | + TRANSPORT_COLOR_RESET = 0, |
| 33 | + TRANSPORT_COLOR_REJECTED = 1 |
| 34 | +}; |
| 35 | + |
| 36 | +static int transport_color_config(void) |
| 37 | +{ |
| 38 | + const char *keys[] = { |
| 39 | + "color.transport.reset", |
| 40 | + "color.transport.rejected" |
| 41 | + }, *key = "color.transport"; |
| 42 | + char *value; |
| 43 | + int i; |
| 44 | + static int initialized; |
| 45 | + |
| 46 | + if (initialized) |
| 47 | + return 0; |
| 48 | + initialized = 1; |
| 49 | + |
| 50 | + if (!git_config_get_string(key, &value)) |
| 51 | + transport_use_color = git_config_colorbool(key, value); |
| 52 | + |
| 53 | + if (!want_color_stderr(transport_use_color)) |
| 54 | + return 0; |
| 55 | + |
| 56 | + for (i = 0; i < ARRAY_SIZE(keys); i++) |
| 57 | + if (!git_config_get_string(keys[i], &value)) { |
| 58 | + if (!value) |
| 59 | + return config_error_nonbool(keys[i]); |
| 60 | + if (color_parse(value, transport_colors[i]) < 0) |
| 61 | + return -1; |
| 62 | + } |
| 63 | + |
| 64 | + return 0; |
| 65 | +} |
| 66 | + |
| 67 | +static const char *transport_get_color(enum color_transport ix) |
| 68 | +{ |
| 69 | + if (want_color_stderr(transport_use_color)) |
| 70 | + return transport_colors[ix]; |
| 71 | + return ""; |
| 72 | +} |
23 | 73 |
|
24 | 74 | static void set_upstreams(struct transport *transport, struct ref *refs, |
25 | 75 | int pretend) |
@@ -373,7 +423,13 @@ static void print_ref_status(char flag, const char *summary, |
373 | 423 | else |
374 | 424 | fprintf(stdout, "%s\n", summary); |
375 | 425 | } else { |
376 | | - fprintf(stderr, " %c %-*s ", flag, summary_width, summary); |
| 426 | + const char *red = "", *reset = ""; |
| 427 | + if (push_had_errors(to)) { |
| 428 | + red = transport_get_color(TRANSPORT_COLOR_REJECTED); |
| 429 | + reset = transport_get_color(TRANSPORT_COLOR_RESET); |
| 430 | + } |
| 431 | + fprintf(stderr, " %s%c %-*s%s ", red, flag, summary_width, |
| 432 | + summary, reset); |
377 | 433 | if (from) |
378 | 434 | fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name)); |
379 | 435 | else |
@@ -522,6 +578,9 @@ void transport_print_push_status(const char *dest, struct ref *refs, |
522 | 578 | char *head; |
523 | 579 | int summary_width = transport_summary_width(refs); |
524 | 580 |
|
| 581 | + if (transport_color_config() < 0) |
| 582 | + warning(_("could not parse transport.color.* config")); |
| 583 | + |
525 | 584 | head = resolve_refdup("HEAD", RESOLVE_REF_READING, NULL, NULL); |
526 | 585 |
|
527 | 586 | if (verbose) { |
@@ -588,6 +647,9 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re |
588 | 647 | struct send_pack_args args; |
589 | 648 | int ret = 0; |
590 | 649 |
|
| 650 | + if (transport_color_config() < 0) |
| 651 | + return -1; |
| 652 | + |
591 | 653 | if (!data->got_remote_heads) |
592 | 654 | get_refs_via_connect(transport, 1, NULL); |
593 | 655 |
|
@@ -1036,6 +1098,9 @@ int transport_push(struct transport *transport, |
1036 | 1098 | *reject_reasons = 0; |
1037 | 1099 | transport_verify_remote_names(refspec_nr, refspec); |
1038 | 1100 |
|
| 1101 | + if (transport_color_config() < 0) |
| 1102 | + return -1; |
| 1103 | + |
1039 | 1104 | if (transport->vtable->push_refs) { |
1040 | 1105 | struct ref *remote_refs; |
1041 | 1106 | struct ref *local_refs = get_local_heads(); |
|
0 commit comments