Skip to content

Commit f5b2cca

Browse files
committed
Merge branch 'rs/prio-queue-to-commit-stack' into jch
* rs/prio-queue-to-commit-stack: use commit_stack instead of prio_queue in LIFO mode
2 parents e962ba6 + 1ae7a35 commit f5b2cca

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

builtin/name-rev.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "object-name.h"
1313
#include "pager.h"
1414
#include "parse-options.h"
15-
#include "prio-queue.h"
1615
#include "hash-lookup.h"
1716
#include "commit-slab.h"
1817
#include "commit-graph.h"
@@ -178,7 +177,7 @@ static void name_rev(struct commit *start_commit,
178177
const char *tip_name, timestamp_t taggerdate,
179178
int from_tag, int deref, struct mem_pool *string_pool)
180179
{
181-
struct prio_queue queue;
180+
struct commit_stack stack = COMMIT_STACK_INIT;
182181
struct commit *commit;
183182
struct commit_stack parents_to_queue = COMMIT_STACK_INIT;
184183
struct rev_name *start_name;
@@ -197,10 +196,9 @@ static void name_rev(struct commit *start_commit,
197196
else
198197
start_name->tip_name = mem_pool_strdup(string_pool, tip_name);
199198

200-
memset(&queue, 0, sizeof(queue)); /* Use the prio_queue as LIFO */
201-
prio_queue_put(&queue, start_commit);
199+
commit_stack_push(&stack, start_commit);
202200

203-
while ((commit = prio_queue_get(&queue))) {
201+
while ((commit = commit_stack_pop(&stack))) {
204202
struct rev_name *name = get_commit_rev_name(commit);
205203
struct commit_list *parents;
206204
int parent_number = 1;
@@ -241,13 +239,13 @@ static void name_rev(struct commit *start_commit,
241239
}
242240
}
243241

244-
/* The first parent must come out first from the prio_queue */
242+
/* The first parent must come out first from the stack */
245243
while (parents_to_queue.nr)
246-
prio_queue_put(&queue,
247-
commit_stack_pop(&parents_to_queue));
244+
commit_stack_push(&stack,
245+
commit_stack_pop(&parents_to_queue));
248246
}
249247

250-
clear_prio_queue(&queue);
248+
commit_stack_clear(&stack);
251249
commit_stack_clear(&parents_to_queue);
252250
}
253251

negotiator/default.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ static int clear_marks(const struct reference *ref, void *cb_data UNUSED)
5757
static void mark_common(struct negotiation_state *ns, struct commit *commit,
5858
int ancestors_only, int dont_parse)
5959
{
60-
struct prio_queue queue = { NULL };
60+
struct commit_stack stack = COMMIT_STACK_INIT;
6161

6262
if (!commit || (commit->object.flags & COMMON))
6363
return;
6464

65-
prio_queue_put(&queue, commit);
65+
commit_stack_push(&stack, commit);
6666
if (!ancestors_only) {
6767
commit->object.flags |= COMMON;
6868

6969
if ((commit->object.flags & SEEN) && !(commit->object.flags & POPPED))
7070
ns->non_common_revs--;
7171
}
72-
while ((commit = prio_queue_get(&queue))) {
72+
while ((commit = commit_stack_pop(&stack))) {
7373
struct object *o = (struct object *)commit;
7474

7575
if (!(o->flags & SEEN))
@@ -94,12 +94,12 @@ static void mark_common(struct negotiation_state *ns, struct commit *commit,
9494
if ((p->object.flags & SEEN) && !(p->object.flags & POPPED))
9595
ns->non_common_revs--;
9696

97-
prio_queue_put(&queue, parents->item);
97+
commit_stack_push(&stack, parents->item);
9898
}
9999
}
100100
}
101101

102-
clear_prio_queue(&queue);
102+
commit_stack_clear(&stack);
103103
}
104104

105105
/*

negotiator/skipping.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ static int clear_marks(const struct reference *ref, void *cb_data UNUSED)
9191
*/
9292
static void mark_common(struct data *data, struct commit *seen_commit)
9393
{
94-
struct prio_queue queue = { NULL };
94+
struct commit_stack stack = COMMIT_STACK_INIT;
9595
struct commit *c;
9696

9797
if (seen_commit->object.flags & COMMON)
9898
return;
9999

100-
prio_queue_put(&queue, seen_commit);
100+
commit_stack_push(&stack, seen_commit);
101101
seen_commit->object.flags |= COMMON;
102-
while ((c = prio_queue_get(&queue))) {
102+
while ((c = commit_stack_pop(&stack))) {
103103
struct commit_list *p;
104104

105105
if (!(c->object.flags & POPPED))
@@ -113,11 +113,11 @@ static void mark_common(struct data *data, struct commit *seen_commit)
113113
continue;
114114

115115
p->item->object.flags |= COMMON;
116-
prio_queue_put(&queue, p->item);
116+
commit_stack_push(&stack, p->item);
117117
}
118118
}
119119

120-
clear_prio_queue(&queue);
120+
commit_stack_clear(&stack);
121121
}
122122

123123
/*

0 commit comments

Comments
 (0)