| 1509 | } |
| 1510 | |
| 1511 | static struct commit_extra_header *read_commit_extra_header_lines( |
| 1512 | const char *buffer, size_t size, |
| 1513 | const char **exclude) |
| 1514 | { |
| 1515 | struct commit_extra_header *extra = NULL, **tail = &extra, *it = NULL; |
| 1516 | const char *line, *next, *eof, *eob; |
| 1517 | struct strbuf buf = STRBUF_INIT; |
| 1518 | |
| 1519 | for (line = buffer, eob = line + size; |
| 1520 | line < eob && *line != '\n'; |
| 1521 | line = next) { |
| 1522 | next = memchr(line, '\n', eob - line); |
| 1523 | next = next ? next + 1 : eob; |
| 1524 | if (*line == ' ') { |
| 1525 | /* continuation */ |
| 1526 | if (it) |
| 1527 | strbuf_add(&buf, line + 1, next - (line + 1)); |
| 1528 | continue; |
| 1529 | } |
| 1530 | if (it) |
| 1531 | it->value = strbuf_detach(&buf, &it->len); |
| 1532 | strbuf_reset(&buf); |
| 1533 | it = NULL; |
| 1534 | |
| 1535 | eof = memchr(line, ' ', next - line); |
| 1536 | if (!eof) |
| 1537 | eof = next; |
| 1538 | else if (standard_header_field(line, eof - line) || |
| 1539 | excluded_header_field(line, eof - line, exclude)) |
| 1540 | continue; |
| 1541 | |
| 1542 | CALLOC_ARRAY(it, 1); |
| 1543 | it->key = xmemdupz(line, eof-line); |
| 1544 | *tail = it; |
| 1545 | tail = &it->next; |
| 1546 | if (eof + 1 < next) |
| 1547 | strbuf_add(&buf, eof + 1, next - (eof + 1)); |
| 1548 | } |
| 1549 | if (it) |
| 1550 | it->value = strbuf_detach(&buf, &it->len); |
| 1551 | return extra; |
| 1552 | } |
| 1553 | |
| 1554 | void free_commit_extra_headers(struct commit_extra_header *extra) |
| 1555 | { |
no test coverage detected