Show More
@@ -17,39 +17,56 b'' | |||||
17 |
|
17 | |||
18 | import re, sys, os |
|
18 | import re, sys, os | |
19 |
|
19 | |||
|
20 | commitheader = r"^(?:# [^\n]*\n)*" | |||
|
21 | afterheader = commitheader + r"(?!#)" | |||
|
22 | beforepatch = afterheader + r"(?!\n(?!@@))" | |||
|
23 | ||||
20 | errors = [ |
|
24 | errors = [ | |
21 | (r"[(]bc[)]", "(BC) needs to be uppercase"), |
|
25 | (beforepatch + r".*[(]bc[)]", "(BC) needs to be uppercase"), | |
22 | (r"[(]issue \d\d\d", "no space allowed between issue and number"), |
|
26 | (beforepatch + r".*[(]issue \d\d\d", "no space allowed between issue and number"), | |
23 | (r"[(]bug(\d|\s)", "use (issueDDDD) instead of bug"), |
|
27 | (beforepatch + r".*[(]bug(\d|\s)", "use (issueDDDD) instead of bug"), | |
24 |
(r" |
|
28 | (commitheader + r"# User [^@\n]+\n", "username is not an email address"), | |
25 |
(r" |
|
29 | (commitheader + r"(?!merge with )[^#]\S+[^:] ", | |
26 | "summary line doesn't start with 'topic: '"), |
|
30 | "summary line doesn't start with 'topic: '"), | |
27 |
( |
|
31 | (afterheader + r"[A-Z][a-z]\S+", "don't capitalize summary lines"), | |
28 |
( |
|
32 | (afterheader + r"[^\n]*: *[A-Z][a-z]\S+", "don't capitalize summary lines"), | |
29 |
(r" |
|
33 | (afterheader + r"\S*[^A-Za-z0-9-]\S*: ", | |
30 | "summary keyword should be most user-relevant one-word command or topic"), |
|
34 | "summary keyword should be most user-relevant one-word command or topic"), | |
31 |
( |
|
35 | (afterheader + r".*\.\s*\n", "don't add trailing period on summary line"), | |
32 |
( |
|
36 | (afterheader + r".{79,}", "summary line too long (limit is 78)"), | |
33 |
(r" |
|
37 | (r"\n\+\n \n", "adds double empty line"), | |
34 |
(r" |
|
38 | (r"\n \n\+\n", "adds double empty line"), | |
35 |
(r" |
|
39 | (r"\n\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), | |
36 | ] |
|
40 | ] | |
37 |
|
41 | |||
|
42 | word = re.compile('\S') | |||
|
43 | def nonempty(first, second): | |||
|
44 | if word.search(first): | |||
|
45 | return first | |||
|
46 | return second | |||
|
47 | ||||
38 | def checkcommit(commit, node = None): |
|
48 | def checkcommit(commit, node = None): | |
39 | exitcode = 0 |
|
49 | exitcode = 0 | |
40 | printed = node is None |
|
50 | printed = node is None | |
41 | for exp, msg in errors: |
|
51 | for exp, msg in errors: | |
42 |
m = re.search(exp, commit |
|
52 | m = re.search(exp, commit) | |
43 | if m: |
|
53 | if m: | |
44 | pos = 0 |
|
54 | pos = 0 | |
|
55 | end = m.end() | |||
|
56 | trailing = re.search(r'(\\n)+$', exp) | |||
|
57 | if trailing: | |||
|
58 | end -= len(trailing.group()) / 2 | |||
|
59 | last = '' | |||
45 | for n, l in enumerate(commit.splitlines(True)): |
|
60 | for n, l in enumerate(commit.splitlines(True)): | |
46 | pos += len(l) |
|
61 | pos += len(l) | |
47 |
if pos |
|
62 | if pos < end: | |
|
63 | last = nonempty(l, last) | |||
|
64 | else: | |||
48 | if not printed: |
|
65 | if not printed: | |
49 | printed = True |
|
66 | printed = True | |
50 | print "node: %s" % node |
|
67 | print "node: %s" % node | |
51 | print "%d: %s" % (n, msg) |
|
68 | print "%d: %s" % (n, msg) | |
52 | print " %s" % l[:-1] |
|
69 | print " %s" % nonempty(l, last)[:-1] | |
53 | if "BYPASS" not in os.environ: |
|
70 | if "BYPASS" not in os.environ: | |
54 | exitcode = 1 |
|
71 | exitcode = 1 | |
55 | break |
|
72 | break |
@@ -103,7 +103,7 b' A patch with other errors:' | |||||
103 | 7: don't add trailing period on summary line |
|
103 | 7: don't add trailing period on summary line | |
104 | This has no topic and ends with a period. |
|
104 | This has no topic and ends with a period. | |
105 | 19: adds double empty line |
|
105 | 19: adds double empty line | |
106 |
|
|
106 | + | |
107 | 15: adds double empty line |
|
107 | 15: adds double empty line | |
108 | + |
|
108 | + | |
109 | 16: adds a function with foo_bar naming |
|
109 | 16: adds a function with foo_bar naming |
General Comments 0
You need to be logged in to leave comments.
Login now