Commit 39bdd84
add-patch: handle splitting hunks with diff.suppressBlankEmpty
When "add -p" parses diffs, it looks for context lines starting with a
single space. But when diff.suppressBlankEmpty is in effect, an empty
context line will omit the space, giving us a true empty line. This
confuses the parser, which is unable to split based on such a line.
It's tempting to say that we should just make sure that we generate a
diff without that option. However, although we do not parse hunks that
the user has manually edited with parse_diff() we do allow the user
to split such hunks. As POSIX calls the decision of whether to print the
space here "implementation-defined" we need to handle edited hunks where
empty context lines omit the space.
So let's handle both cases: a context line either starts with a space or
consists of a totally empty line by normalizing the first character to a
space when we parse them. Normalizing the first character rather than
changing the code to check for a space or newline will hopefully future
proof against introducing similar bugs if the code is changed.
Reported-by: Ilya Tumaykin <itumaykin@gmail.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent 337b4d4 commit 39bdd84
2 files changed
+32
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
403 | 409 | | |
404 | 410 | | |
405 | 411 | | |
| |||
485 | 491 | | |
486 | 492 | | |
487 | 493 | | |
| 494 | + | |
488 | 495 | | |
489 | 496 | | |
490 | 497 | | |
| |||
532 | 539 | | |
533 | 540 | | |
534 | 541 | | |
535 | | - | |
| 542 | + | |
536 | 543 | | |
537 | 544 | | |
538 | 545 | | |
| |||
586 | 593 | | |
587 | 594 | | |
588 | 595 | | |
589 | | - | |
| 596 | + | |
590 | 597 | | |
591 | | - | |
592 | | - | |
| 598 | + | |
| 599 | + | |
593 | 600 | | |
594 | 601 | | |
595 | 602 | | |
| |||
813 | 820 | | |
814 | 821 | | |
815 | 822 | | |
816 | | - | |
| 823 | + | |
817 | 824 | | |
818 | 825 | | |
819 | 826 | | |
| |||
953 | 960 | | |
954 | 961 | | |
955 | 962 | | |
956 | | - | |
| 963 | + | |
957 | 964 | | |
958 | 965 | | |
959 | 966 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
1133 | 1152 | | |
0 commit comments