git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 06/10] run-command: allow capturing of collated output

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 25, 2025, 21:52 UTC
Message-ID
<xmqqplbedwtg.fsf@gitster.g>
In-Reply-To
<20250925125352.1728840-7-adrian.ratiu@collabora.com>
Adrian Ratiu <adrian.ratiu@collabora.com> writes:
Show 40 quoted lines
> From: Emily Shaffer <emilyshaffer@google.com>
>
> Some callers, for example server-side hooks which wish to relay hook
> output to clients across a transport, want to capture what would
> normally print to stderr and do something else with it. Allow that via a
> callback.
>
> By calling the callback regardless of whether there's output available,
> we allow clients to send e.g. a keepalive if necessary.
>
> Because we expose a strbuf, not a fd or FILE*, there's no need to create
> a temporary pipe or similar - we can just skip the print to stderr and
> instead hand it to the caller.
>
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
> ---
>  builtin/fetch.c             |  2 +-
>  builtin/submodule--helper.c |  2 +-
>  hook.c                      |  2 +-
>  run-command.c               | 33 ++++++++++++++++++++++++---------
>  run-command.h               | 22 +++++++++++++++++++++-
>  submodule.c                 |  2 +-
>  t/helper/test-run-command.c | 15 +++++++++++++++
>  t/t0061-run-command.sh      |  7 +++++++
>  8 files changed, 71 insertions(+), 14 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 24645c4653..53bd5552c4 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -2129,7 +2129,7 @@ static int fetch_multiple(struct string_list *list, int max_children,
>  
>  	if (max_children != 1 && list->nr != 1) {
>  		struct parallel_fetch_state state = { argv.v, list, 0, 0, config };
> -		const struct run_process_parallel_opts opts = {
> +		struct run_process_parallel_opts opts = {
>  			.tr2_category = "fetch",
>  			.tr2_label = "parallel/fetch",
This ...
Show 12 quoted lines
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 07a1935cbe..76cae9f015 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -2700,7 +2700,7 @@ static int update_submodules(struct update_data *update_data)
>  {
>  	int i, ret = 0;
>  	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
> -	const struct run_process_parallel_opts opts = {
> +	struct run_process_parallel_opts opts = {
>  		.tr2_category = "submodule",
>  		.tr2_label = "parallel/update",
... and this ...
Show 13 quoted lines
>  
> diff --git a/hook.c b/hook.c
> index 54568d5bc0..199c210b97 100644
> --- a/hook.c
> +++ b/hook.c
> @@ -135,7 +135,7 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
>  	};
>  	const char *const hook_path = find_hook(r, hook_name);
>  	int ret = 0;
> -	const struct run_process_parallel_opts opts = {
> +	struct run_process_parallel_opts opts = {
>  		.tr2_category = "hook",
>  		.tr2_label = hook_name,

... and this are curious changes that are not explained in the proposed log message.

Show 7 quoted lines
> @@ -1841,6 +1852,10 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
>  					   "max:%"PRIuMAX,
>  					   (uintmax_t)opts->processes);
>  
> +	/* ungroup and reading sideband are mutualy exclusive, so disable ungroup */
> +	If (opts->ungroup && opts->consume_sideband)
> +		opts->ungroup = 0;
Make it a BUG(""), which may help avoid unintended bugs, especially ...
Show 21 quoted lines
> diff --git a/run-command.h b/run-command.h
> index 4679987c8e..ad0bab14b0 100644
> --- a/run-command.h
> +++ b/run-command.h
> @@ -436,6 +436,20 @@ typedef int (*feed_pipe_fn)(int child_in,
>  				void *pp_cb,
>  				void *pp_task_cb);
>  
> +/**
> + * If this callback is provided, instead of collating process output to stderr,
> + * they will be collated into a new pipe. consume_sideband_fn will be called
> + * repeatedly. When output is available on that pipe, it will be contained in
> + * 'output'. But it will be called with an empty 'output' too, to allow for
> + * keepalives or similar operations if necessary.
> + *
> + * pp_cb is the callback cookie as passed into run_processes_parallel.
> + *
> + * Since this callback is provided with the collated output, no task cookie is
> + * provided.
> + */
> +typedef void (*consume_sideband_fn)(struct strbuf *output, void *pp_cb);
Show 13 quoted lines
> +
>  /**
>   * This callback is called on every child process that finished processing.
>   *
> @@ -495,6 +509,12 @@ struct run_process_parallel_opts
>  	 */
>  	feed_pipe_fn feed_pipe;
>  
> +	/*
> +	 * consume_sideband: see consume_sideband_fn() above. This can be NULL
> +	 * to omit any special handling.
> +	 */
> +	consume_sideband_fn consume_sideband;

... because which one between this and ungroup gets precedence. Document that they are mutually exclusive, and help the callers with a BUG("") message when both are set.

Show 6 quoted lines
> @@ -529,7 +549,7 @@ struct run_process_parallel_opts
>   * emitting their own output, including dealing with any race
>   * conditions due to writing in parallel to stdout and stderr.
>   */
> -void run_processes_parallel(const struct run_process_parallel_opts *opts);
> +void run_processes_parallel(struct run_process_parallel_opts *opts);
This is the same unexplained curiousity I touched earlier.
Thanks.
Previous: Adrian RatiuNext: Adrian Ratiu
Message 34 of 187 in “Convert remaining hooks to hook.h”
  1. 00/10 Convert remaining hooks to hook.hAdrian Ratiu, Sep 25, 2025
  2. 01/10 run-command: add stdin callback for parallelizationAdrian Ratiu, Sep 25, 2025
  3. Patrick SteinhardtOct 2, 2025
  4. Junio C HamanoOct 2, 2025
  5. Adrian RatiuOct 6, 2025
  6. Adrian RatiuOct 6, 2025
  7. Adrian RatiuOct 14, 2025
  8. 02/10 hook: provide stdin via callbackAdrian Ratiu, Sep 25, 2025
  9. Junio C HamanoSep 25, 2025
  10. Adrian RatiuSep 26, 2025
  11. Emily ShafferOct 10, 2025
  12. Adrian RatiuOct 13, 2025
  13. 03/10 hook: convert 'post-rewrite' hook in sequencer.c to hook.hAdrian Ratiu, Sep 25, 2025
  14. Junio C HamanoSep 25, 2025
  15. Adrian RatiuSep 26, 2025
  16. Phillip WoodSep 26, 2025
  17. Adrian RatiuSep 26, 2025
  18. Phillip WoodSep 29, 2025
  19. Junio C HamanoSep 26, 2025
  20. Adrian RatiuSep 29, 2025
  21. Patrick SteinhardtOct 2, 2025
  22. Adrian RatiuOct 8, 2025
  23. 04/10 transport: convert pre-push hook to hook.hAdrian Ratiu, Sep 25, 2025
  24. D. Ben KnobleSep 25, 2025
  25. Adrian RatiuSep 26, 2025
  26. Phillip WoodSep 26, 2025
  27. Adrian RatiuSep 29, 2025
  28. 05/10 reference-transaction: use hook.h to run hooksAdrian Ratiu, Sep 25, 2025
  29. Junio C HamanoSep 25, 2025
  30. Adrian RatiuSep 26, 2025
  31. Patrick SteinhardtOct 2, 2025
  32. Adrian RatiuOct 8, 2025
  33. 06/10 run-command: allow capturing of collated outputAdrian Ratiu, Sep 25, 2025
  34. Junio C HamanoSep 25, 2025
  35. Adrian RatiuSep 26, 2025
  36. 07/10 hooks: allow callers to capture outputAdrian Ratiu, Sep 25, 2025
  37. 08/10 receive-pack: convert 'update' hook to hook.hAdrian Ratiu, Sep 25, 2025
  38. Junio C HamanoSep 25, 2025
  39. Emily ShafferOct 10, 2025
  40. Adrian RatiuOct 17, 2025
  41. 09/10 post-update: use hook.h libraryAdrian Ratiu, Sep 25, 2025
  42. 10/10 receive-pack: convert receive hooks to hook.hAdrian Ratiu, Sep 25, 2025
  43. Emily ShafferOct 10, 2025
  44. 00/10 Convert remaining hooks to hook.hAdrian Ratiu, Oct 17, 2025
  45. 01/10 run-command: add stdin callback for parallelizationAdrian Ratiu, Oct 17, 2025
  46. Patrick SteinhardtOct 21, 2025
  47. 02/10 hook: provide stdin via callbackAdrian Ratiu, Oct 17, 2025
  48. Patrick SteinhardtOct 21, 2025
  49. Patrick SteinhardtOct 21, 2025
  50. Adrian RatiuOct 21, 2025
  51. 03/10 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Oct 17, 2025
  52. Patrick SteinhardtOct 21, 2025
  53. Adrian RatiuOct 21, 2025
  54. 04/10 transport: convert pre-push to hook APIAdrian Ratiu, Oct 17, 2025
  55. Patrick SteinhardtOct 21, 2025
  56. Adrian RatiuOct 21, 2025
  57. 06/10 hook: allow overriding the ungroup optionAdrian Ratiu, Oct 17, 2025
  58. 05/10 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Oct 17, 2025
  59. 07/10 run-command: allow capturing of collated outputAdrian Ratiu, Oct 17, 2025
  60. Patrick SteinhardtOct 21, 2025
  61. Adrian RatiuOct 21, 2025
  62. 08/10 hooks: allow callers to capture outputAdrian Ratiu, Oct 17, 2025
  63. 09/10 receive-pack: convert update hooks to new APIAdrian Ratiu, Oct 17, 2025
  64. Kristoffer HaugsbakkOct 28, 2025
  65. 10/10 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Oct 17, 2025
  66. Patrick SteinhardtOct 21, 2025
  67. Kristoffer HaugsbakkOct 28, 2025
  68. Adrian RatiuOct 29, 2025
  69. Kristoffer HaugsbakkOct 29, 2025
  70. Junio C HamanoNov 15, 2025
  71. Adrian RatiuNov 17, 2025
  72. Patrick SteinhardtOct 21, 2025
  73. Adrian RatiuOct 21, 2025
  74. 00/10 Convert remaining hooks to hook.hAdrian Ratiu, Nov 24, 2025
  75. 01/10 run-command: add stdin callback for parallelizationAdrian Ratiu, Nov 24, 2025
  76. Junio C HamanoNov 25, 2025
  77. Adrian RatiuNov 27, 2025
  78. 02/10 hook: provide stdin via callbackAdrian Ratiu, Nov 24, 2025
  79. Adrian RatiuNov 29, 2025
  80. Junio C HamanoNov 29, 2025
  81. Adrian RatiuDec 1, 2025
  82. 03/10 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Nov 24, 2025
  83. 04/10 transport: convert pre-push to hook APIAdrian Ratiu, Nov 24, 2025
  84. Junio C HamanoNov 24, 2025
  85. Adrian RatiuNov 27, 2025
  86. 05/10 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Nov 24, 2025
  87. 06/10 hook: allow overriding the ungroup optionAdrian Ratiu, Nov 24, 2025
  88. 09/10 receive-pack: convert update hooks to new APIAdrian Ratiu, Nov 24, 2025
  89. 08/10 hooks: allow callers to capture outputAdrian Ratiu, Nov 24, 2025
  90. 07/10 run-command: allow capturing of collated outputAdrian Ratiu, Nov 24, 2025
  91. 10/10 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Nov 24, 2025
  92. 00/11 Convert remaining hooks to hook.hAdrian Ratiu, Dec 4, 2025
  93. 01/11 run-command: add first helper for pp child statesAdrian Ratiu, Dec 4, 2025
  94. 03/11 hook: provide stdin via callbackAdrian Ratiu, Dec 4, 2025
  95. Patrick SteinhardtDec 16, 2025
  96. 02/11 run-command: add stdin callback for parallelizationAdrian Ratiu, Dec 4, 2025
  97. 04/11 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Dec 4, 2025
  98. 05/11 transport: convert pre-push to hook APIAdrian Ratiu, Dec 4, 2025
  99. Patrick SteinhardtDec 16, 2025
  100. Adrian RatiuDec 16, 2025
  101. Patrick SteinhardtDec 16, 2025
  102. Junio C HamanoDec 17, 2025
  103. 07/11 hook: allow overriding the ungroup optionAdrian Ratiu, Dec 4, 2025
  104. 06/11 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Dec 4, 2025
  105. 08/11 run-command: allow capturing of collated outputAdrian Ratiu, Dec 4, 2025
  106. 09/11 hooks: allow callers to capture outputAdrian Ratiu, Dec 4, 2025
  107. 10/11 receive-pack: convert update hooks to new APIAdrian Ratiu, Dec 4, 2025
  108. Patrick SteinhardtDec 16, 2025
  109. Adrian RatiuDec 16, 2025
  110. 11/11 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Dec 4, 2025
  111. 00/11 Convert remaining hooks to hook.hAdrian Ratiu, Dec 18, 2025
  112. 01/11 run-command: add first helper for pp child statesAdrian Ratiu, Dec 18, 2025
  113. 02/11 run-command: add stdin callback for parallelizationAdrian Ratiu, Dec 18, 2025
  114. 03/11 hook: provide stdin via callbackAdrian Ratiu, Dec 18, 2025
  115. 04/11 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Dec 18, 2025
  116. 05/11 transport: convert pre-push to hook APIAdrian Ratiu, Dec 18, 2025
  117. 06/11 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Dec 18, 2025
  118. 07/11 hook: allow overriding the ungroup optionAdrian Ratiu, Dec 18, 2025
  119. 08/11 run-command: allow capturing of collated outputAdrian Ratiu, Dec 18, 2025
  120. 09/11 hooks: allow callers to capture outputAdrian Ratiu, Dec 18, 2025
  121. 10/11 receive-pack: convert update hooks to new APIAdrian Ratiu, Dec 18, 2025
  122. 11/11 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Dec 18, 2025
  123. Patrick SteinhardtDec 19, 2025
  124. Adrian RatiuDec 20, 2025
  125. 00/11 Convert remaining hooks to hook.hAdrian Ratiu, Dec 26, 2025
  126. 01/11 run-command: add first helper for pp child statesAdrian Ratiu, Dec 26, 2025
  127. 02/11 run-command: add stdin callback for parallelizationAdrian Ratiu, Dec 26, 2025
  128. 03/11 hook: provide stdin via callbackAdrian Ratiu, Dec 26, 2025
  129. 04/11 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Dec 26, 2025
  130. 05/11 transport: convert pre-push to hook APIAdrian Ratiu, Dec 26, 2025
  131. 06/11 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Dec 26, 2025
  132. SZEDER GáborJan 18, 2026
  133. Adrian RatiuJan 18, 2026
  134. 07/11 hook: allow overriding the ungroup optionAdrian Ratiu, Dec 26, 2025
  135. 08/11 run-command: allow capturing of collated outputAdrian Ratiu, Dec 26, 2025
  136. 09/11 hooks: allow callers to capture outputAdrian Ratiu, Dec 26, 2025
  137. 10/11 receive-pack: convert update hooks to new APIAdrian Ratiu, Dec 26, 2025
  138. 11/11 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Dec 26, 2025
  139. Junio C HamanoDec 28, 2025
  140. Adrian RatiuJan 5, 2026
  141. Patrick SteinhardtJan 5, 2026
  142. 00/12 Convert remaining hooks to hook.hAdrian Ratiu, Jan 21, 2026
  143. 01/12 t1800: add hook output stream testsAdrian Ratiu, Jan 21, 2026
  144. Junio C HamanoJan 21, 2026
  145. Adrian RatiuJan 22, 2026
  146. 02/12 run-command: add first helper for pp child statesAdrian Ratiu, Jan 21, 2026
  147. Junio C HamanoJan 21, 2026
  148. Adrian RatiuJan 22, 2026
  149. 03/12 run-command: add stdin callback for parallelizationAdrian Ratiu, Jan 21, 2026
  150. 05/12 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Jan 21, 2026
  151. 04/12 hook: provide stdin via callbackAdrian Ratiu, Jan 21, 2026
  152. 07/12 transport: convert pre-push to hook APIAdrian Ratiu, Jan 21, 2026
  153. 08/12 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Jan 21, 2026
  154. 09/12 hook: add jobs optionAdrian Ratiu, Jan 21, 2026
  155. 10/12 run-command: poll child stdin in addition to stdoutAdrian Ratiu, Jan 21, 2026
  156. Kristoffer HaugsbakkJan 21, 2026
  157. Adrian RatiuJan 22, 2026
  158. Junio C HamanoJan 21, 2026
  159. Adrian RatiuJan 22, 2026
  160. Junio C HamanoJan 22, 2026
  161. Emily ShafferJan 26, 2026
  162. Junio C HamanoJan 27, 2026
  163. Adrian RatiuJan 27, 2026
  164. 11/12 receive-pack: convert update hooks to new APIAdrian Ratiu, Jan 21, 2026
  165. Kristoffer HaugsbakkJan 21, 2026
  166. Adrian RatiuJan 22, 2026
  167. Emily ShafferJan 27, 2026
  168. Adrian RatiuJan 27, 2026
  169. 12/12 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Jan 21, 2026
  170. 06/12 hook: allow separate std[out|err] streamsAdrian Ratiu, Jan 21, 2026
  171. Patrick SteinhardtJan 23, 2026
  172. Adrian RatiuJan 23, 2026
  173. 00/12 Convert remaining hooks to hook.hAdrian Ratiu, Jan 28, 2026
  174. 01/12 t1800: add hook output stream testsAdrian Ratiu, Jan 28, 2026
  175. 02/12 run-command: add helper for pp child statesAdrian Ratiu, Jan 28, 2026
  176. 03/12 run-command: add stdin callback for parallelizationAdrian Ratiu, Jan 28, 2026
  177. 05/12 hook: convert 'post-rewrite' hook in sequencer.c to hook APIAdrian Ratiu, Jan 28, 2026
  178. 04/12 hook: provide stdin via callbackAdrian Ratiu, Jan 28, 2026
  179. 07/12 transport: convert pre-push to hook APIAdrian Ratiu, Jan 28, 2026
  180. 09/12 hook: add jobs optionAdrian Ratiu, Jan 28, 2026
  181. 08/12 reference-transaction: use hook API instead of run-commandAdrian Ratiu, Jan 28, 2026
  182. 10/12 run-command: poll child input in addition to outputAdrian Ratiu, Jan 28, 2026
  183. 06/12 hook: allow separate std[out|err] streamsAdrian Ratiu, Jan 28, 2026
  184. Chris DarrochFeb 2, 2026
  185. Junio C HamanoFeb 2, 2026
  186. 11/12 receive-pack: convert update hooks to new APIAdrian Ratiu, Jan 28, 2026
  187. 12/12 receive-pack: convert receive hooks to hook APIAdrian Ratiu, Jan 28, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.