Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,56 +251,19 @@ static int compare_pt(const void *a_, const void *b_)
return 0;
}

struct lazy_queue {
struct prio_queue queue;
bool get_pending;
};

#define LAZY_QUEUE_INIT { { compare_commits_by_commit_date }, false }

static void *lazy_queue_get(struct lazy_queue *queue)
{
if (queue->get_pending)
prio_queue_get(&queue->queue);
else
queue->get_pending = true;
return prio_queue_peek(&queue->queue);
}

static void lazy_queue_put(struct lazy_queue *queue, void *thing)
{
if (queue->get_pending)
prio_queue_replace(&queue->queue, thing);
else
prio_queue_put(&queue->queue, thing);
queue->get_pending = false;
}

static bool lazy_queue_empty(const struct lazy_queue *queue)
{
return queue->queue.nr == (queue->get_pending ? 1 : 0);
}

static void lazy_queue_clear(struct lazy_queue *queue)
{
clear_prio_queue(&queue->queue);
queue->get_pending = false;
}

static unsigned long finish_depth_computation(struct lazy_queue *queue,
static unsigned long finish_depth_computation(struct prio_queue *queue,
struct possible_tag *best)
{
unsigned long seen_commits = 0;
struct oidset unflagged = OIDSET_INIT;
struct commit *c;

for (size_t i = queue->get_pending ? 1 : 0; i < queue->queue.nr; i++) {
struct commit *commit = queue->queue.array[i].data;
if (!(commit->object.flags & best->flag_within))
oidset_insert(&unflagged, &commit->object.oid);
prio_queue_for_each(queue, c) {
if (!(c->object.flags & best->flag_within))
oidset_insert(&unflagged, &c->object.oid);
}

while (!lazy_queue_empty(queue)) {
struct commit *c = lazy_queue_get(queue);
while ((c = prio_queue_get(queue))) {
struct commit_list *parents = c->parents;
seen_commits++;
if (c->object.flags & best->flag_within) {
Expand All @@ -316,7 +279,7 @@ static unsigned long finish_depth_computation(struct lazy_queue *queue,
repo_parse_commit(the_repository, p);
seen = p->object.flags & SEEN;
if (!seen)
lazy_queue_put(queue, p);
prio_queue_put(queue, p);
flag_before = p->object.flags & best->flag_within;
p->object.flags |= c->object.flags;
flag_after = p->object.flags & best->flag_within;
Expand Down Expand Up @@ -364,8 +327,8 @@ static void append_suffix(int depth, const struct object_id *oid, struct strbuf

static void describe_commit(struct commit *cmit, struct strbuf *dst)
{
struct commit *gave_up_on = NULL;
struct lazy_queue queue = LAZY_QUEUE_INIT;
struct commit *c, *gave_up_on = NULL;
struct prio_queue queue = { compare_commits_by_commit_date };
struct commit_name *n;
struct possible_tag all_matches[MAX_TAGS];
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
Expand Down Expand Up @@ -407,9 +370,8 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
}

cmit->object.flags = SEEN;
lazy_queue_put(&queue, cmit);
while (!lazy_queue_empty(&queue)) {
struct commit *c = lazy_queue_get(&queue);
prio_queue_put(&queue, cmit);
while ((c = prio_queue_get(&queue))) {
struct commit_list *parents = c->parents;
struct commit_name **slot;

Expand Down Expand Up @@ -443,7 +405,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
t->depth++;
}
/* Stop if last remaining path already covered by best candidate(s) */
if (annotated_cnt && lazy_queue_empty(&queue)) {
if (annotated_cnt && !prio_queue_size(&queue)) {
int best_depth = INT_MAX;
unsigned best_within = 0;
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
Expand All @@ -466,7 +428,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
struct commit *p = parents->item;
repo_parse_commit(the_repository, p);
if (!(p->object.flags & SEEN))
lazy_queue_put(&queue, p);
prio_queue_put(&queue, p);
p->object.flags |= c->object.flags;
parents = parents->next;

Expand All @@ -481,7 +443,7 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
if (suffix)
strbuf_addstr(dst, suffix);
lazy_queue_clear(&queue);
clear_prio_queue(&queue);
return;
}
if (unannotated_cnt)
Expand All @@ -497,11 +459,11 @@ static void describe_commit(struct commit *cmit, struct strbuf *dst)
QSORT(all_matches, match_cnt, compare_pt);

if (gave_up_on) {
lazy_queue_put(&queue, gave_up_on);
prio_queue_put(&queue, gave_up_on);
seen_commits--;
}
seen_commits += finish_depth_computation(&queue, &all_matches[0]);
lazy_queue_clear(&queue);
clear_prio_queue(&queue);

if (debug) {
static int label_width = -1;
Expand Down
7 changes: 3 additions & 4 deletions builtin/last-modified.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ static void process_parent(struct last_modified *lm,
static int last_modified_run(struct last_modified *lm)
{
int max_count, queue_popped = 0;
struct commit *c, *n;
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
struct prio_queue not_queue = { compare_commits_by_gen_then_commit_date };
struct commit_list *list;
Expand Down Expand Up @@ -389,10 +390,9 @@ static int last_modified_run(struct last_modified *lm)
}
}

while (queue.nr) {
while ((c = prio_queue_get(&queue))) {
int parent_i;
struct commit_list *p;
struct commit *c = prio_queue_get(&queue);
struct bitmap *active_c = active_paths_for(lm, c);

if ((0 <= max_count && max_count < ++queue_popped) ||
Expand All @@ -416,9 +416,8 @@ static int last_modified_run(struct last_modified *lm)
*/
repo_parse_commit(lm->rev.repo, c);

while (not_queue.nr) {
while ((n = prio_queue_get(&not_queue))) {
struct commit_list *np;
struct commit *n = prio_queue_get(&not_queue);

repo_parse_commit(lm->rev.repo, n);

Expand Down
24 changes: 9 additions & 15 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ static const char *get_color_reset_code(void)

static struct commit *interesting(struct prio_queue *queue)
{
for (size_t i = 0; i < queue->nr; i++) {
struct commit *commit = queue->array[i].data;
if (commit->object.flags & UNINTERESTING)
continue;
return commit;
struct commit *commit;
prio_queue_for_each(queue, commit) {
if (!(commit->object.flags & UNINTERESTING))
return commit;
}
return NULL;
}
Expand Down Expand Up @@ -228,17 +227,18 @@ static void join_revs(struct prio_queue *queue,
{
int all_mask = ((1u << (REV_SHIFT + num_rev)) - 1);
int all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
struct commit *commit;

while (queue->nr) {
while ((commit = prio_queue_peek(queue))) {
struct commit_list *parents;
int still_interesting = !!interesting(queue);
struct commit *commit = prio_queue_peek(queue);
bool get_pending = true;
int flags = commit->object.flags & all_mask;

if (!still_interesting && extra <= 0)
break;

prio_queue_get(queue);

mark_seen(commit, seen_p);
if ((flags & all_revs) == all_revs)
flags |= UNINTERESTING;
Expand All @@ -254,14 +254,8 @@ static void join_revs(struct prio_queue *queue,
if (mark_seen(p, seen_p) && !still_interesting)
extra--;
p->object.flags |= flags;
if (get_pending)
prio_queue_replace(queue, p);
else
prio_queue_put(queue, p);
get_pending = false;
prio_queue_put(queue, p);
}
if (get_pending)
prio_queue_get(queue);
}

/*
Expand Down
24 changes: 13 additions & 11 deletions commit-reach.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ static int compare_commits_by_gen(const void *_a, const void *_b)

static int queue_has_nonstale(struct prio_queue *queue)
{
for (size_t i = 0; i < queue->nr; i++) {
struct commit *commit = queue->array[i].data;
struct commit *commit;
prio_queue_for_each(queue, commit) {
if (!(commit->object.flags & STALE))
return 1;
}
Expand Down Expand Up @@ -1069,6 +1069,7 @@ void ahead_behind(struct repository *r,
struct commit **commits, size_t commits_nr,
struct ahead_behind_count *counts, size_t counts_nr)
{
struct commit *c;
struct prio_queue queue = { .compare = compare_commits_by_gen_then_commit_date };
size_t width = DIV_ROUND_UP(commits_nr, BITS_IN_EWORD);

Expand All @@ -1085,17 +1086,19 @@ void ahead_behind(struct repository *r,
init_bit_arrays(&bit_arrays);

for (size_t i = 0; i < commits_nr; i++) {
struct commit *c = commits[i];
struct bitmap *bitmap = get_bit_array(c, width);
struct bitmap *bitmap;
c = commits[i];
bitmap = get_bit_array(c, width);

bitmap_set(bitmap, i);
insert_no_dup(&queue, c);
}

while (queue_has_nonstale(&queue)) {
struct commit *c = prio_queue_get(&queue);
struct commit_list *p;
struct bitmap *bitmap_c = get_bit_array(c, width);
struct bitmap *bitmap_c;
c = prio_queue_get(&queue);
bitmap_c = get_bit_array(c, width);

for (size_t i = 0; i < counts_nr; i++) {
int reach_from_tip = !!bitmap_get(bitmap_c, counts[i].tip_index);
Expand Down Expand Up @@ -1135,8 +1138,8 @@ void ahead_behind(struct repository *r,

/* STALE is used here, PARENT2 is used by insert_no_dup(). */
repo_clear_commit_marks(r, PARENT2 | STALE);
for (size_t i = 0; i < queue.nr; i++)
free_bit_array(queue.array[i].data);
prio_queue_for_each(&queue, c)
free_bit_array(c);
clear_bit_arrays(&bit_arrays);
clear_prio_queue(&queue);
}
Expand Down Expand Up @@ -1269,7 +1272,7 @@ int get_branch_base_for_tip(struct repository *r,
size_t bases_nr)
{
int best_index = -1;
struct commit *branch_point = NULL;
struct commit *c, *branch_point = NULL;
struct prio_queue queue = { compare_commits_by_gen_then_commit_date };
int found_missing_gen = 0;

Expand Down Expand Up @@ -1322,8 +1325,7 @@ int get_branch_base_for_tip(struct repository *r,
prio_queue_put(&queue, c);
}

while (queue.nr) {
struct commit *c = prio_queue_get(&queue);
while ((c = prio_queue_get(&queue))) {
int best_for_c = get_best(c);
int best_for_p, positive;
struct commit *parent;
Expand Down
11 changes: 2 additions & 9 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,24 +795,17 @@ void commit_list_sort_by_date(struct commit_list **list)
struct commit *pop_most_recent_commit(struct prio_queue *queue,
unsigned int mark)
{
struct commit *ret = prio_queue_peek(queue);
int get_pending = 1;
struct commit *ret = prio_queue_get(queue);
struct commit_list *parents = ret->parents;

while (parents) {
struct commit *commit = parents->item;
if (!repo_parse_commit(the_repository, commit) && !(commit->object.flags & mark)) {
commit->object.flags |= mark;
if (get_pending)
prio_queue_replace(queue, commit);
else
prio_queue_put(queue, commit);
get_pending = 0;
prio_queue_put(queue, commit);
}
parents = parents->next;
}
if (get_pending)
prio_queue_get(queue);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ static int mark_complete_oid(const struct reference *ref, void *cb_data UNUSED)
static void mark_recent_complete_commits(struct fetch_pack_args *args,
timestamp_t cutoff)
{
while (complete.nr) {
struct commit *item = prio_queue_peek(&complete);
struct commit *item;
while ((item = prio_queue_peek(&complete))) {
if (item->date < cutoff)
break;
print_verbose(args, _("Marking %s as complete"),
Expand Down
4 changes: 3 additions & 1 deletion negotiator/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ static const struct object_id *get_rev(struct negotiation_state *ns)
unsigned int mark;
struct commit_list *parents;

if (ns->rev_list.nr == 0 || ns->non_common_revs == 0)
if (ns->non_common_revs == 0)
return NULL;

commit = prio_queue_get(&ns->rev_list);
if (!commit)
return NULL;
repo_parse_commit(the_repository, commit);
parents = commit->parents;

Expand Down
12 changes: 7 additions & 5 deletions negotiator/skipping.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ static int push_parent(struct data *data, struct entry *entry,
/*
* Find the existing entry and use it.
*/
for (size_t i = 0; i < data->rev_list.nr; i++) {
parent_entry = data->rev_list.array[i].data;
prio_queue_for_each(&data->rev_list, parent_entry) {
if (parent_entry->commit == to_push)
goto parent_found;
}
Expand Down Expand Up @@ -181,10 +180,12 @@ static const struct object_id *get_rev(struct data *data)
struct commit_list *p;
int parent_pushed = 0;

if (data->rev_list.nr == 0 || data->non_common_revs == 0)
if (data->non_common_revs == 0)
return NULL;

entry = prio_queue_get(&data->rev_list);
if (!entry)
return NULL;
commit = entry->commit;
commit->object.flags |= POPPED;
if (!(commit->object.flags & COMMON))
Expand Down Expand Up @@ -253,8 +254,9 @@ static void have_sent(struct fetch_negotiator *n, struct commit *c)
static void release(struct fetch_negotiator *n)
{
struct data *data = n->data;
for (size_t i = 0; i < data->rev_list.nr; i++)
free(data->rev_list.array[i].data);
void *entry;
prio_queue_for_each(&data->rev_list, entry)
free(entry);
clear_prio_queue(&data->rev_list);
FREE_AND_NULL(data);
}
Expand Down
2 changes: 1 addition & 1 deletion object-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ static int get_oid_oneline(struct repository *r,
l->item->object.flags |= ONELINE_SEEN;
prio_queue_put(&copy, l->item);
}
while (copy.nr) {
while (prio_queue_size(&copy)) {
const char *p, *buf;
struct commit *commit;
int matches;
Expand Down
Loading
Loading