@@ -452,21 +452,24 @@ static int is_our_ref(struct object *o)
452
452
return o -> flags & ((allow_hidden_ref ? HIDDEN_REF : 0 ) | OUR_REF );
453
453
}
454
454
455
- static int has_unreachable (struct object_array * src )
455
+ /*
456
+ * on successful case, it's up to the caller to close cmd->out
457
+ */
458
+ static int do_reachable_revlist (struct child_process * cmd ,
459
+ struct object_array * src )
456
460
{
457
461
static const char * argv [] = {
458
462
"rev-list" , "--stdin" , NULL ,
459
463
};
460
- static struct child_process cmd = CHILD_PROCESS_INIT ;
461
464
struct object * o ;
462
465
char namebuf [42 ]; /* ^ + SHA-1 + LF */
463
466
int i ;
464
467
465
- cmd . argv = argv ;
466
- cmd . git_cmd = 1 ;
467
- cmd . no_stderr = 1 ;
468
- cmd . in = -1 ;
469
- cmd . out = -1 ;
468
+ cmd -> argv = argv ;
469
+ cmd -> git_cmd = 1 ;
470
+ cmd -> no_stderr = 1 ;
471
+ cmd -> in = -1 ;
472
+ cmd -> out = -1 ;
470
473
471
474
/*
472
475
* If the next rev-list --stdin encounters an unknown commit,
@@ -475,7 +478,7 @@ static int has_unreachable(struct object_array *src)
475
478
*/
476
479
sigchain_push (SIGPIPE , SIG_IGN );
477
480
478
- if (start_command (& cmd ))
481
+ if (start_command (cmd ))
479
482
goto error ;
480
483
481
484
namebuf [0 ] = '^' ;
@@ -487,7 +490,7 @@ static int has_unreachable(struct object_array *src)
487
490
if (!is_our_ref (o ))
488
491
continue ;
489
492
memcpy (namebuf + 1 , oid_to_hex (& o -> oid ), GIT_SHA1_HEXSZ );
490
- if (write_in_full (cmd . in , namebuf , 42 ) < 0 )
493
+ if (write_in_full (cmd -> in , namebuf , 42 ) < 0 )
491
494
goto error ;
492
495
}
493
496
namebuf [40 ] = '\n' ;
@@ -496,17 +499,39 @@ static int has_unreachable(struct object_array *src)
496
499
if (is_our_ref (o ))
497
500
continue ;
498
501
memcpy (namebuf , oid_to_hex (& o -> oid ), GIT_SHA1_HEXSZ );
499
- if (write_in_full (cmd . in , namebuf , 41 ) < 0 )
502
+ if (write_in_full (cmd -> in , namebuf , 41 ) < 0 )
500
503
goto error ;
501
504
}
502
- close (cmd .in );
503
- cmd .in = -1 ;
505
+ close (cmd -> in );
506
+ cmd -> in = -1 ;
507
+ sigchain_pop (SIGPIPE );
508
+
509
+ return 0 ;
510
+
511
+ error :
512
+ sigchain_pop (SIGPIPE );
513
+
514
+ if (cmd -> in >= 0 )
515
+ close (cmd -> in );
516
+ if (cmd -> out >= 0 )
517
+ close (cmd -> out );
518
+ return -1 ;
519
+ }
520
+
521
+ static int has_unreachable (struct object_array * src )
522
+ {
523
+ struct child_process cmd = CHILD_PROCESS_INIT ;
524
+ char buf [1 ];
525
+ int i ;
526
+
527
+ if (do_reachable_revlist (& cmd , src ) < 0 )
528
+ return 1 ;
504
529
505
530
/*
506
531
* The commits out of the rev-list are not ancestors of
507
532
* our ref.
508
533
*/
509
- i = read_in_full (cmd .out , namebuf , 1 );
534
+ i = read_in_full (cmd .out , buf , 1 );
510
535
if (i )
511
536
goto error ;
512
537
close (cmd .out );
@@ -520,16 +545,11 @@ static int has_unreachable(struct object_array *src)
520
545
if (finish_command (& cmd ))
521
546
goto error ;
522
547
523
- sigchain_pop (SIGPIPE );
524
-
525
548
/* All the non-tip ones are ancestors of what we advertised */
526
549
return 0 ;
527
550
528
551
error :
529
552
sigchain_pop (SIGPIPE );
530
-
531
- if (cmd .in >= 0 )
532
- close (cmd .in );
533
553
if (cmd .out >= 0 )
534
554
close (cmd .out );
535
555
return 1 ;
0 commit comments