| 1209 | } |
| 1210 | |
| 1211 | static void recolor_hunk(struct add_p_state *s, struct hunk *hunk) |
| 1212 | { |
| 1213 | const char *plain = s->plain.buf; |
| 1214 | size_t current, eol, next; |
| 1215 | |
| 1216 | if (!s->colored.len) |
| 1217 | return; |
| 1218 | |
| 1219 | hunk->colored_start = s->colored.len; |
| 1220 | for (current = hunk->start; current < hunk->end; ) { |
| 1221 | for (eol = current; eol < hunk->end; eol++) |
| 1222 | if (plain[eol] == '\n') |
| 1223 | break; |
| 1224 | next = eol + (eol < hunk->end); |
| 1225 | if (eol > current && plain[eol - 1] == '\r') |
| 1226 | eol--; |
| 1227 | |
| 1228 | strbuf_addstr(&s->colored, |
| 1229 | plain[current] == '-' ? |
| 1230 | s->cfg.file_old_color : |
| 1231 | plain[current] == '+' ? |
| 1232 | s->cfg.file_new_color : |
| 1233 | s->cfg.context_color); |
| 1234 | strbuf_add(&s->colored, plain + current, eol - current); |
| 1235 | strbuf_addstr(&s->colored, s->cfg.reset_color_diff); |
| 1236 | if (next > eol) |
| 1237 | strbuf_add(&s->colored, plain + eol, next - eol); |
| 1238 | current = next; |
| 1239 | } |
| 1240 | hunk->colored_end = s->colored.len; |
| 1241 | } |
| 1242 | |
| 1243 | static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk) |
| 1244 | { |
no test coverage detected