diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-09-12 10:41:21 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-09-12 10:41:21 -0700 |
| commit | da3799a67b48606f0ffc5154cdbc973224d7af66 (patch) | |
| tree | d1f1d8bf5901bea61a8c07f57986c3387dcf3658 /builtin | |
| parent | Merge branch 'tc/t0450-harden' (diff) | |
| parent | describe: use oidset in finish_depth_computation() (diff) | |
| download | git-da3799a67b48606f0ffc5154cdbc973224d7af66.tar.gz git-da3799a67b48606f0ffc5154cdbc973224d7af66.zip | |
Merge branch 'rs/describe-with-lazy-queue-and-oidset'
Instead of scanning for the remaining items to see if there are
still commits to be explored in the queue, use khash to remember
which items are still on the queue (an unacceptable alternative is
to reserve one object flag bits).
* rs/describe-with-lazy-queue-and-oidset:
describe: use oidset in finish_depth_computation()
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/describe.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/builtin/describe.c b/builtin/describe.c index fbe78ace66..9f4e26d7ff 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -24,6 +24,7 @@ #include "commit-slab.h" #include "wildmatch.h" #include "prio-queue.h" +#include "oidset.h" #define MAX_TAGS (FLAG_BITS - 1) #define DEFAULT_CANDIDATES 10 @@ -286,38 +287,47 @@ static void lazy_queue_clear(struct lazy_queue *queue) queue->get_pending = false; } -static bool all_have_flag(const struct lazy_queue *queue, unsigned flag) +static unsigned long finish_depth_computation(struct lazy_queue *queue, + struct possible_tag *best) { + unsigned long seen_commits = 0; + struct oidset unflagged = OIDSET_INIT; + 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 & flag)) - return false; + if (!(commit->object.flags & best->flag_within)) + oidset_insert(&unflagged, &commit->object.oid); } - return true; -} -static unsigned long finish_depth_computation(struct lazy_queue *queue, - struct possible_tag *best) -{ - unsigned long seen_commits = 0; while (!lazy_queue_empty(queue)) { struct commit *c = lazy_queue_get(queue); struct commit_list *parents = c->parents; seen_commits++; if (c->object.flags & best->flag_within) { - if (all_have_flag(queue, best->flag_within)) + if (!oidset_size(&unflagged)) break; - } else + } else { + oidset_remove(&unflagged, &c->object.oid); best->depth++; + } while (parents) { + unsigned seen, flag_before, flag_after; struct commit *p = parents->item; repo_parse_commit(the_repository, p); - if (!(p->object.flags & SEEN)) + seen = p->object.flags & SEEN; + if (!seen) lazy_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; + if (!seen && !flag_after) + oidset_insert(&unflagged, &p->object.oid); + if (seen && !flag_before && flag_after) + oidset_remove(&unflagged, &p->object.oid); parents = parents->next; } } + oidset_clear(&unflagged); return seen_commits; } |
