diff options
| author | René Scharfe <l.s.r@web.de> | 2026-03-17 22:40:07 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-18 10:39:56 -0700 |
| commit | 1ae7a359ae53e98f153b8fb0dea532d2007a0093 (patch) | |
| tree | 3eae603e4bcd133211d43f56cf3552095842896b /builtin | |
| parent | ca1db8a0f7dc0dbea892e99f5b37c5fe5861be71 (diff) | |
| download | git-1ae7a359ae53e98f153b8fb0dea532d2007a0093.tar.xz | |
use commit_stack instead of prio_queue in LIFO mode
A prio_queue with a NULL compare function acts as a stack -- the last
element in is the first one out (LIFO). Use an actual commit_stack
instead where possible, as it documents the behavior better, provides
type safety and saves some memory because prio_queue stores an
additional tie-breaking counter per element.
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/name-rev.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 6188cf98ce..d6594ada53 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -12,7 +12,6 @@ #include "object-name.h" #include "pager.h" #include "parse-options.h" -#include "prio-queue.h" #include "hash-lookup.h" #include "commit-slab.h" #include "commit-graph.h" @@ -178,7 +177,7 @@ static void name_rev(struct commit *start_commit, const char *tip_name, timestamp_t taggerdate, int from_tag, int deref, struct mem_pool *string_pool) { - struct prio_queue queue; + struct commit_stack stack = COMMIT_STACK_INIT; struct commit *commit; struct commit_stack parents_to_queue = COMMIT_STACK_INIT; struct rev_name *start_name; @@ -197,10 +196,9 @@ static void name_rev(struct commit *start_commit, else start_name->tip_name = mem_pool_strdup(string_pool, tip_name); - memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */ - prio_queue_put(&queue, start_commit); + commit_stack_push(&stack, start_commit); - while ((commit = prio_queue_get(&queue))) { + while ((commit = commit_stack_pop(&stack))) { struct rev_name *name = get_commit_rev_name(commit); struct commit_list *parents; int parent_number = 1; @@ -241,13 +239,13 @@ static void name_rev(struct commit *start_commit, } } - /* The first parent must come out first from the prio_queue */ + /* The first parent must come out first from the stack */ while (parents_to_queue.nr) - prio_queue_put(&queue, - commit_stack_pop(&parents_to_queue)); + commit_stack_push(&stack, + commit_stack_pop(&parents_to_queue)); } - clear_prio_queue(&queue); + commit_stack_clear(&stack); commit_stack_clear(&parents_to_queue); } |
