Skip to content

Commit c7a5d9a

Browse files
committed
Revert "Merge branch 'rs/pop-recent-commit-with-prio-queue' into next"
This reverts commit 03dce62, reversing changes made to 6ba6078.
1 parent c89ff58 commit c7a5d9a

File tree

10 files changed

+34
-170
lines changed

10 files changed

+34
-170
lines changed

commit.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "parse.h"
3232
#include "object-file.h"
3333
#include "object-file-convert.h"
34-
#include "prio-queue.h"
3534

3635
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
3736

@@ -740,27 +739,20 @@ void commit_list_sort_by_date(struct commit_list **list)
740739
commit_list_sort(list, commit_list_compare_by_date);
741740
}
742741

743-
struct commit *pop_most_recent_commit(struct prio_queue *queue,
742+
struct commit *pop_most_recent_commit(struct commit_list **list,
744743
unsigned int mark)
745744
{
746-
struct commit *ret = prio_queue_peek(queue);
747-
int get_pending = 1;
745+
struct commit *ret = pop_commit(list);
748746
struct commit_list *parents = ret->parents;
749747

750748
while (parents) {
751749
struct commit *commit = parents->item;
752750
if (!repo_parse_commit(the_repository, commit) && !(commit->object.flags & mark)) {
753751
commit->object.flags |= mark;
754-
if (get_pending)
755-
prio_queue_replace(queue, commit);
756-
else
757-
prio_queue_put(queue, commit);
758-
get_pending = 0;
752+
commit_list_insert_by_date(commit, list);
759753
}
760754
parents = parents->next;
761755
}
762-
if (get_pending)
763-
prio_queue_get(queue);
764756
return ret;
765757
}
766758

commit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ const char *repo_logmsg_reencode(struct repository *r,
201201

202202
const char *skip_blank_lines(const char *msg);
203203

204-
struct prio_queue;
205-
206-
/* Removes the first commit from a prio_queue and adds its parents. */
207-
struct commit *pop_most_recent_commit(struct prio_queue *queue,
204+
/** Removes the first commit from a list sorted by date, and adds all
205+
* of its parents.
206+
**/
207+
struct commit *pop_most_recent_commit(struct commit_list **list,
208208
unsigned int mark);
209209

210210
struct commit *pop_commit(struct commit_list **stack);

fetch-pack.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "commit-graph.h"
3535
#include "sigchain.h"
3636
#include "mergesort.h"
37-
#include "prio-queue.h"
3837

3938
static int transfer_unpack_limit = -1;
4039
static int fetch_unpack_limit = -1;
@@ -602,15 +601,15 @@ static int find_common(struct fetch_negotiator *negotiator,
602601
return count ? retval : 0;
603602
}
604603

605-
static struct prio_queue complete = { compare_commits_by_commit_date };
604+
static struct commit_list *complete;
606605

607606
static int mark_complete(const struct object_id *oid)
608607
{
609608
struct commit *commit = deref_without_lazy_fetch(oid, 1);
610609

611610
if (commit && !(commit->object.flags & COMPLETE)) {
612611
commit->object.flags |= COMPLETE;
613-
prio_queue_put(&complete, commit);
612+
commit_list_insert(commit, &complete);
614613
}
615614
return 0;
616615
}
@@ -627,12 +626,9 @@ static int mark_complete_oid(const char *refname UNUSED,
627626
static void mark_recent_complete_commits(struct fetch_pack_args *args,
628627
timestamp_t cutoff)
629628
{
630-
while (complete.nr) {
631-
struct commit *item = prio_queue_peek(&complete);
632-
if (item->date < cutoff)
633-
break;
629+
while (complete && cutoff <= complete->item->date) {
634630
print_verbose(args, _("Marking %s as complete"),
635-
oid_to_hex(&item->object.oid));
631+
oid_to_hex(&complete->item->object.oid));
636632
pop_most_recent_commit(&complete, COMPLETE);
637633
}
638634
}
@@ -802,6 +798,7 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
802798
refs_for_each_rawref(get_main_ref_store(the_repository),
803799
mark_complete_oid, NULL);
804800
for_each_cached_alternate(NULL, mark_alternate_complete);
801+
commit_list_sort_by_date(&complete);
805802
if (cutoff)
806803
mark_recent_complete_commits(args, cutoff);
807804
}

object-name.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "commit-reach.h"
2929
#include "date.h"
3030
#include "object-file-convert.h"
31-
#include "prio-queue.h"
3231

3332
static int get_oid_oneline(struct repository *r, const char *, struct object_id *,
3433
const struct commit_list *);
@@ -1462,7 +1461,7 @@ static int get_oid_oneline(struct repository *r,
14621461
const char *prefix, struct object_id *oid,
14631462
const struct commit_list *list)
14641463
{
1465-
struct prio_queue copy = { compare_commits_by_commit_date };
1464+
struct commit_list *copy = NULL, **copy_tail = &copy;
14661465
const struct commit_list *l;
14671466
int found = 0;
14681467
int negative = 0;
@@ -1484,9 +1483,9 @@ static int get_oid_oneline(struct repository *r,
14841483

14851484
for (l = list; l; l = l->next) {
14861485
l->item->object.flags |= ONELINE_SEEN;
1487-
prio_queue_put(&copy, l->item);
1486+
copy_tail = &commit_list_insert(l->item, copy_tail)->next;
14881487
}
1489-
while (copy.nr) {
1488+
while (copy) {
14901489
const char *p, *buf;
14911490
struct commit *commit;
14921491
int matches;
@@ -1508,7 +1507,7 @@ static int get_oid_oneline(struct repository *r,
15081507
regfree(&regex);
15091508
for (l = list; l; l = l->next)
15101509
clear_commit_marks(l->item, ONELINE_SEEN);
1511-
clear_prio_queue(&copy);
1510+
free_commit_list(copy);
15121511
return found ? 0 : -1;
15131512
}
15141513

@@ -2062,6 +2061,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
20622061
cb.list = &list;
20632062
refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
20642063
refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb);
2064+
commit_list_sort_by_date(&list);
20652065
ret = get_oid_oneline(repo, name + 2, oid, list);
20662066

20672067
free_commit_list(list);

prio-queue.c

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,22 @@ void prio_queue_put(struct prio_queue *queue, void *thing)
5858
}
5959
}
6060

61-
static void sift_down_root(struct prio_queue *queue)
61+
void *prio_queue_get(struct prio_queue *queue)
6262
{
63+
void *result;
6364
size_t ix, child;
6465

66+
if (!queue->nr)
67+
return NULL;
68+
if (!queue->compare)
69+
return queue->array[--queue->nr].data; /* LIFO */
70+
71+
result = queue->array[0].data;
72+
if (!--queue->nr)
73+
return result;
74+
75+
queue->array[0] = queue->array[queue->nr];
76+
6577
/* Push down the one at the root */
6678
for (ix = 0; ix * 2 + 1 < queue->nr; ix = child) {
6779
child = ix * 2 + 1; /* left */
@@ -74,23 +86,6 @@ static void sift_down_root(struct prio_queue *queue)
7486

7587
swap(queue, child, ix);
7688
}
77-
}
78-
79-
void *prio_queue_get(struct prio_queue *queue)
80-
{
81-
void *result;
82-
83-
if (!queue->nr)
84-
return NULL;
85-
if (!queue->compare)
86-
return queue->array[--queue->nr].data; /* LIFO */
87-
88-
result = queue->array[0].data;
89-
if (!--queue->nr)
90-
return result;
91-
92-
queue->array[0] = queue->array[queue->nr];
93-
sift_down_root(queue);
9489
return result;
9590
}
9691

@@ -102,17 +97,3 @@ void *prio_queue_peek(struct prio_queue *queue)
10297
return queue->array[queue->nr - 1].data;
10398
return queue->array[0].data;
10499
}
105-
106-
void prio_queue_replace(struct prio_queue *queue, void *thing)
107-
{
108-
if (!queue->nr) {
109-
prio_queue_put(queue, thing);
110-
} else if (!queue->compare) {
111-
queue->array[queue->nr - 1].ctr = queue->insertion_ctr++;
112-
queue->array[queue->nr - 1].data = thing;
113-
} else {
114-
queue->array[0].ctr = queue->insertion_ctr++;
115-
queue->array[0].data = thing;
116-
sift_down_root(queue);
117-
}
118-
}

prio-queue.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ void *prio_queue_get(struct prio_queue *);
5252
*/
5353
void *prio_queue_peek(struct prio_queue *);
5454

55-
/*
56-
* Replace the "thing" that compares the smallest with a new "thing",
57-
* like prio_queue_get()+prio_queue_put() would do, but in a more
58-
* efficient way. Does the same as prio_queue_put() if the queue is
59-
* empty.
60-
*/
61-
void prio_queue_replace(struct prio_queue *queue, void *thing);
62-
6355
void clear_prio_queue(struct prio_queue *);
6456

6557
/* Reverse the LIFO elements */

t/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,6 @@ benchmarks = [
11161116
'perf/p1450-fsck.sh',
11171117
'perf/p1451-fsck-skip-list.sh',
11181118
'perf/p1500-graph-walks.sh',
1119-
'perf/p1501-rev-parse-oneline.sh',
11201119
'perf/p2000-sparse-operations.sh',
11211120
'perf/p3400-rebase.sh',
11221121
'perf/p3404-rebase-interactive.sh',

t/perf/p1501-rev-parse-oneline.sh

Lines changed: 0 additions & 71 deletions
This file was deleted.

t/unit-tests/u-prio-queue.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ static int intcmp(const void *va, const void *vb, void *data UNUSED)
1313
#define STACK -3
1414
#define GET -4
1515
#define REVERSE -5
16-
#define REPLACE -6
1716

1817
static int show(int *v)
1918
{
@@ -52,15 +51,6 @@ static void test_prio_queue(int *input, size_t input_size,
5251
case REVERSE:
5352
prio_queue_reverse(&pq);
5453
break;
55-
case REPLACE:
56-
peek = prio_queue_peek(&pq);
57-
cl_assert(i + 1 < input_size);
58-
cl_assert(input[i + 1] >= 0);
59-
cl_assert(j < result_size);
60-
cl_assert_equal_i(result[j], show(peek));
61-
j++;
62-
prio_queue_replace(&pq, &input[++i]);
63-
break;
6454
default:
6555
prio_queue_put(&pq, &input[i]);
6656
break;
@@ -91,13 +81,6 @@ void test_prio_queue__empty(void)
9181
((int []){ 1, 2, MISSING, 1, 2, MISSING }));
9282
}
9383

94-
void test_prio_queue__replace(void)
95-
{
96-
TEST_INPUT(((int []){ REPLACE, 6, 2, 4, REPLACE, 5, 7, GET,
97-
REPLACE, 1, DUMP }),
98-
((int []){ MISSING, 2, 4, 5, 1, 6, 7 }));
99-
}
100-
10184
void test_prio_queue__stack(void)
10285
{
10386
TEST_INPUT(((int []){ STACK, 8, 1, 5, 4, 6, 2, 3, DUMP }),
@@ -109,9 +92,3 @@ void test_prio_queue__reverse_stack(void)
10992
TEST_INPUT(((int []){ STACK, 1, 2, 3, 4, 5, 6, REVERSE, DUMP }),
11093
((int []){ 1, 2, 3, 4, 5, 6 }));
11194
}
112-
113-
void test_prio_queue__replace_stack(void)
114-
{
115-
TEST_INPUT(((int []){ STACK, 8, 1, 5, REPLACE, 4, 6, 2, 3, DUMP }),
116-
((int []){ 5, 3, 2, 6, 4, 1, 8 }));
117-
}

0 commit comments

Comments
 (0)