@@ -456,7 +456,8 @@ static int is_our_ref(struct object *o)
456
456
* on successful case, it's up to the caller to close cmd->out
457
457
*/
458
458
static int do_reachable_revlist (struct child_process * cmd ,
459
- struct object_array * src )
459
+ struct object_array * src ,
460
+ struct object_array * reachable )
460
461
{
461
462
static const char * argv [] = {
462
463
"rev-list" , "--stdin" , NULL ,
@@ -487,6 +488,8 @@ static int do_reachable_revlist(struct child_process *cmd,
487
488
o = get_indexed_object (-- i );
488
489
if (!o )
489
490
continue ;
491
+ if (reachable && o -> type == OBJ_COMMIT )
492
+ o -> flags &= ~TMP_MARK ;
490
493
if (!is_our_ref (o ))
491
494
continue ;
492
495
memcpy (namebuf + 1 , oid_to_hex (& o -> oid ), GIT_SHA1_HEXSZ );
@@ -496,8 +499,13 @@ static int do_reachable_revlist(struct child_process *cmd,
496
499
namebuf [40 ] = '\n' ;
497
500
for (i = 0 ; i < src -> nr ; i ++ ) {
498
501
o = src -> objects [i ].item ;
499
- if (is_our_ref (o ))
502
+ if (is_our_ref (o )) {
503
+ if (reachable )
504
+ add_object_array (o , NULL , reachable );
500
505
continue ;
506
+ }
507
+ if (reachable && o -> type == OBJ_COMMIT )
508
+ o -> flags |= TMP_MARK ;
501
509
memcpy (namebuf , oid_to_hex (& o -> oid ), GIT_SHA1_HEXSZ );
502
510
if (write_in_full (cmd -> in , namebuf , 41 ) < 0 )
503
511
goto error ;
@@ -518,13 +526,51 @@ static int do_reachable_revlist(struct child_process *cmd,
518
526
return -1 ;
519
527
}
520
528
529
+ static int get_reachable_list (struct object_array * src ,
530
+ struct object_array * reachable )
531
+ {
532
+ struct child_process cmd = CHILD_PROCESS_INIT ;
533
+ int i ;
534
+ struct object * o ;
535
+ char namebuf [42 ]; /* ^ + SHA-1 + LF */
536
+
537
+ if (do_reachable_revlist (& cmd , src , reachable ) < 0 )
538
+ return -1 ;
539
+
540
+ while ((i = read_in_full (cmd .out , namebuf , 41 )) == 41 ) {
541
+ struct object_id sha1 ;
542
+
543
+ if (namebuf [40 ] != '\n' || get_oid_hex (namebuf , & sha1 ))
544
+ break ;
545
+
546
+ o = lookup_object (sha1 .hash );
547
+ if (o && o -> type == OBJ_COMMIT ) {
548
+ o -> flags &= ~TMP_MARK ;
549
+ }
550
+ }
551
+ for (i = get_max_object_index (); 0 < i ; i -- ) {
552
+ o = get_indexed_object (i - 1 );
553
+ if (o && o -> type == OBJ_COMMIT &&
554
+ (o -> flags & TMP_MARK )) {
555
+ add_object_array (o , NULL , reachable );
556
+ o -> flags &= ~TMP_MARK ;
557
+ }
558
+ }
559
+ close (cmd .out );
560
+
561
+ if (finish_command (& cmd ))
562
+ return -1 ;
563
+
564
+ return 0 ;
565
+ }
566
+
521
567
static int has_unreachable (struct object_array * src )
522
568
{
523
569
struct child_process cmd = CHILD_PROCESS_INIT ;
524
570
char buf [1 ];
525
571
int i ;
526
572
527
- if (do_reachable_revlist (& cmd , src ) < 0 )
573
+ if (do_reachable_revlist (& cmd , src , NULL ) < 0 )
528
574
return 1 ;
529
575
530
576
/*
0 commit comments