patch_parse: handle missing newline indicator in old file#5159
patch_parse: handle missing newline indicator in old file#5159ethomson merged 4 commits intolibgit2:masterfrom
Conversation
|
Fixes #5153 |
|
@pks-t Nice! didn't see that. we can add the patch until it is fixed, really great! looking for this to be merged and the roadmap for releasing. |
|
I don't know if this is related, but I tested your PR and it seems to work. But when I try to apply this patch, I cannot. I applied the following patch in with However, when I try to apply it via |
|
I have noticed that none of the patch parse tests actually verify if a patch was correctly parsed. For instance parsing the following snippet with and then printing the resulting diff using Notice that the |
|
That can be either we don't print out the diff about newline or we are just ignoring it. I will do some checks to provide feedback |
|
But |
|
I fixed this in #5161, please check! |
I know, as noticed in my commit message :) Anyway, I'm closing this PR in favour of yours, so thanks a lot for fixing this! |
The patch ID is supposed to be mostly context-insignificant and thus only includes added or deleted lines. As such, we shouldn't honor end-of-file-without-newline markers in diffs. Ignore such lines to fix how we compute the patch ID for such diffs.
When either the old or new file contents have no newline at the end of the file, then git-diff(1) will print out a "\ No newline at end of file" indicator. While we do correctly handle this in the case where the new file has this indcator, we fail to parse patches where the old file is missing a newline at EOF. Fix this bug by handling and missing newline indicators in the old file. Add tests to verify that we can parse such files.
ea99541 to
b089328
Compare
|
This supersedes #5161 again. |
|
Fixes #5177 |
|
Thanks! |
When either the old or new file contents have no newline at the end of
the file, then git-diff(1) will print out a "\ No newline at end of
file" indicator. While we do correctly handle this in the case where the
new file has this indcator, we fail to parse patches where the old file
is missing a newline at EOF.
Fix this bug by handling and missing newline indicators in the old file.
Add tests to verify that we can parse such files.
I've tried to modify our patch printing logic to also emit the "No newline at end of file" markers, but it turned out to be non-trivial. Many of the diff/patch structs are part of our public API and thus cannot be easily changed, so I didn't quite know where to put the missing newline indicators. So I've stopped short of actually verifying that we round-trip such patches correctly when parsing and printing them, as we do not do this correctly right now.
Fixes #5157