# HG changeset patch
# User Sjoerd Mullender <sjoerd@acm.org>
# Date 1415102328 -3600
# Node ID 2ac85cc1e11bf4402ffbf62481afc55dd24df735
# Parent  95e8189b5fb4cfb0c0364f1f5b8a009578e39ba4
Symlinks may have no newline at the end.

diff -r 95e8189b5fb4 -r 2ac85cc1e11b check_whitespace.py
--- 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