Skip to content

Commit 169c979

Browse files
pks-tgitster
authored andcommitted
hooks: remove implicit dependency on the_repository
We implicitly depend on `the_repository` in our hook subsystem because we use `strbuf_git_path()` to compute hook paths. Remove this dependency by accepting a `struct repository` as parameter instead. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 419dbb2 commit 169c979

File tree

18 files changed

+47
-42
lines changed

18 files changed

+47
-42
lines changed

builtin/am.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ static int run_applypatch_msg_hook(struct am_state *state)
490490
assert(state->msg);
491491

492492
if (!state->no_verify)
493-
ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL);
493+
ret = run_hooks_l(the_repository, "applypatch-msg",
494+
am_path(state, "final-commit"), NULL);
494495

495496
if (!ret) {
496497
FREE_AND_NULL(state->msg);
@@ -512,7 +513,7 @@ static int run_post_rewrite_hook(const struct am_state *state)
512513
strvec_push(&opt.args, "rebase");
513514
opt.path_to_stdin = am_path(state, "rewritten");
514515

515-
return run_hooks_opt("post-rewrite", &opt);
516+
return run_hooks_opt(the_repository, "post-rewrite", &opt);
516517
}
517518

518519
/**
@@ -1663,7 +1664,7 @@ static void do_commit(const struct am_state *state)
16631664
const char *reflog_msg, *author, *committer = NULL;
16641665
struct strbuf sb = STRBUF_INIT;
16651666

1666-
if (!state->no_verify && run_hooks("pre-applypatch"))
1667+
if (!state->no_verify && run_hooks(the_repository, "pre-applypatch"))
16671668
exit(1);
16681669

16691670
if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL))
@@ -1716,7 +1717,7 @@ static void do_commit(const struct am_state *state)
17161717
fclose(fp);
17171718
}
17181719

1719-
run_hooks("post-applypatch");
1720+
run_hooks(the_repository, "post-applypatch");
17201721

17211722
free_commit_list(parents);
17221723
strbuf_release(&sb);

builtin/bugreport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
5858
for (p = hook_name_list; *p; p++) {
5959
const char *hook = *p;
6060

61-
if (hook_exists(hook))
61+
if (hook_exists(the_repository, hook))
6262
strbuf_addf(hook_info, "%s\n", hook);
6363
}
6464
}

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void branch_info_release(struct branch_info *info)
125125
static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
126126
int changed)
127127
{
128-
return run_hooks_l("post-checkout",
128+
return run_hooks_l(the_repository, "post-checkout",
129129
oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
130130
oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
131131
changed ? "1" : "0", NULL);

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ static int checkout(int submodule_progress, int filter_submodules)
788788
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
789789
die(_("unable to write new index file"));
790790

791-
err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()),
791+
err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid()),
792792
oid_to_hex(&oid), "1", NULL);
793793

794794
if (!err && (option_recurse_submodules.nr > 0)) {

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int need_to_gc(void)
463463
else
464464
return 0;
465465

466-
if (run_hooks("pre-auto-gc"))
466+
if (run_hooks(the_repository, "pre-auto-gc"))
467467
return 0;
468468
return 1;
469469
}

builtin/hook.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int run(int argc, const char **argv, const char *prefix)
5858
hook_name = argv[0];
5959
if (!ignore_missing)
6060
opt.error_if_missing = 1;
61-
ret = run_hooks_opt(hook_name, &opt);
61+
ret = run_hooks_opt(the_repository, hook_name, &opt);
6262
if (ret < 0) /* error() return */
6363
ret = 1;
6464
return ret;

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static void finish(struct commit *head_commit,
478478
}
479479

480480
/* Run a post-merge hook */
481-
run_hooks_l("post-merge", squash ? "1" : "0", NULL);
481+
run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL);
482482

483483
if (new_head)
484484
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");

builtin/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17741774

17751775
/* If a hook exists, give it a chance to interrupt*/
17761776
if (!ok_to_skip_pre_rebase &&
1777-
run_hooks_l("pre-rebase", options.upstream_arg,
1777+
run_hooks_l(the_repository, "pre-rebase", options.upstream_arg,
17781778
argc ? argv[0] : NULL, NULL))
17791779
die(_("The pre-rebase hook refused to rebase."));
17801780

builtin/receive-pack.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,
792792
struct child_process proc = CHILD_PROCESS_INIT;
793793
struct async muxer;
794794
int code;
795-
const char *hook_path = find_hook(hook_name);
795+
const char *hook_path = find_hook(the_repository, hook_name);
796796

797797
if (!hook_path)
798798
return 0;
@@ -922,7 +922,7 @@ static int run_update_hook(struct command *cmd)
922922
{
923923
struct child_process proc = CHILD_PROCESS_INIT;
924924
int code;
925-
const char *hook_path = find_hook("update");
925+
const char *hook_path = find_hook(the_repository, "update");
926926

927927
if (!hook_path)
928928
return 0;
@@ -1098,7 +1098,7 @@ static int run_proc_receive_hook(struct command *commands,
10981098
int hook_use_push_options = 0;
10991099
int version = 0;
11001100
int code;
1101-
const char *hook_path = find_hook("proc-receive");
1101+
const char *hook_path = find_hook(the_repository, "proc-receive");
11021102

11031103
if (!hook_path) {
11041104
rp_error("cannot find hook 'proc-receive'");
@@ -1409,7 +1409,7 @@ static const char *push_to_checkout(unsigned char *hash,
14091409
strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree));
14101410
strvec_pushv(&opt.env, env->v);
14111411
strvec_push(&opt.args, hash_to_hex(hash));
1412-
if (run_hooks_opt(push_to_checkout_hook, &opt))
1412+
if (run_hooks_opt(the_repository, push_to_checkout_hook, &opt))
14131413
return "push-to-checkout hook declined";
14141414
else
14151415
return NULL;
@@ -1618,7 +1618,7 @@ static void run_update_post_hook(struct command *commands)
16181618
struct child_process proc = CHILD_PROCESS_INIT;
16191619
const char *hook;
16201620

1621-
hook = find_hook("post-update");
1621+
hook = find_hook(the_repository, "post-update");
16221622
if (!hook)
16231623
return;
16241624

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int add_worktree(const char *path, const char *refname,
573573
NULL);
574574
opt.dir = path;
575575

576-
ret = run_hooks_opt("post-checkout", &opt);
576+
ret = run_hooks_opt(the_repository, "post-checkout", &opt);
577577
}
578578

579579
strvec_clear(&child_env);

0 commit comments

Comments
 (0)