]> git.ipfire.org Git - thirdparty/git.git/commitdiff
receive-pack: convert update hooks to new API
authorEmily Shaffer <emilyshaffer@google.com>
Fri, 17 Oct 2025 14:15:43 +0000 (17:15 +0300)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Oct 2025 21:32:53 +0000 (14:32 -0700)
Use the new hook sideband API introduced in the previous commit.

The hook API avoids creating a custom struct child_process and other
internal hook plumbing (e.g. calling find_hook()) and prepares for
the specification of hooks via configs or running parallel hooks.

Execution is still sequential through the current hook.[ch] via the
run_proces_parallel_opts.processes=1 arg.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/receive-pack.c

index c9288a9c7e382bd19193d8b94268e0d0bec2c7f8..93b6f28662aaa1c290ec400c7914f8e1196f7fff 100644 (file)
@@ -939,31 +939,26 @@ static int run_receive_hook(struct command *commands,
        return status;
 }
 
-static int run_update_hook(struct command *cmd)
+static void hook_output_to_sideband(struct strbuf *output, void *cb_data UNUSED)
 {
-       struct child_process proc = CHILD_PROCESS_INIT;
-       int code;
-       const char *hook_path = find_hook(the_repository, "update");
-
-       if (!hook_path)
-               return 0;
+       if (output && output->len)
+               send_sideband(1, 2, output->buf, output->len, use_sideband);
+}
 
-       strvec_push(&proc.args, hook_path);
-       strvec_push(&proc.args, cmd->ref_name);
-       strvec_push(&proc.args, oid_to_hex(&cmd->old_oid));
-       strvec_push(&proc.args, oid_to_hex(&cmd->new_oid));
+static int run_update_hook(struct command *cmd)
+{
+       struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
 
-       proc.no_stdin = 1;
-       proc.stdout_to_stderr = 1;
-       proc.err = use_sideband ? -1 : 0;
-       proc.trace2_hook_name = "update";
+       strvec_pushl(&opt.args,
+                    cmd->ref_name,
+                    oid_to_hex(&cmd->old_oid),
+                    oid_to_hex(&cmd->new_oid),
+                    NULL);
 
-       code = start_command(&proc);
-       if (code)
-               return code;
        if (use_sideband)
-               copy_to_sideband(proc.err, -1, NULL);
-       return finish_command(&proc);
+               opt.consume_sideband = hook_output_to_sideband;
+
+       return run_hooks_opt(the_repository, "update", &opt);
 }
 
 static struct command *find_command_by_refname(struct command *list,
@@ -1640,33 +1635,20 @@ out:
 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(the_repository, "post-update");
-       if (!hook)
-               return;
+       struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
 
        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_opt(the_repository, "post-update", &opt);
 }
 
 static void check_aliased_update_internal(struct command *cmd,