@@ -1316,65 +1316,56 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
13161316 die (_ ("Aborting." ));
13171317}
13181318
1319- static int run_pre_push_hook (struct transport * transport ,
1320- struct ref * remote_refs )
1319+ static int pre_push_hook_feed_stdin (int hook_stdin_fd , void * pp_cb , void * pp_task_cb UNUSED )
13211320{
1322- int ret = 0 , x ;
1323- struct ref * r ;
1324- struct child_process proc = CHILD_PROCESS_INIT ;
1325- struct strbuf buf ;
1326- const char * hook_path = find_hook (the_repository , "pre-push" );
1321+ struct hook_cb_data * hook_cb = pp_cb ;
1322+ struct ref * r = hook_cb -> options -> feed_pipe_ctx ;
1323+ struct strbuf * buf = hook_cb -> options -> feed_pipe_cb_data ;
1324+ int ret = 0 ;
13271325
1328- if (!hook_path )
1329- return 0 ;
1326+ if (!r )
1327+ return 1 ; /* no more refs */
13301328
1331- strvec_push (& proc .args , hook_path );
1332- strvec_push (& proc .args , transport -> remote -> name );
1333- strvec_push (& proc .args , transport -> url );
1329+ if (!buf )
1330+ BUG ("pipe_task_cb must contain a valid strbuf" );
13341331
1335- proc . in = -1 ;
1336- proc . trace2_hook_name = "pre-push" ;
1332+ hook_cb -> options -> feed_pipe_ctx = r -> next ;
1333+ strbuf_reset ( buf ) ;
13371334
1338- if (start_command (& proc )) {
1339- finish_command (& proc );
1340- return -1 ;
1341- }
1342-
1343- sigchain_push (SIGPIPE , SIG_IGN );
1335+ if (!r -> peer_ref ) return 0 ;
1336+ if (r -> status == REF_STATUS_REJECT_NONFASTFORWARD ) return 0 ;
1337+ if (r -> status == REF_STATUS_REJECT_STALE ) return 0 ;
1338+ if (r -> status == REF_STATUS_REJECT_REMOTE_UPDATED ) return 0 ;
1339+ if (r -> status == REF_STATUS_UPTODATE ) return 0 ;
13441340
1345- strbuf_init (& buf , 256 );
1341+ strbuf_addf (buf , "%s %s %s %s\n" ,
1342+ r -> peer_ref -> name , oid_to_hex (& r -> new_oid ),
1343+ r -> name , oid_to_hex (& r -> old_oid ));
13461344
1347- for (r = remote_refs ; r ; r = r -> next ) {
1348- if (!r -> peer_ref ) continue ;
1349- if (r -> status == REF_STATUS_REJECT_NONFASTFORWARD ) continue ;
1350- if (r -> status == REF_STATUS_REJECT_STALE ) continue ;
1351- if (r -> status == REF_STATUS_REJECT_REMOTE_UPDATED ) continue ;
1352- if (r -> status == REF_STATUS_UPTODATE ) continue ;
1345+ ret = write_in_full (hook_stdin_fd , buf -> buf , buf -> len );
1346+ if (ret < 0 && errno != EPIPE )
1347+ return ret ; /* We do not mind if a hook does not read all refs. */
13531348
1354- strbuf_reset (& buf );
1355- strbuf_addf ( & buf , "%s %s %s %s\n" ,
1356- r -> peer_ref -> name , oid_to_hex (& r -> new_oid ),
1357- r -> name , oid_to_hex (& r -> old_oid ));
1349+ return 0 ;
1350+ }
13581351
1359- if (write_in_full (proc .in , buf .buf , buf .len ) < 0 ) {
1360- /* We do not mind if a hook does not read all refs. */
1361- if (errno != EPIPE )
1362- ret = -1 ;
1363- break ;
1364- }
1365- }
1352+ static int run_pre_push_hook (struct transport * transport ,
1353+ struct ref * remote_refs )
1354+ {
1355+ struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT ;
1356+ struct strbuf buf = STRBUF_INIT ;
1357+ int ret = 0 ;
13661358
1367- strbuf_release (& buf );
1359+ strvec_push (& opt .args , transport -> remote -> name );
1360+ strvec_push (& opt .args , transport -> url );
13681361
1369- x = close ( proc . in ) ;
1370- if (! ret )
1371- ret = x ;
1362+ opt . feed_pipe = pre_push_hook_feed_stdin ;
1363+ opt . feed_pipe_ctx = remote_refs ;
1364+ opt . feed_pipe_cb_data = & buf ;
13721365
1373- sigchain_pop ( SIGPIPE );
1366+ ret = run_hooks_opt ( the_repository , "pre-push" , & opt );
13741367
1375- x = finish_command (& proc );
1376- if (!ret )
1377- ret = x ;
1368+ strbuf_release (& buf );
13781369
13791370 return ret ;
13801371}
0 commit comments