hghooks: fix pep8/style issues in commit-message.py (
bug 1366667) r?gps
MozReview-Commit-ID: 1RWuVp9BmjG
--- a/hghooks/mozhghooks/commit-message.py
+++ b/hghooks/mozhghooks/commit-message.py
@@ -8,128 +8,138 @@
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import re
from mercurial.node import hex, short
-INVALID_REVIEW_FLAG_RE = re.compile(r'[\s\.;]r\?(?:\w|$)')
+INVALID_REVIEW_FLAG_RE = re.compile(r'[\s.;]r\?(?:\w|$)')
goodMessage = [re.compile(x, re.I) for x in [
r'bug [0-9]+',
r'no bug',
r'^(back(ing|ed)?\s+out|backout).*(\s+|\:)[0-9a-f]{12}',
r'^(revert(ed|ing)?).*(\s+|\:)[0-9a-f]{12}',
r'^add(ed|ing)? tag'
]]
trySyntax = re.compile(r'\btry:')
VENDORED_PATHS = (
'servo/',
)
-def isvendorctx(ctx):
+
+def is_vendor_ctx(ctx):
# This check isn't strictly necessary. But it does filter out
# most changesets without having to inspect the file list.
desc = ctx.description()
if 'Source-Revision: ' not in desc:
return False
# Other hooks should ensure that only certain users can change
# vendored paths.
if not any(f.startswith(VENDORED_PATHS) for f in ctx.files()):
return False
return True
-def isGoodMessage(c):
+def is_good_message(ui, c):
def message(fmt):
- print "\n\n************************** ERROR ****************************"
- print fmt.format(rev = hex(c.node())[:12])
- print c.user()
- print c.description()
- print "*************************************************************\n\n"
+ ui.write(
+ '\n\n'
+ '************************** ERROR ****************************\n'
+ '%s\n%s\n%s\n'
+ '*************************************************************\n'
+ '\n\n'
+ % (fmt.format(rev=hex(c.node())[:12]), c.user(), c.description())
+ )
- if isvendorctx(c):
- print('(%s looks like a vendoring change; ignoring commit message '
- 'hook)' % short(c.node()))
+ if is_vendor_ctx(c):
+ ui.write('(%s looks like a vendoring change; ignoring commit message '
+ 'hook)\n' % short(c.node()))
return True
desc = c.description()
firstline = desc.splitlines()[0]
if c.user() in ["ffxbld", "seabld", "tbirdbld", "cltbld",
"Gaia Pushbot <release+gaiajson@mozilla.com>",
"B2G Bumper Bot <release+b2gbumper@mozilla.com>"]:
return True
if trySyntax.search(desc):
- message("Rev {rev} uses try syntax. (Did you mean to push to Try instead?)")
+ message("Rev {rev} uses try syntax. (Did you mean to push to Try "
+ "instead?)")
return False
# Match against [PATCH] and [PATCH n/m]
if "[PATCH" in desc:
- message("Rev {rev} contains git-format-patch \"[PATCH]\" cruft. Use git-format-patch -k to avoid this.")
+ message('Rev {rev} contains git-format-patch "[PATCH]" cruft. Use '
+ 'git-format-patch -k to avoid this.')
return False
if INVALID_REVIEW_FLAG_RE.search(firstline):
- message("Rev {rev} contains 'r?' in the commit message. Please use 'r=' instead.")
+ message("Rev {rev} contains 'r?' in the commit message. Please use "
+ "'r=' instead.")
return False
for r in goodMessage:
if r.search(firstline):
return True
- dlower = desc.lower()
- if dlower.startswith("merge") or dlower.startswith("merging") or dlower.startswith("automated merge"):
+ desc_lower = desc.lower()
+ if desc_lower.startswith(('merge', 'merging', 'automated merge')):
if len(c.parents()) == 2:
return True
else:
- message("Rev {rev} claims to be a merge, but it has only one parent.")
+ message("Rev {rev} claims to be a merge, but it has only one "
+ "parent.")
return False
- if dlower.startswith("back") or dlower.startswith("revert"):
- # Purposely ambiguous: it's ok to say "backed out rev N" or "reverted to rev N-1"
+ if desc_lower.startswith(('back', 'revert')):
+ # Purposely ambiguous: it's ok to say "backed out rev N" or
+ # "reverted to rev N-1"
message("Backout rev {rev} needs a bug number or a rev id.")
else:
- message("Rev {rev} needs \"Bug N\" or \"No bug\" in the commit message.")
+ message('Rev {rev} needs "Bug N" or "No bug" in the commit message.')
return False
+
def hook(ui, repo, node, hooktype, source=None, **kwargs):
if source in ('pull', 'strip'):
return 0
# All changesets from node to "tip" inclusive are part of this push.
rev = repo.changectx(node).rev()
tip = repo.changectx("tip").rev()
rejecting = False
for i in reversed(xrange(rev, tip + 1)):
c = repo.changectx(i)
if "IGNORE BAD COMMIT MESSAGES" in c.description():
# Ignore commit messages for all earlier revs in this push.
break
- if not isGoodMessage(c):
+ if not is_good_message(ui, c):
# Keep looping so the pusher sees all commits they need to fix.
rejecting = True
if not rejecting:
- return 0
+ return 0
# We want to allow using this hook locally
if hooktype == "pretxnchangegroup":
return 1
- print "This changeset would have been rejected!"
- return 0 # to fail not warn change to 1
+ ui.write('This changeset would have been rejected!\n')
+ return 0 # to fail not warn change to 1