Git fork

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
169c9797 419dbb29

+47 -42
+5 -4
builtin/am.c
··· 490 490 assert(state->msg); 491 491 492 492 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); 494 495 495 496 if (!ret) { 496 497 FREE_AND_NULL(state->msg); ··· 512 513 strvec_push(&opt.args, "rebase"); 513 514 opt.path_to_stdin = am_path(state, "rewritten"); 514 515 515 - return run_hooks_opt("post-rewrite", &opt); 516 + return run_hooks_opt(the_repository, "post-rewrite", &opt); 516 517 } 517 518 518 519 /** ··· 1663 1664 const char *reflog_msg, *author, *committer = NULL; 1664 1665 struct strbuf sb = STRBUF_INIT; 1665 1666 1666 - if (!state->no_verify && run_hooks("pre-applypatch")) 1667 + if (!state->no_verify && run_hooks(the_repository, "pre-applypatch")) 1667 1668 exit(1); 1668 1669 1669 1670 if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL)) ··· 1716 1717 fclose(fp); 1717 1718 } 1718 1719 1719 - run_hooks("post-applypatch"); 1720 + run_hooks(the_repository, "post-applypatch"); 1720 1721 1721 1722 free_commit_list(parents); 1722 1723 strbuf_release(&sb);
+1 -1
builtin/bugreport.c
··· 58 58 for (p = hook_name_list; *p; p++) { 59 59 const char *hook = *p; 60 60 61 - if (hook_exists(hook)) 61 + if (hook_exists(the_repository, hook)) 62 62 strbuf_addf(hook_info, "%s\n", hook); 63 63 } 64 64 }
+1 -1
builtin/checkout.c
··· 125 125 static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit, 126 126 int changed) 127 127 { 128 - return run_hooks_l("post-checkout", 128 + return run_hooks_l(the_repository, "post-checkout", 129 129 oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), 130 130 oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), 131 131 changed ? "1" : "0", NULL);
+1 -1
builtin/clone.c
··· 788 788 if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK)) 789 789 die(_("unable to write new index file")); 790 790 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()), 792 792 oid_to_hex(&oid), "1", NULL); 793 793 794 794 if (!err && (option_recurse_submodules.nr > 0)) {
+1 -1
builtin/gc.c
··· 463 463 else 464 464 return 0; 465 465 466 - if (run_hooks("pre-auto-gc")) 466 + if (run_hooks(the_repository, "pre-auto-gc")) 467 467 return 0; 468 468 return 1; 469 469 }
+1 -1
builtin/hook.c
··· 58 58 hook_name = argv[0]; 59 59 if (!ignore_missing) 60 60 opt.error_if_missing = 1; 61 - ret = run_hooks_opt(hook_name, &opt); 61 + ret = run_hooks_opt(the_repository, hook_name, &opt); 62 62 if (ret < 0) /* error() return */ 63 63 ret = 1; 64 64 return ret;
+1 -1
builtin/merge.c
··· 478 478 } 479 479 480 480 /* 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); 482 482 483 483 if (new_head) 484 484 apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
+1 -1
builtin/rebase.c
··· 1774 1774 1775 1775 /* If a hook exists, give it a chance to interrupt*/ 1776 1776 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, 1778 1778 argc ? argv[0] : NULL, NULL)) 1779 1779 die(_("The pre-rebase hook refused to rebase.")); 1780 1780
+5 -5
builtin/receive-pack.c
··· 792 792 struct child_process proc = CHILD_PROCESS_INIT; 793 793 struct async muxer; 794 794 int code; 795 - const char *hook_path = find_hook(hook_name); 795 + const char *hook_path = find_hook(the_repository, hook_name); 796 796 797 797 if (!hook_path) 798 798 return 0; ··· 922 922 { 923 923 struct child_process proc = CHILD_PROCESS_INIT; 924 924 int code; 925 - const char *hook_path = find_hook("update"); 925 + const char *hook_path = find_hook(the_repository, "update"); 926 926 927 927 if (!hook_path) 928 928 return 0; ··· 1098 1098 int hook_use_push_options = 0; 1099 1099 int version = 0; 1100 1100 int code; 1101 - const char *hook_path = find_hook("proc-receive"); 1101 + const char *hook_path = find_hook(the_repository, "proc-receive"); 1102 1102 1103 1103 if (!hook_path) { 1104 1104 rp_error("cannot find hook 'proc-receive'"); ··· 1409 1409 strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); 1410 1410 strvec_pushv(&opt.env, env->v); 1411 1411 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)) 1413 1413 return "push-to-checkout hook declined"; 1414 1414 else 1415 1415 return NULL; ··· 1618 1618 struct child_process proc = CHILD_PROCESS_INIT; 1619 1619 const char *hook; 1620 1620 1621 - hook = find_hook("post-update"); 1621 + hook = find_hook(the_repository, "post-update"); 1622 1622 if (!hook) 1623 1623 return; 1624 1624
+1 -1
builtin/worktree.c
··· 573 573 NULL); 574 574 opt.dir = path; 575 575 576 - ret = run_hooks_opt("post-checkout", &opt); 576 + ret = run_hooks_opt(the_repository, "post-checkout", &opt); 577 577 } 578 578 579 579 strvec_clear(&child_env);
+1 -1
commit.c
··· 1960 1960 va_end(args); 1961 1961 1962 1962 opt.invoked_hook = invoked_hook; 1963 - return run_hooks_opt(name, &opt); 1963 + return run_hooks_opt(the_repository, name, &opt); 1964 1964 }
+11 -10
hook.c
··· 10 10 #include "environment.h" 11 11 #include "setup.h" 12 12 13 - const char *find_hook(const char *name) 13 + const char *find_hook(struct repository *r, const char *name) 14 14 { 15 15 static struct strbuf path = STRBUF_INIT; 16 16 17 17 int found_hook; 18 18 19 19 strbuf_reset(&path); 20 - strbuf_git_path(&path, "hooks/%s", name); 20 + strbuf_repo_git_path(&path, r, "hooks/%s", name); 21 21 found_hook = access(path.buf, X_OK) >= 0; 22 22 #ifdef STRIP_EXTENSION 23 23 if (!found_hook) { ··· 48 48 return path.buf; 49 49 } 50 50 51 - int hook_exists(const char *name) 51 + int hook_exists(struct repository *r, const char *name) 52 52 { 53 - return !!find_hook(name); 53 + return !!find_hook(r, name); 54 54 } 55 55 56 56 static int pick_next_hook(struct child_process *cp, ··· 121 121 strvec_clear(&options->args); 122 122 } 123 123 124 - int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) 124 + int run_hooks_opt(struct repository *r, const char *hook_name, 125 + struct run_hooks_opt *options) 125 126 { 126 127 struct strbuf abs_path = STRBUF_INIT; 127 128 struct hook_cb_data cb_data = { ··· 129 130 .hook_name = hook_name, 130 131 .options = options, 131 132 }; 132 - const char *const hook_path = find_hook(hook_name); 133 + const char *const hook_path = find_hook(r, hook_name); 133 134 int ret = 0; 134 135 const struct run_process_parallel_opts opts = { 135 136 .tr2_category = "hook", ··· 173 174 return ret; 174 175 } 175 176 176 - int run_hooks(const char *hook_name) 177 + int run_hooks(struct repository *r, const char *hook_name) 177 178 { 178 179 struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; 179 180 180 - return run_hooks_opt(hook_name, &opt); 181 + return run_hooks_opt(r, hook_name, &opt); 181 182 } 182 183 183 - int run_hooks_l(const char *hook_name, ...) 184 + int run_hooks_l(struct repository *r, const char *hook_name, ...) 184 185 { 185 186 struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; 186 187 va_list ap; ··· 191 192 strvec_push(&opt.args, arg); 192 193 va_end(ap); 193 194 194 - return run_hooks_opt(hook_name, &opt); 195 + return run_hooks_opt(r, hook_name, &opt); 195 196 }
+8 -5
hook.h
··· 2 2 #define HOOK_H 3 3 #include "strvec.h" 4 4 5 + struct repository; 6 + 5 7 struct run_hooks_opt 6 8 { 7 9 /* Environment vars to be set for each hook */ ··· 55 57 * or disabled. Note that this points to static storage that will be 56 58 * overwritten by further calls to find_hook and run_hook_*. 57 59 */ 58 - const char *find_hook(const char *name); 60 + const char *find_hook(struct repository *r, const char *name); 59 61 60 62 /** 61 63 * A boolean version of find_hook() 62 64 */ 63 - int hook_exists(const char *hookname); 65 + int hook_exists(struct repository *r, const char *hookname); 64 66 65 67 /** 66 68 * Takes a `hook_name`, resolves it to a path with find_hook(), and ··· 70 72 * Returns the status code of the run hook, or a negative value on 71 73 * error(). 72 74 */ 73 - int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options); 75 + int run_hooks_opt(struct repository *r, const char *hook_name, 76 + struct run_hooks_opt *options); 74 77 75 78 /** 76 79 * A wrapper for run_hooks_opt() which provides a dummy "struct 77 80 * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT". 78 81 */ 79 - int run_hooks(const char *hook_name); 82 + int run_hooks(struct repository *r, const char *hook_name); 80 83 81 84 /** 82 85 * Like run_hooks(), a wrapper for run_hooks_opt(). ··· 87 90 * hook. This function behaves like the old run_hook_le() API. 88 91 */ 89 92 LAST_ARG_MUST_BE_NULL 90 - int run_hooks_l(const char *hook_name, ...); 93 + int run_hooks_l(struct repository *r, const char *hook_name, ...); 91 94 #endif
+3 -3
read-cache.c
··· 3156 3156 else 3157 3157 ret = close_lock_file_gently(lock); 3158 3158 3159 - run_hooks_l("post-index-change", 3160 - istate->updated_workdir ? "1" : "0", 3161 - istate->updated_skipworktree ? "1" : "0", NULL); 3159 + run_hooks_l(the_repository, "post-index-change", 3160 + istate->updated_workdir ? "1" : "0", 3161 + istate->updated_skipworktree ? "1" : "0", NULL); 3162 3162 istate->updated_workdir = 0; 3163 3163 istate->updated_skipworktree = 0; 3164 3164
+1 -1
refs.c
··· 2132 2132 const char *hook; 2133 2133 int ret = 0, i; 2134 2134 2135 - hook = find_hook("reference-transaction"); 2135 + hook = find_hook(transaction->ref_store->repo, "reference-transaction"); 2136 2136 if (!hook) 2137 2137 return ret; 2138 2138
+1 -1
reset.c
··· 79 79 reflog_head); 80 80 } 81 81 if (!ret && run_hook) 82 - run_hooks_l("post-checkout", 82 + run_hooks_l(the_repository, "post-checkout", 83 83 oid_to_hex(head ? head : null_oid()), 84 84 oid_to_hex(oid), "1", NULL); 85 85 strbuf_release(&msg);
+3 -3
sequencer.c
··· 1316 1316 struct child_process proc = CHILD_PROCESS_INIT; 1317 1317 int code; 1318 1318 struct strbuf sb = STRBUF_INIT; 1319 - const char *hook_path = find_hook("post-rewrite"); 1319 + const char *hook_path = find_hook(the_repository, "post-rewrite"); 1320 1320 1321 1321 if (!hook_path) 1322 1322 return 0; ··· 1614 1614 } 1615 1615 } 1616 1616 1617 - if (hook_exists("prepare-commit-msg")) { 1617 + if (hook_exists(r, "prepare-commit-msg")) { 1618 1618 res = run_prepare_commit_msg_hook(r, msg, hook_commit); 1619 1619 if (res) 1620 1620 goto out; ··· 5149 5149 5150 5150 hook_opt.path_to_stdin = rebase_path_rewritten_list(); 5151 5151 strvec_push(&hook_opt.args, "rebase"); 5152 - run_hooks_opt("post-rewrite", &hook_opt); 5152 + run_hooks_opt(r, "post-rewrite", &hook_opt); 5153 5153 } 5154 5154 apply_autostash(rebase_path_autostash()); 5155 5155
+1 -1
transport.c
··· 1271 1271 struct ref *r; 1272 1272 struct child_process proc = CHILD_PROCESS_INIT; 1273 1273 struct strbuf buf; 1274 - const char *hook_path = find_hook("pre-push"); 1274 + const char *hook_path = find_hook(the_repository, "pre-push"); 1275 1275 1276 1276 if (!hook_path) 1277 1277 return 0;