]> git.ipfire.org Git - thirdparty/git.git/commitdiff
name-rev: use commit_stack
authorRené Scharfe <l.s.r@web.de>
Wed, 24 Dec 2025 17:03:17 +0000 (18:03 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Dec 2025 23:29:27 +0000 (08:29 +0900)
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>
builtin/name-rev.c

index 615f7d1aae498769109caf2da7bf9c31c13ce054..6188cf98ce0157efe14ae3c5d8533bca82454f15 100644 (file)
@@ -180,8 +180,7 @@ static void name_rev(struct commit *start_commit,
 {
        struct prio_queue queue;
        struct commit *commit;
-       struct commit **parents_to_queue = NULL;
-       size_t parents_to_queue_nr, parents_to_queue_alloc = 0;
+       struct commit_stack parents_to_queue = COMMIT_STACK_INIT;
        struct rev_name *start_name;
 
        repo_parse_commit(the_repository, start_commit);
@@ -206,7 +205,7 @@ static void name_rev(struct commit *start_commit,
                struct commit_list *parents;
                int parent_number = 1;
 
-               parents_to_queue_nr = 0;
+               parents_to_queue.nr = 0;
 
                for (parents = commit->parents;
                                parents;
@@ -238,22 +237,18 @@ static void name_rev(struct commit *start_commit,
                                                                string_pool);
                                else
                                        parent_name->tip_name = name->tip_name;
-                               ALLOC_GROW(parents_to_queue,
-                                          parents_to_queue_nr + 1,
-                                          parents_to_queue_alloc);
-                               parents_to_queue[parents_to_queue_nr] = parent;
-                               parents_to_queue_nr++;
+                               commit_stack_push(&parents_to_queue, parent);
                        }
                }
 
                /* The first parent must come out first from the prio_queue */
-               while (parents_to_queue_nr)
+               while (parents_to_queue.nr)
                        prio_queue_put(&queue,
-                                      parents_to_queue[--parents_to_queue_nr]);
+                                      commit_stack_pop(&parents_to_queue));
        }
 
        clear_prio_queue(&queue);
-       free(parents_to_queue);
+       commit_stack_clear(&parents_to_queue);
 }
 
 static int subpath_matches(const char *path, const char *filter)