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