diff options
author | Taylor Blau <me@ttaylorr.com> | 2022-10-31 04:04:44 +0300 |
---|---|---|
committer | Taylor Blau <me@ttaylorr.com> | 2022-10-31 04:04:44 +0300 |
commit | 2f503ee0d7bcddabed697439cfbe0b74966a4dec (patch) | |
tree | 0a93359fb8a8a627cf484d5a9240f425bd51b27e /negotiator | |
parent | 1e230dfd6c12c896eb85192197fcc15d627fcf84 (diff) | |
parent | 4654134976fd4d80ea664c159f798f21c7917d8c (diff) |
Merge branch 'jt/skipping-negotiator-wo-recursion'
Rewrite a deep recursion in the skipping negotiator to use a loop
with on-heap prio queue to avoid stack wastage.
* jt/skipping-negotiator-wo-recursion:
negotiator/skipping: avoid stack overflow
Diffstat (limited to 'negotiator')
-rw-r--r-- | negotiator/skipping.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/negotiator/skipping.c b/negotiator/skipping.c index c4398f5ae1..0f5ac48e87 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -86,21 +86,26 @@ static int clear_marks(const char *refname, const struct object_id *oid, /* * Mark this SEEN commit and all its SEEN ancestors as COMMON. */ -static void mark_common(struct data *data, struct commit *c) +static void mark_common(struct data *data, struct commit *seen_commit) { - struct commit_list *p; + struct prio_queue queue = { NULL }; + struct commit *c; - if (c->object.flags & COMMON) - return; - c->object.flags |= COMMON; - if (!(c->object.flags & POPPED)) - data->non_common_revs--; + prio_queue_put(&queue, seen_commit); + while ((c = prio_queue_get(&queue))) { + struct commit_list *p; + if (c->object.flags & COMMON) + return; + c->object.flags |= COMMON; + if (!(c->object.flags & POPPED)) + data->non_common_revs--; - if (!c->object.parsed) - return; - for (p = c->parents; p; p = p->next) { - if (p->item->object.flags & SEEN) - mark_common(data, p->item); + if (!c->object.parsed) + return; + for (p = c->parents; p; p = p->next) { + if (p->item->object.flags & SEEN) + prio_queue_put(&queue, p->item); + } } } |