checkstyle: Work around bug in difflib
If a file misses the newline at the end it gets detected by checkstyle, but the resulting patch is incorrect and does not apply. It took me a while to understand that it wasn't me using checkstyle incorrectly, but that the patch was faulty. The bug itself is in difflib and dates back to 2008. To reproduce: - Remove trailing newline from a file - git add the file - run ./utils/checkstyle.py -s | patch -p0 Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
284919ef2e
commit
62c31a352c
1 changed files with 6 additions and 0 deletions
|
@ -168,6 +168,12 @@ def parse_diff(diff):
|
|||
hunk = DiffHunk(line)
|
||||
|
||||
elif hunk is not None:
|
||||
# Work around https://github.com/python/cpython/issues/46395
|
||||
# See https://www.gnu.org/software/diffutils/manual/html_node/Incomplete-Lines.html
|
||||
if line[-1] != '\n':
|
||||
hunk.append(line + '\n')
|
||||
line = '\\ No newline at end of file\n'
|
||||
|
||||
hunk.append(line)
|
||||
|
||||
if hunk:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue