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