Skip to content

Commit 5e5cc0e

Browse files
nasamuffingitster
authored andcommitted
receive-pack: convert update hooks to new API
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>
1 parent fedcd93 commit 5e5cc0e

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

builtin/receive-pack.c

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -939,31 +939,26 @@ static int run_receive_hook(struct command *commands,
939939
return status;
940940
}
941941

942-
static int run_update_hook(struct command *cmd)
942+
static void hook_output_to_sideband(struct strbuf *output, void *cb_data UNUSED)
943943
{
944-
struct child_process proc = CHILD_PROCESS_INIT;
945-
int code;
946-
const char *hook_path = find_hook(the_repository, "update");
947-
948-
if (!hook_path)
949-
return 0;
944+
if (output && output->len)
945+
send_sideband(1, 2, output->buf, output->len, use_sideband);
946+
}
950947

951-
strvec_push(&proc.args, hook_path);
952-
strvec_push(&proc.args, cmd->ref_name);
953-
strvec_push(&proc.args, oid_to_hex(&cmd->old_oid));
954-
strvec_push(&proc.args, oid_to_hex(&cmd->new_oid));
948+
static int run_update_hook(struct command *cmd)
949+
{
950+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
955951

956-
proc.no_stdin = 1;
957-
proc.stdout_to_stderr = 1;
958-
proc.err = use_sideband ? -1 : 0;
959-
proc.trace2_hook_name = "update";
952+
strvec_pushl(&opt.args,
953+
cmd->ref_name,
954+
oid_to_hex(&cmd->old_oid),
955+
oid_to_hex(&cmd->new_oid),
956+
NULL);
960957

961-
code = start_command(&proc);
962-
if (code)
963-
return code;
964958
if (use_sideband)
965-
copy_to_sideband(proc.err, -1, NULL);
966-
return finish_command(&proc);
959+
opt.consume_sideband = hook_output_to_sideband;
960+
961+
return run_hooks_opt(the_repository, "update", &opt);
967962
}
968963

969964
static struct command *find_command_by_refname(struct command *list,
@@ -1640,33 +1635,20 @@ static const char *update(struct command *cmd, struct shallow_info *si)
16401635
static void run_update_post_hook(struct command *commands)
16411636
{
16421637
struct command *cmd;
1643-
struct child_process proc = CHILD_PROCESS_INIT;
1644-
const char *hook;
1645-
1646-
hook = find_hook(the_repository, "post-update");
1647-
if (!hook)
1648-
return;
1638+
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
16491639

16501640
for (cmd = commands; cmd; cmd = cmd->next) {
16511641
if (cmd->error_string || cmd->did_not_exist)
16521642
continue;
1653-
if (!proc.args.nr)
1654-
strvec_push(&proc.args, hook);
1655-
strvec_push(&proc.args, cmd->ref_name);
1643+
strvec_push(&opt.args, cmd->ref_name);
16561644
}
1657-
if (!proc.args.nr)
1645+
if (!opt.args.nr)
16581646
return;
16591647

1660-
proc.no_stdin = 1;
1661-
proc.stdout_to_stderr = 1;
1662-
proc.err = use_sideband ? -1 : 0;
1663-
proc.trace2_hook_name = "post-update";
1648+
if (use_sideband)
1649+
opt.consume_sideband = hook_output_to_sideband;
16641650

1665-
if (!start_command(&proc)) {
1666-
if (use_sideband)
1667-
copy_to_sideband(proc.err, -1, NULL);
1668-
finish_command(&proc);
1669-
}
1651+
run_hooks_opt(the_repository, "post-update", &opt);
16701652
}
16711653

16721654
static void check_aliased_update_internal(struct command *cmd,

0 commit comments

Comments
 (0)