Re: [PATCH v3 05/13] hooks: convert 'post-checkout' hook to hook library
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 29, 2021, 05:55 UTC
- Message-ID
- <xmqqfsskml2r.fsf@gitster.g>
- In-Reply-To
- <patch-v3-05.13-2a747a65829-20211019T231647Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 29 quoted lines
> if (!ret && opts->checkout) {
> - const char *hook = find_hook("post-checkout");
> - if (hook) {
> - const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL };
> - cp.git_cmd = 0;
> - cp.no_stdin = 1;
> - cp.stdout_to_stderr = 1;
> - cp.dir = path;
> - cp.env = env;
> - cp.argv = NULL;
> - cp.trace2_hook_name = "post-checkout";
> - strvec_pushl(&cp.args, absolute_path(hook),
> - oid_to_hex(null_oid()),
> - oid_to_hex(&commit->object.oid),
> - "1", NULL);
> - ret = run_command(&cp);
> - }
> + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
> +
> + strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL);
> + strvec_pushl(&opt.args,
> + oid_to_hex(null_oid()),
> + oid_to_hex(&commit->object.oid),
> + "1",
> + NULL);
> + opt.dir = path;
> + opt.absolute_path = 1;
> +
> + ret = run_hooks_oneshot("post-checkout", &opt);I can see how passing opt from the caller gives more flexibility like allowing to pass arbitrary environments. The interface still looks a bit unwieldy as I expect passing command line args would be a much more common need than tweaking the environment, but let's keep reading.