@@ -139,11 +139,25 @@ static struct command *commands;
139
139
static const char pre_receive_hook [] = "hooks/pre-receive" ;
140
140
static const char post_receive_hook [] = "hooks/post-receive" ;
141
141
142
+ static int copy_to_sideband (int in , int out , void * arg )
143
+ {
144
+ char data [128 ];
145
+ while (1 ) {
146
+ ssize_t sz = xread (in , data , sizeof (data ));
147
+ if (sz <= 0 )
148
+ break ;
149
+ send_sideband (1 , 2 , data , sz , use_sideband );
150
+ }
151
+ close (in );
152
+ return 0 ;
153
+ }
154
+
142
155
static int run_receive_hook (const char * hook_name )
143
156
{
144
157
static char buf [sizeof (commands -> old_sha1 ) * 2 + PATH_MAX + 4 ];
145
158
struct command * cmd ;
146
159
struct child_process proc ;
160
+ struct async muxer ;
147
161
const char * argv [2 ];
148
162
int have_input = 0 , code ;
149
163
@@ -163,9 +177,23 @@ static int run_receive_hook(const char *hook_name)
163
177
proc .in = -1 ;
164
178
proc .stdout_to_stderr = 1 ;
165
179
180
+ if (use_sideband ) {
181
+ memset (& muxer , 0 , sizeof (muxer ));
182
+ muxer .proc = copy_to_sideband ;
183
+ muxer .in = -1 ;
184
+ code = start_async (& muxer );
185
+ if (code )
186
+ return code ;
187
+ proc .err = muxer .in ;
188
+ }
189
+
166
190
code = start_command (& proc );
167
- if (code )
191
+ if (code ) {
192
+ if (use_sideband )
193
+ finish_async (& muxer );
168
194
return code ;
195
+ }
196
+
169
197
for (cmd = commands ; cmd ; cmd = cmd -> next ) {
170
198
if (!cmd -> error_string ) {
171
199
size_t n = snprintf (buf , sizeof (buf ), "%s %s %s\n" ,
@@ -177,13 +205,17 @@ static int run_receive_hook(const char *hook_name)
177
205
}
178
206
}
179
207
close (proc .in );
208
+ if (use_sideband )
209
+ finish_async (& muxer );
180
210
return finish_command (& proc );
181
211
}
182
212
183
213
static int run_update_hook (struct command * cmd )
184
214
{
185
215
static const char update_hook [] = "hooks/update" ;
186
216
const char * argv [5 ];
217
+ struct child_process proc ;
218
+ int code ;
187
219
188
220
if (access (update_hook , X_OK ) < 0 )
189
221
return 0 ;
@@ -194,8 +226,18 @@ static int run_update_hook(struct command *cmd)
194
226
argv [3 ] = sha1_to_hex (cmd -> new_sha1 );
195
227
argv [4 ] = NULL ;
196
228
197
- return run_command_v_opt (argv , RUN_COMMAND_NO_STDIN |
198
- RUN_COMMAND_STDOUT_TO_STDERR );
229
+ memset (& proc , 0 , sizeof (proc ));
230
+ proc .no_stdin = 1 ;
231
+ proc .stdout_to_stderr = 1 ;
232
+ proc .err = use_sideband ? -1 : 0 ;
233
+ proc .argv = argv ;
234
+
235
+ code = start_command (& proc );
236
+ if (code )
237
+ return code ;
238
+ if (use_sideband )
239
+ copy_to_sideband (proc .err , -1 , NULL );
240
+ return finish_command (& proc );
199
241
}
200
242
201
243
static int is_ref_checked_out (const char * ref )
@@ -384,8 +426,9 @@ static char update_post_hook[] = "hooks/post-update";
384
426
static void run_update_post_hook (struct command * cmd )
385
427
{
386
428
struct command * cmd_p ;
387
- int argc , status ;
429
+ int argc ;
388
430
const char * * argv ;
431
+ struct child_process proc ;
389
432
390
433
for (argc = 0 , cmd_p = cmd ; cmd_p ; cmd_p = cmd_p -> next ) {
391
434
if (cmd_p -> error_string )
@@ -407,8 +450,18 @@ static void run_update_post_hook(struct command *cmd)
407
450
argc ++ ;
408
451
}
409
452
argv [argc ] = NULL ;
410
- status = run_command_v_opt (argv , RUN_COMMAND_NO_STDIN
411
- | RUN_COMMAND_STDOUT_TO_STDERR );
453
+
454
+ memset (& proc , 0 , sizeof (proc ));
455
+ proc .no_stdin = 1 ;
456
+ proc .stdout_to_stderr = 1 ;
457
+ proc .err = use_sideband ? -1 : 0 ;
458
+ proc .argv = argv ;
459
+
460
+ if (!start_command (& proc )) {
461
+ if (use_sideband )
462
+ copy_to_sideband (proc .err , -1 , NULL );
463
+ finish_command (& proc );
464
+ }
412
465
}
413
466
414
467
static void execute_commands (const char * unpacker_error )
0 commit comments