Mercurial > hgbook
comparison en/examples/data/check_whitespace.py @ 65:e3894bb9d1f5
Fix bugs in check_whitespace.py.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Fri, 04 Aug 2006 14:00:22 -0700 |
parents | 18210d46491f |
children |
comparison
equal
deleted
inserted
replaced
64:d12a199ed472 | 65:e3894bb9d1f5 |
---|---|
5 def trailing_whitespace(difflines): | 5 def trailing_whitespace(difflines): |
6 added, linenum, header = [], 0, False | 6 added, linenum, header = [], 0, False |
7 | 7 |
8 for line in difflines: | 8 for line in difflines: |
9 if header: | 9 if header: |
10 # remember the name of the file that this diff affects | |
11 m = re.match(r'(?:---|\+\+\+) ([^\t]+)', line) | |
12 if m and m.group(1) != '/dev/null': | |
13 filename = m.group(1).split('/', 1)[-1] | |
10 if line.startswith('+++ '): | 14 if line.startswith('+++ '): |
11 header = False | 15 header = False |
12 else: | |
13 # remember the name of the file that this diff affects | |
14 m = re.match(r'--- [^/]/([^\t])', line) | |
15 if m: filename = m.group(1) | |
16 continue | 16 continue |
17 if line.startswith('diff '): | 17 if line.startswith('diff '): |
18 header = True | 18 header = True |
19 continue | 19 continue |
20 # hunk header - save the line number | 20 # hunk header - save the line number |
21 m = re.match(r'@@ -(\d+),', line) | 21 m = re.match(r'@@ -\d+,\d+ \+(\d+),', line) |
22 if m: | 22 if m: |
23 linenum = int(m.group(1)) | 23 linenum = int(m.group(1)) |
24 continue | 24 continue |
25 # hunk body - check for an added line with trailing whitespace | 25 # hunk body - check for an added line with trailing whitespace |
26 m = re.match(r'\+.*\s$', line) | 26 m = re.match(r'\+.*\s$', line) |