view contrib/check-commit @ 22864:96b6b3d78697

revset: cache most conditions used in `filter` Except when stated otherwise, the condition used in `smartset.filter` will be cached. A new argument has been introduced to disable that behavior. We use it for filters created from `and` and `sub` operations. This gives massive performance boosts for revsets with expensive conditions. revset: branch(stable) or branch(default) before) wall 4.329070 comb 4.320000 user 4.310000 sys 0.010000 (best of 3) after) wall 2.356451 comb 2.360000 user 2.330000 sys 0.030000 (best of 4) revset: author(mpm) or author(lmoscovicz) before) wall 4.434719 comb 4.440000 user 4.440000 sys 0.000000 (best of 3) after) wall 2.321720 comb 2.320000 user 2.320000 sys 0.000000 (best of 4)
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 09 Oct 2014 22:57:52 -0700
parents 15d0390a27fe
children ba272156113f
line wrap: on
line source

#!/usr/bin/env python
#
# Copyright 2014 Matt Mackall <mpm@selenic.com>
#
# A tool/hook to run basic sanity checks on commits/patches for
# submission to Mercurial. Install by adding the following to your
# .hg/hgrc:
#
# [hooks]
# pretxncommit = contrib/check-commit
#
# The hook can be temporarily bypassed with:
#
# $ BYPASS= hg commit
#
# See also: http://mercurial.selenic.com/wiki/ContributingChanges

import re, sys, os

errors = [
    (r"[(]bc[)]", "(BC) needs to be uppercase"),
    (r"[(]issue \d\d\d", "no space allowed between issue and number"),
    (r"[(]bug", "use (issueDDDD) instead of bug"),
    (r"^# User [^@\n]+$", "username is not an email address"),
    (r"^# .*\n(?!merge with )[^#]\S+[^:] ",
     "summary line doesn't start with 'topic: '"),
    (r"^# .*\n[A-Z][a-z]\S+", "don't capitalize summary lines"),
    (r"^# .*\n.*\.\s+$", "don't add trailing period on summary line"),
    (r"^# .*\n.{78,}", "summary line too long"),
    (r"^\+\n \n", "adds double empty line"),
    (r"\+\s+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()

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

sys.exit(exitcode)