aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2023-06-09 23:14:37 -0400
committerMike Frysinger <vapier@google.com>2023-06-22 14:22:39 -0400
commit1fc51c305b4b77365b3119062332843956b1be77 (patch)
tree5b83239021d12e8021c81e765fe58e94a5326e5c
parente2a519ed6fdb51fd790cad792e72302e4ea2bccf (diff)
downloadrepohooks-1fc51c305b4b77365b3119062332843956b1be77.tar.gz
pre-upload: hoist exclusion logic earlier
Filter the set of hooks as soon as we have all the info we need. If all the hooks are filtered, we can exit sooner. Otherwise, present a more accurate summary to users as to how many hooks we'll actually be running. Since we no longer need the scope in the main loop, switch to processing the NamedTuple directly so we don't have to unpack every field in it. Bug: 160223496 Test: unittests Change-Id: I63d65a9034a6d4ca6d70b158ceab7c6f5861f326
-rwxr-xr-xpre-upload.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/pre-upload.py b/pre-upload.py
index 5d57a71..6c43c42 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -319,8 +319,6 @@ def _run_project_hooks_in_cwd(
if not hooks:
return ret
- output.set_num_hooks(len(hooks))
-
# Set up the environment like repo would with the forall command.
try:
remote = rh.git.get_upstream_remote()
@@ -334,6 +332,12 @@ def _run_project_hooks_in_cwd(
project = rh.Project(name=project_name, dir=proj_dir)
rel_proj_dir = os.path.relpath(proj_dir, rh.git.find_repo_root())
+ # Filter out the hooks to process.
+ hooks = [x for x in hooks if rel_proj_dir not in x.scope]
+ if not hooks:
+ return ret
+ output.set_num_hooks(len(hooks))
+
os.environ.update({
'REPO_LREV': rh.git.get_commit_for_ref(upstream_branch),
'REPO_PATH': rel_proj_dir,
@@ -357,11 +361,9 @@ def _run_project_hooks_in_cwd(
commit_summary = desc.split('\n', 1)[0]
output.commit_start(commit=commit, commit_summary=commit_summary)
- for name, hook, exclusion_scope in hooks:
- if rel_proj_dir in exclusion_scope:
- continue
- output.hook_start(name)
- hook_results = hook(project, commit, desc, diff)
+ for hook in hooks:
+ output.hook_start(hook.name)
+ hook_results = hook.hook(project, commit, desc, diff)
output.hook_finish()
ret.add_results(hook_results)
(error, warning) = _process_hook_results(hook_results)