commit-reach: use commit_stack
Use commit_stack instead of open-coding it. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 24, 2025 at 18:03 UTC
0e445956f4c9b6d079feb5ed831f018c857b955b
1 file changed
+12
-13
commit-reach.c
+12
-13
@@ -283,8 +283,8 @@ static int remove_redundant_with_gen(struct repository *r,
283
{
284
size_t i, count_non_stale = 0, count_still_independent = cnt;
285
timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
286
- struct commit **walk_start, **sorted;
287
- size_t walk_start_nr = 0, walk_start_alloc = cnt;
286
+ struct commit **sorted;
287
+ struct commit_stack walk_start = COMMIT_STACK_INIT;
288
size_t min_gen_pos = 0;
289
290
/*
@@ -298,7 +298,7 @@ static int remove_redundant_with_gen(struct repository *r,
298
QSORT(sorted, cnt, compare_commits_by_gen);
299
min_generation = commit_graph_generation(sorted[0]);
300
301
- ALLOC_ARRAY(walk_start, walk_start_alloc);
301
+ commit_stack_grow(&walk_start, cnt);
302
303
/* Mark all parents of the input as STALE */
304
for (i = 0; i < cnt; i++) {
@@ -312,18 +312,17 @@ static int remove_redundant_with_gen(struct repository *r,
312
repo_parse_commit(r, parents->item);
313
if (!(parents->item->object.flags & STALE)) {
314
parents->item->object.flags |= STALE;
315
- ALLOC_GROW(walk_start, walk_start_nr + 1, walk_start_alloc);
316
- walk_start[walk_start_nr++] = parents->item;
315
+ commit_stack_push(&walk_start, parents->item);
316
}
317
parents = parents->next;
318
}
319
}
320
322
- QSORT(walk_start, walk_start_nr, compare_commits_by_gen);
321
+ QSORT(walk_start.items, walk_start.nr, compare_commits_by_gen);
322
323
/* remove STALE bit for now to allow walking through parents */
325
- for (i = 0; i < walk_start_nr; i++)
326
- walk_start[i]->object.flags &= ~STALE;
324
+ for (i = 0; i < walk_start.nr; i++)
325
+ walk_start.items[i]->object.flags &= ~STALE;
326
327
/*
328
* Start walking from the highest generation. Hopefully, it will
@@ -331,12 +330,12 @@ static int remove_redundant_with_gen(struct repository *r,
330
* terminate early. Otherwise, we will do the same amount of work
331
* as before.
332
*/
334
- for (i = walk_start_nr; i && count_still_independent > 1; i--) {
333
+ for (i = walk_start.nr; i && count_still_independent > 1; i--) {
334
/* push the STALE bits up to min generation */
335
struct commit_list *stack = NULL;
336
338
- commit_list_insert(walk_start[i - 1], &stack);
339
- walk_start[i - 1]->object.flags |= STALE;
337
+ commit_list_insert(walk_start.items[i - 1], &stack);
338
+ walk_start.items[i - 1]->object.flags |= STALE;
339
340
while (stack) {
341
struct commit_list *parents;
@@ -390,8 +389,8 @@ static int remove_redundant_with_gen(struct repository *r,
389
}
390
391
/* clear marks */
393
- clear_commit_marks_many(walk_start_nr, walk_start, STALE);
394
- free(walk_start);
392
+ clear_commit_marks_many(walk_start.nr, walk_start.items, STALE);
393
+ commit_stack_clear(&walk_start);
394
395
*dedup_cnt = count_non_stale;
396
return 0;