MCPcopy Index your code
hub / github.com/git/git / recount_diff

Function recount_diff

apply.c:1512–1560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1510}
1511
1512static void recount_diff(const char *line, int size, struct fragment *fragment)
1513{
1514 int oldlines = 0, newlines = 0, ret = 0;
1515
1516 if (size < 1) {
1517 warning("recount: ignore empty hunk");
1518 return;
1519 }
1520
1521 for (;;) {
1522 int len = linelen(line, size);
1523 size -= len;
1524 line += len;
1525
1526 if (size < 1)
1527 break;
1528
1529 switch (*line) {
1530 case ' ': case '\n':
1531 newlines++;
1532 /* fall through */
1533 case '-':
1534 oldlines++;
1535 continue;
1536 case '+':
1537 newlines++;
1538 continue;
1539 case '\\':
1540 continue;
1541 case '@':
1542 ret = size < 3 || !starts_with(line, "@@ ");
1543 break;
1544 case 'd':
1545 ret = size < 5 || !starts_with(line, "diff ");
1546 break;
1547 default:
1548 ret = -1;
1549 break;
1550 }
1551 if (ret) {
1552 warning(_("recount: unexpected line: %.*s"),
1553 (int)linelen(line, size), line);
1554 return;
1555 }
1556 break;
1557 }
1558 fragment->oldlines = oldlines;
1559 fragment->newlines = newlines;
1560}
1561
1562/*
1563 * Parse a unified diff fragment header of the

Callers 1

parse_fragmentFunction · 0.85

Calls 3

warningFunction · 0.85
starts_withFunction · 0.85
linelenFunction · 0.70

Tested by

no test coverage detected