| 753 | } |
| 754 | |
| 755 | static void emit_line_0(struct diff_options *o, |
| 756 | const char *set_sign, const char *set, unsigned reverse, const char *reset, |
| 757 | int first, const char *line, int len) |
| 758 | { |
| 759 | int has_trailing_newline, has_trailing_carriage_return; |
| 760 | int needs_reset = 0; /* at the end of the line */ |
| 761 | FILE *file = o->file; |
| 762 | |
| 763 | fputs(diff_line_prefix(o), file); |
| 764 | |
| 765 | has_trailing_newline = (len > 0 && line[len-1] == '\n'); |
| 766 | if (has_trailing_newline) |
| 767 | len--; |
| 768 | |
| 769 | has_trailing_carriage_return = (len > 0 && line[len-1] == '\r'); |
| 770 | if (has_trailing_carriage_return) |
| 771 | len--; |
| 772 | |
| 773 | if (!len && !first) |
| 774 | goto end_of_line; |
| 775 | |
| 776 | if (reverse && want_color(o->use_color)) { |
| 777 | fputs(GIT_COLOR_REVERSE, file); |
| 778 | needs_reset = 1; |
| 779 | } |
| 780 | |
| 781 | if (set_sign) { |
| 782 | fputs(set_sign, file); |
| 783 | needs_reset = 1; |
| 784 | } |
| 785 | |
| 786 | if (first) |
| 787 | fputc(first, file); |
| 788 | |
| 789 | if (!len) |
| 790 | goto end_of_line; |
| 791 | |
| 792 | if (set) { |
| 793 | if (set_sign && set != set_sign) |
| 794 | fputs(reset, file); |
| 795 | fputs(set, file); |
| 796 | needs_reset = 1; |
| 797 | } |
| 798 | fwrite(line, len, 1, file); |
| 799 | needs_reset = 1; /* 'line' may contain color codes. */ |
| 800 | |
| 801 | end_of_line: |
| 802 | if (needs_reset) |
| 803 | fputs(reset, file); |
| 804 | if (has_trailing_carriage_return) |
| 805 | fputc('\r', file); |
| 806 | if (has_trailing_newline) |
| 807 | fputc('\n', file); |
| 808 | } |
| 809 | |
| 810 | static void emit_line(struct diff_options *o, const char *set, const char *reset, |
| 811 | const char *line, int len) |
no test coverage detected