Skip to content

Commit 0e44595

Browse files
rscharfegitster
authored andcommitted
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>
1 parent 3e456f1 commit 0e44595

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

commit-reach.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ static int remove_redundant_with_gen(struct repository *r,
283283
{
284284
size_t i, count_non_stale = 0, count_still_independent = cnt;
285285
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;
288288
size_t min_gen_pos = 0;
289289

290290
/*
@@ -298,7 +298,7 @@ static int remove_redundant_with_gen(struct repository *r,
298298
QSORT(sorted, cnt, compare_commits_by_gen);
299299
min_generation = commit_graph_generation(sorted[0]);
300300

301-
ALLOC_ARRAY(walk_start, walk_start_alloc);
301+
commit_stack_grow(&walk_start, cnt);
302302

303303
/* Mark all parents of the input as STALE */
304304
for (i = 0; i < cnt; i++) {
@@ -312,31 +312,30 @@ static int remove_redundant_with_gen(struct repository *r,
312312
repo_parse_commit(r, parents->item);
313313
if (!(parents->item->object.flags & STALE)) {
314314
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);
317316
}
318317
parents = parents->next;
319318
}
320319
}
321320

322-
QSORT(walk_start, walk_start_nr, compare_commits_by_gen);
321+
QSORT(walk_start.items, walk_start.nr, compare_commits_by_gen);
323322

324323
/* 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;
327326

328327
/*
329328
* Start walking from the highest generation. Hopefully, it will
330329
* find all other items during the first-parent walk, and we can
331330
* terminate early. Otherwise, we will do the same amount of work
332331
* as before.
333332
*/
334-
for (i = walk_start_nr; i && count_still_independent > 1; i--) {
333+
for (i = walk_start.nr; i && count_still_independent > 1; i--) {
335334
/* push the STALE bits up to min generation */
336335
struct commit_list *stack = NULL;
337336

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;
340339

341340
while (stack) {
342341
struct commit_list *parents;
@@ -390,8 +389,8 @@ static int remove_redundant_with_gen(struct repository *r,
390389
}
391390

392391
/* 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);
395394

396395
*dedup_cnt = count_non_stale;
397396
return 0;

0 commit comments

Comments
 (0)