* Parse a unified diff. Note that this really needs to parse each * fragment separately, since the only way to know the difference * between a "---" that is part of a patch, and a "---" that starts * the next patch is to look at the line counts.. */
| 1758 | * the next patch is to look at the line counts.. |
| 1759 | */ |
| 1760 | static int parse_fragment(struct apply_state *state, |
| 1761 | const char *line, |
| 1762 | unsigned long size, |
| 1763 | struct patch *patch, |
| 1764 | struct fragment *fragment) |
| 1765 | { |
| 1766 | int added, deleted; |
| 1767 | int len = linelen(line, size), offset; |
| 1768 | int skip_len = 0; |
| 1769 | unsigned long oldlines, newlines; |
| 1770 | unsigned long leading, trailing; |
| 1771 | |
| 1772 | /* do not complain a symbolic link being an incomplete line */ |
| 1773 | if (patch->ws_rule & WS_INCOMPLETE_LINE) { |
| 1774 | /* |
| 1775 | * We want to figure out if the postimage is a |
| 1776 | * symbolic link when applying the patch normally, or |
| 1777 | * if the preimage is a symbolic link when applying |
| 1778 | * the patch in reverse. A normal patch only has |
| 1779 | * old_mode without new_mode. If it changes the |
| 1780 | * filemode, new_mode has value, which is different |
| 1781 | * from old_mode. |
| 1782 | */ |
| 1783 | unsigned mode = (state->apply_in_reverse |
| 1784 | ? patch->old_mode |
| 1785 | : patch->new_mode |
| 1786 | ? patch->new_mode |
| 1787 | : patch->old_mode); |
| 1788 | if (mode && S_ISLNK(mode)) |
| 1789 | patch->ws_rule &= ~WS_INCOMPLETE_LINE; |
| 1790 | } |
| 1791 | |
| 1792 | offset = parse_fragment_header(line, len, fragment); |
| 1793 | if (offset < 0) |
| 1794 | return -1; |
| 1795 | if (offset > 0 && patch->recount) |
| 1796 | recount_diff(line + offset, size - offset, fragment); |
| 1797 | oldlines = fragment->oldlines; |
| 1798 | newlines = fragment->newlines; |
| 1799 | leading = 0; |
| 1800 | trailing = 0; |
| 1801 | |
| 1802 | /* Parse the thing.. */ |
| 1803 | line += len; |
| 1804 | size -= len; |
| 1805 | state->linenr++; |
| 1806 | added = deleted = 0; |
| 1807 | for (offset = len; |
| 1808 | 0 < size; |
| 1809 | offset += len, size -= len, line += len, state->linenr++) { |
| 1810 | if (!oldlines && !newlines) |
| 1811 | break; |
| 1812 | len = linelen(line, size); |
| 1813 | if (!len || line[len-1] != '\n') |
| 1814 | return -1; |
| 1815 | |
| 1816 | /* |
| 1817 | * For an incomplete line, skip_len counts the bytes |
no test coverage detected