Mercurial > hg
changeset 27780:f47185f09533
check-commit: modularize
author | timeless <timeless@mozdev.org> |
---|---|
date | Thu, 07 Jan 2016 00:55:45 +0000 |
parents | b2479d305c10 |
children | 2af351bd289c |
files | contrib/check-commit |
diffstat | 1 files changed, 27 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/check-commit Thu Jan 07 03:58:40 2016 +0000 +++ b/contrib/check-commit Thu Jan 07 00:55:45 2016 +0000 @@ -35,25 +35,32 @@ (r"^\+[ \t]+def [a-z]+_[a-z]", "adds a function with foo_bar naming"), ] -node = os.environ.get("HG_NODE") - -if node: - commit = os.popen("hg export %s" % node).read() -else: - commit = sys.stdin.read() +def checkcommit(commit): + exitcode = 0 + for exp, msg in errors: + m = re.search(exp, commit, re.MULTILINE) + if m: + pos = 0 + for n, l in enumerate(commit.splitlines(True)): + pos += len(l) + if pos >= m.end(): + print "%d: %s" % (n, msg) + print " %s" % l[:-1] + if "BYPASS" not in os.environ: + exitcode = 1 + break + return exitcode -exitcode = 0 -for exp, msg in errors: - m = re.search(exp, commit, re.MULTILINE) - if m: - pos = 0 - for n, l in enumerate(commit.splitlines(True)): - pos += len(l) - if pos >= m.end(): - print "%d: %s" % (n, msg) - print " %s" % l[:-1] - if "BYPASS" not in os.environ: - exitcode = 1 - break +def readcommit(node): + return os.popen("hg export %s" % node).read() + +if __name__ == "__main__": + node = os.environ.get("HG_NODE") -sys.exit(exitcode) + if node: + commit = readcommit(node) + else: + commit = sys.stdin.read() + + exitcode = checkcommit(commit) + sys.exit(exitcode)