diff mbox series

[v8,32/37] post-update: use hook.h library

Message ID 20210311021037.3001235-33-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series config-based hooks | expand

Commit Message

Emily Shaffer March 11, 2021, 2:10 a.m. UTC
By using run_hooks() instead of run_hook_le(), 'post-update' hooks can
be specified in the config as well as the hookdir.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 Documentation/githooks.txt |  3 +++
 builtin/receive-pack.c     | 27 ++++++++-------------------
 2 files changed, 11 insertions(+), 19 deletions(-)

Comments

Ævar Arnfjörð Bjarmason March 12, 2021, 9:14 a.m. UTC | #1
On Thu, Mar 11 2021, Emily Shaffer wrote:

> By using run_hooks() instead of run_hook_le(), 'post-update' hooks can
> be specified in the config as well as the hookdir.

Looking ahead in the series no tests for this, seems like a good thing
to have some at least trivial tests for each hook and their config
invocation.
Emily Shaffer March 30, 2021, 12:01 a.m. UTC | #2
On Fri, Mar 12, 2021 at 10:14:31AM +0100, Ævar Arnfjörð Bjarmason wrote:
> 
> 
> On Thu, Mar 11 2021, Emily Shaffer wrote:
> 
> > By using run_hooks() instead of run_hook_le(), 'post-update' hooks can
> > be specified in the config as well as the hookdir.
> 
> Looking ahead in the series no tests for this, seems like a good thing
> to have some at least trivial tests for each hook and their config
> invocation.

I'll look through the series and make sure the hooks being converted
have at least some test to make sure they worked; I think I checked that
for some of the early ones but got lazy :) I'll try and add some
config-specified tests too. Thanks, it's on my todo list.

 - Emily
diff mbox series

Patch

diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index c16353be2d..fe5381b95b 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -508,6 +508,9 @@  Both standard output and standard error output are forwarded to
 `git send-pack` on the other end, so you can simply `echo` messages
 for the user.
 
+Hooks run during 'post-update' will be run in parallel, unless hook.jobs is
+configured to 1.
+
 reference-transaction
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e448956a32..955efbdf6d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1688,33 +1688,22 @@  static const char *update(struct command *cmd, struct shallow_info *si)
 static void run_update_post_hook(struct command *commands)
 {
 	struct command *cmd;
-	struct child_process proc = CHILD_PROCESS_INIT;
-	const char *hook;
-
-	hook = find_hook("post-update");
-	if (!hook)
-		return;
+	struct run_hooks_opt opt;
+	run_hooks_opt_init_async(&opt);
 
 	for (cmd = commands; cmd; cmd = cmd->next) {
 		if (cmd->error_string || cmd->did_not_exist)
 			continue;
-		if (!proc.args.nr)
-			strvec_push(&proc.args, hook);
-		strvec_push(&proc.args, cmd->ref_name);
+		strvec_push(&opt.args, cmd->ref_name);
 	}
-	if (!proc.args.nr)
+	if (!opt.args.nr)
 		return;
 
-	proc.no_stdin = 1;
-	proc.stdout_to_stderr = 1;
-	proc.err = use_sideband ? -1 : 0;
-	proc.trace2_hook_name = "post-update";
+	if (use_sideband)
+		opt.consume_sideband = hook_output_to_sideband;
 
-	if (!start_command(&proc)) {
-		if (use_sideband)
-			copy_to_sideband(proc.err, -1, NULL);
-		finish_command(&proc);
-	}
+	run_hooks("post-update", &opt);
+	run_hooks_opt_clear(&opt);
 }
 
 static void check_aliased_update_internal(struct command *cmd,