name-rev: use commit_stack

Simplify the code by using 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 d78039cd500176c919a749deb197ed68d1847110
1 file changed +6 -11
builtin/name-rev.c
+6 -11
@@ -180,8 +180,7 @@ static void name_rev(struct commit *start_commit,
180 {
181 struct prio_queue queue;
182 struct commit *commit;
183 - struct commit **parents_to_queue = NULL;
184 - size_t parents_to_queue_nr, parents_to_queue_alloc = 0;
183 + struct commit_stack parents_to_queue = COMMIT_STACK_INIT;
184 struct rev_name *start_name;
185
186 repo_parse_commit(the_repository, start_commit);
@@ -206,7 +205,7 @@ static void name_rev(struct commit *start_commit,
205 struct commit_list *parents;
206 int parent_number = 1;
207
209 - parents_to_queue_nr = 0;
208 + parents_to_queue.nr = 0;
209
210 for (parents = commit->parents;
211 parents;
@@ -238,22 +237,18 @@ static void name_rev(struct commit *start_commit,
237 string_pool);
238 else
239 parent_name->tip_name = name->tip_name;
241 - ALLOC_GROW(parents_to_queue,
242 - parents_to_queue_nr + 1,
243 - parents_to_queue_alloc);
244 - parents_to_queue[parents_to_queue_nr] = parent;
245 - parents_to_queue_nr++;
240 + commit_stack_push(&parents_to_queue, parent);
241 }
242 }
243
244 /* The first parent must come out first from the prio_queue */
250 - while (parents_to_queue_nr)
245 + while (parents_to_queue.nr)
246 prio_queue_put(&queue,
252 - parents_to_queue[--parents_to_queue_nr]);
247 + commit_stack_pop(&parents_to_queue));
248 }
249
250 clear_prio_queue(&queue);
256 - free(parents_to_queue);
251 + commit_stack_clear(&parents_to_queue);
252 }
253
254 static int subpath_matches(const char *path, const char *filter)