| 463 | } |
| 464 | |
| 465 | static int parse_hunk_header(struct add_p_state *s, struct hunk *hunk) |
| 466 | { |
| 467 | struct hunk_header *header = &hunk->header; |
| 468 | const char *line = s->plain.buf + hunk->start, *p = line; |
| 469 | const char *eol = memchr(p, '\n', s->plain.len - hunk->start); |
| 470 | |
| 471 | if (!eol) |
| 472 | eol = s->plain.buf + s->plain.len; |
| 473 | |
| 474 | if (!skip_prefix(p, "@@ -", &p) || |
| 475 | parse_range(&p, &header->old_offset, &header->old_count) < 0 || |
| 476 | !skip_prefix(p, " +", &p) || |
| 477 | parse_range(&p, &header->new_offset, &header->new_count) < 0 || |
| 478 | !skip_prefix(p, " @@", &p)) |
| 479 | return error(_("could not parse hunk header '%.*s'"), |
| 480 | (int)(eol - line), line); |
| 481 | |
| 482 | hunk->start = eol - s->plain.buf + (*eol == '\n'); |
| 483 | header->extra_start = p - s->plain.buf; |
| 484 | header->extra_end = hunk->start; |
| 485 | |
| 486 | if (!s->colored.len) { |
| 487 | header->colored_extra_start = header->colored_extra_end = 0; |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | /* Now find the extra text in the colored diff */ |
| 492 | line = s->colored.buf + hunk->colored_start; |
| 493 | eol = memchr(line, '\n', s->colored.len - hunk->colored_start); |
| 494 | if (!eol) |
| 495 | eol = s->colored.buf + s->colored.len; |
| 496 | p = memmem(line, eol - line, "@@ -", 4); |
| 497 | if (p && (p = memmem(p + 4, eol - p - 4, " @@", 3))) { |
| 498 | header->colored_extra_start = p + 3 - s->colored.buf; |
| 499 | } else { |
| 500 | /* could not parse colored hunk header, leave as-is */ |
| 501 | header->colored_extra_start = hunk->colored_start; |
| 502 | header->suppress_colored_line_range = 1; |
| 503 | } |
| 504 | hunk->colored_start = eol - s->colored.buf + (*eol == '\n'); |
| 505 | header->colored_extra_end = hunk->colored_start; |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static int is_octal(const char *p, size_t len) |
| 511 | { |
no test coverage detected