diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-05-10 20:23:27 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-05-10 20:23:28 +0300 |
commit | e2abfa7212525daa24a52d9f53c45b736abb5dfe (patch) | |
tree | 955c71a79ebb32c86f1d09bbe181b914ecb13da6 /negotiator/default.c | |
parent | 07ac32fff94b245aec3e2b80efad0b5dada629cb (diff) | |
parent | 10e8a52ef11bbf260f0cb672d9b02b3cd9c780ca (diff) |
Merge branch 'hx/negotiator-non-recursive'
The implementation of the default "negotiator", used to find common
ancestor over the network for object tranfer, used to be recursive;
it was updated to be iterative to conserve stackspace usage.
* hx/negotiator-non-recursive:
negotiator/skipping: fix some problems in mark_common()
negotiator/default: avoid stack overflow
Diffstat (limited to 'negotiator/default.c')
-rw-r--r-- | negotiator/default.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/negotiator/default.c b/negotiator/default.c index 5cb2b1d204..9a5b696327 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -56,30 +56,49 @@ static int clear_marks(const char *refname, const struct object_id *oid, static void mark_common(struct negotiation_state *ns, struct commit *commit, int ancestors_only, int dont_parse) { - if (commit != NULL && !(commit->object.flags & COMMON)) { - struct object *o = (struct object *)commit; + struct prio_queue queue = { NULL }; + + if (!commit || (commit->object.flags & COMMON)) + return; + + prio_queue_put(&queue, commit); + if (!ancestors_only) { + commit->object.flags |= COMMON; - if (!ancestors_only) - o->flags |= COMMON; + if ((commit->object.flags & SEEN) && !(commit->object.flags & POPPED)) + ns->non_common_revs--; + } + while ((commit = prio_queue_get(&queue))) { + struct object *o = (struct object *)commit; if (!(o->flags & SEEN)) rev_list_push(ns, commit, SEEN); else { struct commit_list *parents; - if (!ancestors_only && !(o->flags & POPPED)) - ns->non_common_revs--; if (!o->parsed && !dont_parse) if (repo_parse_commit(the_repository, commit)) - return; + continue; for (parents = commit->parents; parents; - parents = parents->next) - mark_common(ns, parents->item, 0, - dont_parse); + parents = parents->next) { + struct commit *p = parents->item; + + if (p->object.flags & COMMON) + continue; + + p->object.flags |= COMMON; + + if ((p->object.flags & SEEN) && !(p->object.flags & POPPED)) + ns->non_common_revs--; + + prio_queue_put(&queue, parents->item); + } } } + + clear_prio_queue(&queue); } /* |