Skip to content

Commit 005f3fb

Browse files
10ne1gitster
authored andcommitted
builtin/receive-pack: avoid spinning no-op sideband async threads
Exit early if the hooks do not exist, to avoid spinning up/down sideband async threads which no-op. It is important to call the hook_exists() API provided by hook.[ch] because it covers both config-defined hooks and the "traditional" hooks from the hookdir. find_hook() only covers the hookdir hooks. The regression happened because the no-op async threads add some additional overhead which can be measured with the receive-refs test of the benchmarks suite [1]. Reproduced using: cd benchmarks/receive-refs && \ ./run --revisions /path/to/git \ fc148b1~,fc148b146ad41be71a7852c4867f0773cbfe1ff9 \ --parameter-list refformat reftable --parameter-list refcount 10000 1: https://gitlab.com/gitlab-org/data-access/git/benchmarks Fixes: fc148b1 ("receive-pack: convert update hooks to new API") Reported-by: Patrick Steinhardt <ps@pks.im> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> [jc: avoid duplicated hardcoded hook names] Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b5e9ad5 commit 005f3fb

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

builtin/receive-pack.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ static int run_receive_hook(struct command *commands,
914914
int saved_stderr = -1;
915915
int ret;
916916

917+
if (!hook_exists(the_repository, hook_name))
918+
return 0;
919+
917920
/* if there are no valid commands, don't invoke the hook at all. */
918921
while (iter && skip_broken && (iter->error_string || iter->did_not_exist))
919922
iter = iter->next;
@@ -955,12 +958,16 @@ static int run_receive_hook(struct command *commands,
955958

956959
static int run_update_hook(struct command *cmd)
957960
{
961+
static const char hook_name[] = "update";
958962
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
959963
struct async sideband_async;
960964
int sideband_async_started = 0;
961965
int saved_stderr = -1;
962966
int code;
963967

968+
if (!hook_exists(the_repository, hook_name))
969+
return 0;
970+
964971
strvec_pushl(&opt.args,
965972
cmd->ref_name,
966973
oid_to_hex(&cmd->old_oid),
@@ -969,7 +976,7 @@ static int run_update_hook(struct command *cmd)
969976

970977
prepare_sideband_async(&sideband_async, &saved_stderr, &sideband_async_started);
971978

972-
code = run_hooks_opt(the_repository, "update", &opt);
979+
code = run_hooks_opt(the_repository, hook_name, &opt);
973980

974981
finish_sideband_async(&sideband_async, saved_stderr, sideband_async_started);
975982

@@ -1649,12 +1656,16 @@ static const char *update(struct command *cmd, struct shallow_info *si)
16491656

16501657
static void run_update_post_hook(struct command *commands)
16511658
{
1659+
static const char hook_name[] = "post-update";
16521660
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
16531661
struct async sideband_async;
16541662
struct command *cmd;
16551663
int sideband_async_started = 0;
16561664
int saved_stderr = -1;
16571665

1666+
if (!hook_exists(the_repository, hook_name))
1667+
return;
1668+
16581669
for (cmd = commands; cmd; cmd = cmd->next) {
16591670
if (cmd->error_string || cmd->did_not_exist)
16601671
continue;
@@ -1665,7 +1676,7 @@ static void run_update_post_hook(struct command *commands)
16651676

16661677
prepare_sideband_async(&sideband_async, &saved_stderr, &sideband_async_started);
16671678

1668-
run_hooks_opt(the_repository, "post-update", &opt);
1679+
run_hooks_opt(the_repository, hook_name, &opt);
16691680

16701681
finish_sideband_async(&sideband_async, saved_stderr, sideband_async_started);
16711682
}

0 commit comments

Comments
 (0)