hooks: convert non-worktree 'post-checkout' hook to hook library

Move the running of the 'post-checkout' hook away from run-command.h to the new hook.h library, except in the case of builtin/worktree.c. That special-case will be handled in a subsequent commit. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Emily Shaffer committed Dec 22, 2021 at 04:59 UTC 72ddf34d7c62a0b272d5cdd8f62fcfc782bb3a45
3 files changed +6 -3
builtin/checkout.c
+2 -1
@@ -9,6 +9,7 @@
9 #include "config.h"
10 #include "diff.h"
11 #include "dir.h"
12 +#include "hook.h"
13 #include "ll-merge.h"
14 #include "lockfile.h"
15 #include "merge-recursive.h"
@@ -114,7 +115,7 @@ static void branch_info_release(struct branch_info *info)
115 static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit,
116 int changed)
117 {
117 - return run_hook_le(NULL, "post-checkout",
118 + return run_hooks_l("post-checkout",
119 oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
120 oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
121 changed ? "1" : "0", NULL);
builtin/clone.c
+2 -1
@@ -32,6 +32,7 @@
32 #include "connected.h"
33 #include "packfile.h"
34 #include "list-objects-filter-options.h"
35 +#include "hook.h"
36
37 /*
38 * Overall FIXMEs:
@@ -705,7 +706,7 @@ static int checkout(int submodule_progress)
706 if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
707 die(_("unable to write new index file"));
708
708 - err |= run_hook_le(NULL, "post-checkout", oid_to_hex(null_oid()),
709 + err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()),
710 oid_to_hex(&oid), "1", NULL);
711
712 if (!err && (option_recurse_submodules.nr > 0)) {
reset.c
+2 -1
@@ -7,6 +7,7 @@
7 #include "tree-walk.h"
8 #include "tree.h"
9 #include "unpack-trees.h"
10 +#include "hook.h"
11
12 int reset_head(struct repository *r, struct object_id *oid, const char *action,
13 const char *switch_to_branch, unsigned flags,
@@ -127,7 +128,7 @@ reset_head_refs:
128 reflog_head);
129 }
130 if (run_hook)
130 - run_hook_le(NULL, "post-checkout",
131 + run_hooks_l("post-checkout",
132 oid_to_hex(orig ? orig : null_oid()),
133 oid_to_hex(oid), "1", NULL);
134