| 852 | } |
| 853 | |
| 854 | static void render_diff_header(struct add_p_state *s, |
| 855 | struct file_diff *file_diff, int colored, |
| 856 | struct strbuf *out) |
| 857 | { |
| 858 | /* |
| 859 | * If there was a mode change, the first hunk is a pseudo hunk that |
| 860 | * corresponds to the mode line in the header. If the user did not want |
| 861 | * to stage that "hunk", we actually have to cut it out from the header. |
| 862 | */ |
| 863 | int skip_mode_change = |
| 864 | file_diff->mode_change && file_diff->hunk->use != USE_HUNK; |
| 865 | struct hunk *head = &file_diff->head, *first = file_diff->hunk; |
| 866 | |
| 867 | if (!skip_mode_change) { |
| 868 | render_hunk(s, head, 0, colored, out); |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | if (colored) { |
| 873 | const char *p = s->colored.buf; |
| 874 | |
| 875 | strbuf_add(out, p + head->colored_start, |
| 876 | first->colored_start - head->colored_start); |
| 877 | strbuf_add(out, p + first->colored_end, |
| 878 | head->colored_end - first->colored_end); |
| 879 | } else { |
| 880 | const char *p = s->plain.buf; |
| 881 | |
| 882 | strbuf_add(out, p + head->start, first->start - head->start); |
| 883 | strbuf_add(out, p + first->end, head->end - first->end); |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | /* Coalesce hunks again that were split */ |
| 888 | static int merge_hunks(struct add_p_state *s, struct file_diff *file_diff, |
no test coverage detected