changeset 7:2ac85cc1e11b

Symlinks may have no newline at the end.
author Sjoerd Mullender <sjoerd@acm.org>
date Tue, 04 Nov 2014 12:58:48 +0100 (2014-11-04)
parents 95e8189b5fb4
children 42b21d1a4e84
files check_whitespace.py
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/check_whitespace.py	Fri Oct 31 16:19:24 2014 +0100
+++ b/check_whitespace.py	Tue Nov 04 12:58:48 2014 +0100
@@ -28,10 +28,13 @@
     tbre = re.compile(r'\+.*\t')
     resre = re.compile(r'\+(<<<<<<<|>>>>>>>)')
     adding = False
+    islink = False              # symlinks can have no newline at end
 
     for chunk in difflines:
         for line in chunk.split('\n'):
             if header:
+                if line.startswith('new file mode'):
+                    islink = '120000' in line
                 # remember the name of the file that this diff affects
                 m = fnre.match(line)
                 if m is not None and m.group('filename') != '/dev/null':
@@ -42,6 +45,7 @@
             if line.startswith('diff '):
                 header = True
                 adding = False
+                islink = False
                 continue
             # hunk header - save the line number
             m = lnre.match(line)
@@ -54,7 +58,7 @@
                 adding = True
             elif line[:1] in (' ', '-'):
                 adding = False
-            elif adding and line.startswith(r'\ No newline at end of file'):
+            elif adding and not islink and line.startswith(r'\ No newline at end of file'):
                 adding = False
                 yield filename, linenum, 'no newline at end of file'
             # hunk body - check for an added line with bad whitespace