@@ -911,26 +911,11 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
911
911
commit -> object .flags |= TREESAME ;
912
912
}
913
913
914
- static void commit_list_insert_by_date_cached (struct commit * p , struct commit_list * * head ,
915
- struct commit_list * cached_base , struct commit_list * * cache )
916
- {
917
- struct commit_list * new_entry ;
918
-
919
- if (cached_base && p -> date < cached_base -> item -> date )
920
- new_entry = commit_list_insert_by_date (p , & cached_base -> next );
921
- else
922
- new_entry = commit_list_insert_by_date (p , head );
923
-
924
- if (cache && (!* cache || p -> date < (* cache )-> item -> date ))
925
- * cache = new_entry ;
926
- }
927
-
928
914
static int process_parents (struct rev_info * revs , struct commit * commit ,
929
- struct commit_list * * list , struct commit_list * * cache_ptr )
915
+ struct commit_list * * list , struct prio_queue * queue )
930
916
{
931
917
struct commit_list * parent = commit -> parents ;
932
918
unsigned left_flag ;
933
- struct commit_list * cached_base = cache_ptr ? * cache_ptr : NULL ;
934
919
935
920
if (commit -> object .flags & ADDED )
936
921
return 0 ;
@@ -966,7 +951,9 @@ static int process_parents(struct rev_info *revs, struct commit *commit,
966
951
continue ;
967
952
p -> object .flags |= SEEN ;
968
953
if (list )
969
- commit_list_insert_by_date_cached (p , list , cached_base , cache_ptr );
954
+ commit_list_insert_by_date (p , list );
955
+ if (queue )
956
+ prio_queue_put (queue , p );
970
957
}
971
958
return 0 ;
972
959
}
@@ -1006,7 +993,9 @@ static int process_parents(struct rev_info *revs, struct commit *commit,
1006
993
if (!(p -> object .flags & SEEN )) {
1007
994
p -> object .flags |= SEEN ;
1008
995
if (list )
1009
- commit_list_insert_by_date_cached (p , list , cached_base , cache_ptr );
996
+ commit_list_insert_by_date (p , list );
997
+ if (queue )
998
+ prio_queue_put (queue , p );
1010
999
}
1011
1000
if (revs -> first_parent_only )
1012
1001
break ;
@@ -3345,14 +3334,14 @@ int prepare_revision_walk(struct rev_info *revs)
3345
3334
return 0 ;
3346
3335
}
3347
3336
3348
- static enum rewrite_result rewrite_one (struct rev_info * revs , struct commit * * pp )
3337
+ static enum rewrite_result rewrite_one_1 (struct rev_info * revs ,
3338
+ struct commit * * pp ,
3339
+ struct prio_queue * queue )
3349
3340
{
3350
- struct commit_list * cache = NULL ;
3351
-
3352
3341
for (;;) {
3353
3342
struct commit * p = * pp ;
3354
3343
if (!revs -> limited )
3355
- if (process_parents (revs , p , & revs -> commits , & cache ) < 0 )
3344
+ if (process_parents (revs , p , NULL , queue ) < 0 )
3356
3345
return rewrite_one_error ;
3357
3346
if (p -> object .flags & UNINTERESTING )
3358
3347
return rewrite_one_ok ;
@@ -3366,6 +3355,31 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
3366
3355
}
3367
3356
}
3368
3357
3358
+ static void merge_queue_into_list (struct prio_queue * q , struct commit_list * * list )
3359
+ {
3360
+ while (q -> nr ) {
3361
+ struct commit * item = prio_queue_peek (q );
3362
+ struct commit_list * p = * list ;
3363
+
3364
+ if (p && p -> item -> date >= item -> date )
3365
+ list = & p -> next ;
3366
+ else {
3367
+ p = commit_list_insert (item , list );
3368
+ list = & p -> next ; /* skip newly added item */
3369
+ prio_queue_get (q ); /* pop item */
3370
+ }
3371
+ }
3372
+ }
3373
+
3374
+ static enum rewrite_result rewrite_one (struct rev_info * revs , struct commit * * pp )
3375
+ {
3376
+ struct prio_queue queue = { compare_commits_by_commit_date };
3377
+ enum rewrite_result ret = rewrite_one_1 (revs , pp , & queue );
3378
+ merge_queue_into_list (& queue , & revs -> commits );
3379
+ clear_prio_queue (& queue );
3380
+ return ret ;
3381
+ }
3382
+
3369
3383
int rewrite_parents (struct rev_info * revs , struct commit * commit ,
3370
3384
rewrite_parent_fn_t rewrite_parent )
3371
3385
{
0 commit comments