@@ -49,14 +49,14 @@ static int queue_has_nonstale(struct prio_queue *queue)
49
49
}
50
50
51
51
/* all input commits in one and twos[] must have been parsed! */
52
- static struct commit_list * paint_down_to_common (struct repository * r ,
53
- struct commit * one , int n ,
54
- struct commit * * twos ,
55
- timestamp_t min_generation ,
56
- int ignore_missing_commits )
52
+ static int paint_down_to_common (struct repository * r ,
53
+ struct commit * one , int n ,
54
+ struct commit * * twos ,
55
+ timestamp_t min_generation ,
56
+ int ignore_missing_commits ,
57
+ struct commit_list * * result )
57
58
{
58
59
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
59
- struct commit_list * result = NULL ;
60
60
int i ;
61
61
timestamp_t last_gen = GENERATION_NUMBER_INFINITY ;
62
62
@@ -65,8 +65,8 @@ static struct commit_list *paint_down_to_common(struct repository *r,
65
65
66
66
one -> object .flags |= PARENT1 ;
67
67
if (!n ) {
68
- commit_list_append (one , & result );
69
- return result ;
68
+ commit_list_append (one , result );
69
+ return 0 ;
70
70
}
71
71
prio_queue_put (& queue , one );
72
72
@@ -94,7 +94,7 @@ static struct commit_list *paint_down_to_common(struct repository *r,
94
94
if (flags == (PARENT1 | PARENT2 )) {
95
95
if (!(commit -> object .flags & RESULT )) {
96
96
commit -> object .flags |= RESULT ;
97
- commit_list_insert_by_date (commit , & result );
97
+ commit_list_insert_by_date (commit , result );
98
98
}
99
99
/* Mark parents of a found merge stale */
100
100
flags |= STALE ;
@@ -107,23 +107,27 @@ static struct commit_list *paint_down_to_common(struct repository *r,
107
107
continue ;
108
108
if (repo_parse_commit (r , p )) {
109
109
clear_prio_queue (& queue );
110
- free_commit_list (result );
110
+ free_commit_list (* result );
111
+ * result = NULL ;
111
112
/*
112
113
* At this stage, we know that the commit is
113
114
* missing: `repo_parse_commit()` uses
114
115
* `OBJECT_INFO_DIE_IF_CORRUPT` and therefore
115
116
* corrupt commits would already have been
116
117
* dispatched with a `die()`.
117
118
*/
118
- return NULL ;
119
+ if (ignore_missing_commits )
120
+ return 0 ;
121
+ return error (_ ("could not parse commit %s" ),
122
+ oid_to_hex (& p -> object .oid ));
119
123
}
120
124
p -> object .flags |= flags ;
121
125
prio_queue_put (& queue , p );
122
126
}
123
127
}
124
128
125
129
clear_prio_queue (& queue );
126
- return result ;
130
+ return 0 ;
127
131
}
128
132
129
133
static struct commit_list * merge_bases_many (struct repository * r ,
@@ -150,7 +154,10 @@ static struct commit_list *merge_bases_many(struct repository *r,
150
154
return NULL ;
151
155
}
152
156
153
- list = paint_down_to_common (r , one , n , twos , 0 , 0 );
157
+ if (paint_down_to_common (r , one , n , twos , 0 , 0 , & list )) {
158
+ free_commit_list (list );
159
+ return NULL ;
160
+ }
154
161
155
162
while (list ) {
156
163
struct commit * commit = pop_commit (& list );
@@ -204,7 +211,7 @@ static int remove_redundant_no_gen(struct repository *r,
204
211
for (i = 0 ; i < cnt ; i ++ )
205
212
repo_parse_commit (r , array [i ]);
206
213
for (i = 0 ; i < cnt ; i ++ ) {
207
- struct commit_list * common ;
214
+ struct commit_list * common = NULL ;
208
215
timestamp_t min_generation = commit_graph_generation (array [i ]);
209
216
210
217
if (redundant [i ])
@@ -220,8 +227,16 @@ static int remove_redundant_no_gen(struct repository *r,
220
227
if (curr_generation < min_generation )
221
228
min_generation = curr_generation ;
222
229
}
223
- common = paint_down_to_common (r , array [i ], filled ,
224
- work , min_generation , 0 );
230
+ if (paint_down_to_common (r , array [i ], filled ,
231
+ work , min_generation , 0 , & common )) {
232
+ clear_commit_marks (array [i ], all_flags );
233
+ clear_commit_marks_many (filled , work , all_flags );
234
+ free_commit_list (common );
235
+ free (work );
236
+ free (redundant );
237
+ free (filled_index );
238
+ return -1 ;
239
+ }
225
240
if (array [i ]-> object .flags & PARENT2 )
226
241
redundant [i ] = 1 ;
227
242
for (j = 0 ; j < filled ; j ++ )
@@ -421,6 +436,10 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
421
436
clear_commit_marks_many (n , twos , all_flags );
422
437
423
438
cnt = remove_redundant (r , rslt , cnt );
439
+ if (cnt < 0 ) {
440
+ free (rslt );
441
+ return NULL ;
442
+ }
424
443
result = NULL ;
425
444
for (i = 0 ; i < cnt ; i ++ )
426
445
commit_list_insert_by_date (rslt [i ], & result );
@@ -490,7 +509,7 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
490
509
int nr_reference , struct commit * * reference ,
491
510
int ignore_missing_commits )
492
511
{
493
- struct commit_list * bases ;
512
+ struct commit_list * bases = NULL ;
494
513
int ret = 0 , i ;
495
514
timestamp_t generation , max_generation = GENERATION_NUMBER_ZERO ;
496
515
@@ -509,10 +528,11 @@ int repo_in_merge_bases_many(struct repository *r, struct commit *commit,
509
528
if (generation > max_generation )
510
529
return ret ;
511
530
512
- bases = paint_down_to_common (r , commit ,
513
- nr_reference , reference ,
514
- generation , ignore_missing_commits );
515
- if (commit -> object .flags & PARENT2 )
531
+ if (paint_down_to_common (r , commit ,
532
+ nr_reference , reference ,
533
+ generation , ignore_missing_commits , & bases ))
534
+ ret = -1 ;
535
+ else if (commit -> object .flags & PARENT2 )
516
536
ret = 1 ;
517
537
clear_commit_marks (commit , all_flags );
518
538
clear_commit_marks_many (nr_reference , reference , all_flags );
@@ -565,6 +585,10 @@ struct commit_list *reduce_heads(struct commit_list *heads)
565
585
}
566
586
}
567
587
num_head = remove_redundant (the_repository , array , num_head );
588
+ if (num_head < 0 ) {
589
+ free (array );
590
+ return NULL ;
591
+ }
568
592
for (i = 0 ; i < num_head ; i ++ )
569
593
tail = & commit_list_insert (array [i ], tail )-> next ;
570
594
free (array );
0 commit comments