Skip to content

Commit 9151f05

Browse files
10ne1gitster
authored andcommitted
hook: allow overriding the ungroup option
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>
1 parent ccf5936 commit 9151f05

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

builtin/hook.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ static int run(int argc, const char **argv, const char *prefix,
4343
if (!argc)
4444
goto usage;
4545

46+
/*
47+
* All current "hook run" use-cases require ungrouped child output.
48+
* If this changes, a hook run argument can be added to toggle it.
49+
*/
50+
opt.ungroup = 1;
51+
4652
/*
4753
* Having a -- for "run" when providing <hook-args> is
4854
* mandatory.

commit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,9 @@ int run_commit_hook(int editor_is_used, const char *index_file,
19651965
strvec_push(&opt.args, arg);
19661966
va_end(args);
19671967

1968+
/* All commit hook use-cases require ungrouping child output. */
1969+
opt.ungroup = 1;
1970+
19681971
opt.invoked_hook = invoked_hook;
19691972
return run_hooks_opt(the_repository, name, &opt);
19701973
}

hook.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
147147
.tr2_label = hook_name,
148148

149149
.processes = 1,
150-
.ungroup = 1,
150+
.ungroup = options->ungroup,
151151

152152
.get_next_task = pick_next_hook,
153153
.start_failure = notify_start_failure,
@@ -192,6 +192,9 @@ int run_hooks(struct repository *r, const char *hook_name)
192192
{
193193
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
194194

195+
/* All use-cases of this API require ungrouping. */
196+
opt.ungroup = 1;
197+
195198
return run_hooks_opt(r, hook_name, &opt);
196199
}
197200

hook.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ struct run_hooks_opt
3434
*/
3535
int *invoked_hook;
3636

37+
/**
38+
* Allow hooks to set run_processes_parallel() 'ungroup' behavior.
39+
*/
40+
unsigned int ungroup:1;
41+
3742
/**
3843
* Path to file which should be piped to stdin for each hook.
3944
*/

0 commit comments

Comments
 (0)