Better handling of "No newline at end of file" marker#5
Better handling of "No newline at end of file" marker#5sourcefrog merged 15 commits intogitpatch-rs:mainfrom
Conversation
|
I just hit this in testing cargo-mutants; it would be nice to merge and release a fix. |
|
@romamik I added a commit to fix a git conflict, hope you don't mind |
…es after the patch.
…rsedLine to LineOrEmptyLine to avoid confusion
|
Just pushed changes that make the resulting code much closer to the current main branch state. Mostly I removed most of the changes in the public API and pushed those flags up the stack while parsing. |
|
"No newline at end of file" marker (the marker) can appear after a removed line, an added line, or a context line. Depending on this, it refers to old content of the file, new content of the file, or both. To support this, while parsing the line, I expect the optional marker after every line: the function When processing each hunk, I check if there was a line with the marker attached, both for old and new content of the file. When processing the whole patch, I check the last hunk if it has these markers. Skipping trailing empty lines Before the changes, when the marker was encountered, the parsing of the lines stopped, and then the empty line was skipped in the |
Ah I see, that makes sense. |
Fixes #4.
Now the parser checks for every line if it is followed by the "No newline at end of file" line, and saves it with the line. This flag is later used to determine this status for the hunk and then for the file.
Also, I renamed the flag to
missing_newlineas for me, it was hard to wrap my head around the inverted logic of the previous flag. I know that the original marker has negated meaning and that is the main source of confusion, but having variables that are opposite to the marker present in file was an additional source of confusion to me.