Show More
@@ -35,25 +35,32 b' errors = [' | |||||
35 | (r"^\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), |
|
35 | (r"^\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), | |
36 | ] |
|
36 | ] | |
37 |
|
37 | |||
38 | node = os.environ.get("HG_NODE") |
|
38 | def checkcommit(commit): | |
39 |
|
39 | exitcode = 0 | ||
40 | if node: |
|
40 | for exp, msg in errors: | |
41 | commit = os.popen("hg export %s" % node).read() |
|
41 | m = re.search(exp, commit, re.MULTILINE) | |
42 | else: |
|
42 | if m: | |
43 | commit = sys.stdin.read() |
|
43 | pos = 0 | |
|
44 | for n, l in enumerate(commit.splitlines(True)): | |||
|
45 | pos += len(l) | |||
|
46 | if pos >= m.end(): | |||
|
47 | print "%d: %s" % (n, msg) | |||
|
48 | print " %s" % l[:-1] | |||
|
49 | if "BYPASS" not in os.environ: | |||
|
50 | exitcode = 1 | |||
|
51 | break | |||
|
52 | return exitcode | |||
44 |
|
53 | |||
45 | exitcode = 0 |
|
54 | def readcommit(node): | |
46 | for exp, msg in errors: |
|
55 | return os.popen("hg export %s" % node).read() | |
47 | m = re.search(exp, commit, re.MULTILINE) |
|
56 | ||
48 | if m: |
|
57 | if __name__ == "__main__": | |
49 | pos = 0 |
|
58 | node = os.environ.get("HG_NODE") | |
50 | for n, l in enumerate(commit.splitlines(True)): |
|
|||
51 | pos += len(l) |
|
|||
52 | if pos >= m.end(): |
|
|||
53 | print "%d: %s" % (n, msg) |
|
|||
54 | print " %s" % l[:-1] |
|
|||
55 | if "BYPASS" not in os.environ: |
|
|||
56 | exitcode = 1 |
|
|||
57 | break |
|
|||
58 |
|
59 | |||
59 | sys.exit(exitcode) |
|
60 | if node: | |
|
61 | commit = readcommit(node) | |||
|
62 | else: | |||
|
63 | commit = sys.stdin.read() | |||
|
64 | ||||
|
65 | exitcode = checkcommit(commit) | |||
|
66 | sys.exit(exitcode) |
General Comments 0
You need to be logged in to leave comments.
Login now