]> git.ipfire.org Git - thirdparty/git.git/commitdiff
hook: allow overriding the ungroup option
authorAdrian Ratiu <adrian.ratiu@collabora.com>
Thu, 18 Dec 2025 17:11:21 +0000 (19:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Dec 2025 04:46:26 +0000 (13:46 +0900)
When calling run_process_parallel() in run_hooks_opt(), the
ungroup option is currently hardcoded to .ungroup = 1.

This causes problems when ungrouping should be disabled, for
example when sideband-reading collated output from child hooks,
because sideband-reading and ungrouping are mutually exclusive.

Thus a new hook.h option is added to allow overriding.

The existing ungroup=1 behavior is preserved in the run_hooks()
API and the "hook run" command. We could modify these to take
an option if necessary, so I added two code comments there.

Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/hook.c
commit.c
hook.c
hook.h

index 7afec380d2e579d0b704434144aaf21bdfcb030c..73e7b8c2e878eb134006cd34fbdb15053b465eb3 100644 (file)
@@ -43,6 +43,12 @@ static int run(int argc, const char **argv, const char *prefix,
        if (!argc)
                goto usage;
 
+       /*
+        * All current "hook run" use-cases require ungrouped child output.
+        * If this changes, a hook run argument can be added to toggle it.
+        */
+       opt.ungroup = 1;
+
        /*
         * Having a -- for "run" when providing <hook-args> is
         * mandatory.
index 16d91b2bfcf291b876e1edb5ea54520edad21c0c..7da33dde86337b2c16d5f9ff843d5ce92080f82d 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -1965,6 +1965,9 @@ int run_commit_hook(int editor_is_used, const char *index_file,
                strvec_push(&opt.args, arg);
        va_end(args);
 
+       /* All commit hook use-cases require ungrouping child output. */
+       opt.ungroup = 1;
+
        opt.invoked_hook = invoked_hook;
        return run_hooks_opt(the_repository, name, &opt);
 }
diff --git a/hook.c b/hook.c
index 5ddd7678d18f0d17437ae99d465b64ce8f3ef5c6..00a1e2ad22a9d77daa4c221bd5d21105e85c2ed7 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -153,7 +153,7 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
                .tr2_label = hook_name,
 
                .processes = 1,
-               .ungroup = 1,
+               .ungroup = options->ungroup,
 
                .get_next_task = pick_next_hook,
                .start_failure = notify_start_failure,
@@ -198,6 +198,9 @@ int run_hooks(struct repository *r, const char *hook_name)
 {
        struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
 
+       /* All use-cases of this API require ungrouping. */
+       opt.ungroup = 1;
+
        return run_hooks_opt(r, hook_name, &opt);
 }
 
diff --git a/hook.h b/hook.h
index 2169d4a6bd3f2eb02e307db6f7b108efce5a494e..78a1a44690ef34a682d9555f8ab7ccaed50e87aa 100644 (file)
--- a/hook.h
+++ b/hook.h
@@ -34,6 +34,11 @@ struct run_hooks_opt
         */
        int *invoked_hook;
 
+       /**
+        * Allow hooks to set run_processes_parallel() 'ungroup' behavior.
+        */
+       unsigned int ungroup:1;
+
        /**
         * Path to file which should be piped to stdin for each hook.
         */