@@ -412,10 +412,26 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
412
412
commit -> object .flags |= TREESAME ;
413
413
}
414
414
415
- static int add_parents_to_list (struct rev_info * revs , struct commit * commit , struct commit_list * * list )
415
+ static void insert_by_date_cached (struct commit * p , struct commit_list * * head ,
416
+ struct commit_list * cached_base , struct commit_list * * cache )
417
+ {
418
+ struct commit_list * new_entry ;
419
+
420
+ if (cached_base && p -> date < cached_base -> item -> date )
421
+ new_entry = insert_by_date (p , & cached_base -> next );
422
+ else
423
+ new_entry = insert_by_date (p , head );
424
+
425
+ if (cache && (!* cache || p -> date < (* cache )-> item -> date ))
426
+ * cache = new_entry ;
427
+ }
428
+
429
+ static int add_parents_to_list (struct rev_info * revs , struct commit * commit ,
430
+ struct commit_list * * list , struct commit_list * * cache_ptr )
416
431
{
417
432
struct commit_list * parent = commit -> parents ;
418
433
unsigned left_flag ;
434
+ struct commit_list * cached_base = cache_ptr ? * cache_ptr : NULL ;
419
435
420
436
if (commit -> object .flags & ADDED )
421
437
return 0 ;
@@ -445,7 +461,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
445
461
if (p -> object .flags & SEEN )
446
462
continue ;
447
463
p -> object .flags |= SEEN ;
448
- insert_by_date (p , list );
464
+ insert_by_date_cached (p , list , cached_base , cache_ptr );
449
465
}
450
466
return 0 ;
451
467
}
@@ -470,7 +486,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
470
486
p -> object .flags |= left_flag ;
471
487
if (!(p -> object .flags & SEEN )) {
472
488
p -> object .flags |= SEEN ;
473
- insert_by_date (p , list );
489
+ insert_by_date_cached (p , list , cached_base , cache_ptr );
474
490
}
475
491
if (revs -> first_parent_only )
476
492
break ;
@@ -611,7 +627,7 @@ static int limit_list(struct rev_info *revs)
611
627
612
628
if (revs -> max_age != -1 && (commit -> date < revs -> max_age ))
613
629
obj -> flags |= UNINTERESTING ;
614
- if (add_parents_to_list (revs , commit , & list ) < 0 )
630
+ if (add_parents_to_list (revs , commit , & list , NULL ) < 0 )
615
631
return -1 ;
616
632
if (obj -> flags & UNINTERESTING ) {
617
633
mark_parents_uninteresting (commit );
@@ -1458,10 +1474,12 @@ enum rewrite_result {
1458
1474
1459
1475
static enum rewrite_result rewrite_one (struct rev_info * revs , struct commit * * pp )
1460
1476
{
1477
+ struct commit_list * cache = NULL ;
1478
+
1461
1479
for (;;) {
1462
1480
struct commit * p = * pp ;
1463
1481
if (!revs -> limited )
1464
- if (add_parents_to_list (revs , p , & revs -> commits ) < 0 )
1482
+ if (add_parents_to_list (revs , p , & revs -> commits , & cache ) < 0 )
1465
1483
return rewrite_one_error ;
1466
1484
if (p -> parents && p -> parents -> next )
1467
1485
return rewrite_one_ok ;
@@ -1580,7 +1598,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
1580
1598
if (revs -> max_age != -1 &&
1581
1599
(commit -> date < revs -> max_age ))
1582
1600
continue ;
1583
- if (add_parents_to_list (revs , commit , & revs -> commits ) < 0 )
1601
+ if (add_parents_to_list (revs , commit , & revs -> commits , NULL ) < 0 )
1584
1602
return NULL ;
1585
1603
}
1586
1604
0 commit comments