hghooks: pass 'node' to pre() hook methods (
bug 1454296) r?gps
Pass 'node' to pre() to allow hooks to inspect the whole commit.
MozReview-Commit-ID: ET4hjte1vzO
--- a/hghooks/mozhghooks/check/prevent_cross_channel_messages.py
+++ b/hghooks/mozhghooks/check/prevent_cross_channel_messages.py
@@ -30,17 +30,17 @@ class XChannelMessageCheck(PreTxnChangeg
def name(self):
return 'x_channel_message'
def relevant(self):
return (
self.repo_metadata['firefox']
or self.repo_metadata['thunderbird'])
- def pre(self):
+ def pre(self, node):
pass
def check(self, ctx):
if not any(line.startswith('X-Channel-')
for line in ctx.description().splitlines()):
return True
print_banner(self.ui, 'error', X_CHANNEL_COMMIT_FOUND)
--- a/hghooks/mozhghooks/check/prevent_ftl_changes.py
+++ b/hghooks/mozhghooks/check/prevent_ftl_changes.py
@@ -44,17 +44,17 @@ class FTLCheck(PreTxnChangegroupCheck):
"""
@property
def name(self):
return 'ftl_check'
def relevant(self):
return self.repo_metadata['firefox_releasing']
- def pre(self):
+ def pre(self, node):
pass
def check(self, ctx):
if len(ctx.parents()) > 1:
# Skip merge changesets
return True
if is_backout(ctx.description()):
--- a/hghooks/mozhghooks/check/prevent_subrepos.py
+++ b/hghooks/mozhghooks/check/prevent_subrepos.py
@@ -33,17 +33,17 @@ class PreventSubReposCheck(PreTxnChangeg
"""
@property
def name(self):
return 'prevent_subrepos'
def relevant(self):
return True
- def pre(self):
+ def pre(self, node):
self.done = False
def check(self, ctx):
# Since the check can be non-fatal and since it requires a manifest
# (which can be expensive to obtain), no-op if there is no work to do.
if self.done:
return True
--- a/hghooks/mozhghooks/check/prevent_symlinks.py
+++ b/hghooks/mozhghooks/check/prevent_symlinks.py
@@ -32,17 +32,17 @@ class PreventSymlinksCheck(PreTxnChangeg
@property
def name(self):
return 'prevent_symlinks'
def relevant(self):
return not self.repo_metadata['user_repo']
- def pre(self):
+ def pre(self, node):
pass
def check(self, ctx):
manifest = ctx.manifest()
links = []
for f in ctx.files():
if f not in manifest:
--- a/hghooks/mozhghooks/check/prevent_wptsync_changes.py
+++ b/hghooks/mozhghooks/check/prevent_wptsync_changes.py
@@ -40,17 +40,17 @@ class WPTSyncCheck(PreTxnChangegroupChec
"""
@property
def name(self):
return 'wptsync_check'
def relevant(self):
return os.environ['USER'] == 'wptsync@mozilla.com'
- def pre(self):
+ def pre(self, node):
pass
def check(self, ctx):
success = False
if self.repo_metadata['path'] == 'try':
success = True
elif self.repo_metadata['path'] == 'integration/mozilla-inbound':
invalid_paths = [path for path in ctx.files() if not allowed_paths.match(path)]
--- a/hghooks/mozhghooks/check/single_root.py
+++ b/hghooks/mozhghooks/check/single_root.py
@@ -38,17 +38,17 @@ class SingleRootCheck(PreTxnChangegroupC
"""
@property
def name(self):
return 'single_root'
def relevant(self):
return not self.repo_metadata['user_repo']
- def pre(self):
+ def pre(self, node):
self.new_roots = set()
def check(self, ctx):
if ctx.rev() != 0 and ctx.p1().node() == nullid:
self.new_roots.add(ctx.node())
return True
--- a/hghooks/mozhghooks/check/try_task_config_file.py
+++ b/hghooks/mozhghooks/check/try_task_config_file.py
@@ -26,17 +26,17 @@ class TryConfigCheck(PreTxnChangegroupCh
"""
@property
def name(self):
return 'try_task_config'
def relevant(self):
return self.repo_metadata['firefox_releasing']
- def pre(self):
+ def pre(self, node):
pass
def check(self, ctx):
if 'try_task_config.json' not in ctx.files():
return True
print_banner(self.ui, 'error', TRY_CONFIG_FOUND)
return False
--- a/hghooks/mozhghooks/checks.py
+++ b/hghooks/mozhghooks/checks.py
@@ -57,29 +57,34 @@ class PreTxnChangegroupCheck(object):
Returns True if the check should run. False otherwise.
The return value of this method is tightly validated to help prevent
logic bugs.
"""
@abc.abstractmethod
- def pre(self):
+ def pre(self, node):
"""Called once before any changesets are examined.
Allows derived classes to set additional instance state without having
to call parent methods.
+ `node` - the first changeset in the group that was added (as per
+ pretxnchangegroup).
+
Return value is ignored.
"""
@abc.abstractmethod
def check(self, ctx):
"""Verifies a single changeset.
+ `ctx` - changectx object.
+
Returns True if the check passes. False otherwise.
"""
@abc.abstractmethod
def post_check(self):
"""Called after all changesets have been checked.
If the check gathers state during per-changeset invocations and needs
--- a/hghooks/mozhghooks/extension.py
+++ b/hghooks/mozhghooks/extension.py
@@ -124,17 +124,17 @@ def get_checks(ui, repo, source, classes
return checks
def pretxnchangegroup(ui, repo, node, source=None, **kwargs):
checks = get_checks(ui, repo, source,
get_check_classes('pretxnchangegroup'))
for check in checks:
- check.pre()
+ check.pre(node)
for rev in repo.changelog.revs(repo[node].rev()):
ctx = repo[rev]
for check in checks:
if not check.check(ctx):
return 1