From: Okhuomon Ajayi Date: Tue, 27 Oct 2026 15:34:28 GMT Subject: [Outreachy PATCH] negotiator/default: stop using the_repository Message-ID: <20261027153429.14131-1-okhuomonajayi54@gmail.com> The default negotiator uses the_repository to parse commits, clear marks, and walk refs. fetch_negotiator_init() already has the repository but does not pass it down. Give default_negotiator_init() a repository parameter, store it on the negotiation state, and use it for those calls. clear_marks() receives the repository through its callback data. Drop USE_THE_REPOSITORY_VARIABLE. Signed-off-by: Okhuomon Ajayi --- fetch-negotiator.c | 2 +- negotiator/default.c | 26 +++++++++++++++----------- negotiator/default.h | 4 +++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/fetch-negotiator.c b/fetch-negotiator.c index be383367f5..1a2cf3f384 100644 --- a/fetch-negotiator.c +++ b/fetch-negotiator.c @@ -19,7 +19,7 @@ void fetch_negotiator_init(struct repository *r, return; case FETCH_NEGOTIATION_CONSECUTIVE: - default_negotiator_init(negotiator); + default_negotiator_init(negotiator, r); return; } } diff --git a/negotiator/default.c b/negotiator/default.c index 19cdf3808c..4684bed796 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "default.h" #include "../commit.h" @@ -18,6 +16,7 @@ static int marked; struct negotiation_state { + struct repository *repo; struct prio_queue rev_list; int non_common_revs; }; @@ -28,7 +27,7 @@ static void rev_list_push(struct negotiation_state *ns, if (!(commit->object.flags & mark)) { commit->object.flags |= mark; - if (repo_parse_commit(the_repository, commit)) + if (repo_parse_commit(ns->repo, commit)) return; prio_queue_put(&ns->rev_list, commit); @@ -38,9 +37,10 @@ static void rev_list_push(struct negotiation_state *ns, } } -static int clear_marks(const struct reference *ref, void *cb_data UNUSED) +static int clear_marks(const struct reference *ref, void *cb_data) { - struct object *o = deref_tag(the_repository, parse_object(the_repository, ref->oid), + struct repository *r = cb_data; + struct object *o = deref_tag(r, parse_object(r, ref->oid), ref->name, 0); if (o && o->type == OBJ_COMMIT) @@ -78,7 +78,7 @@ static void mark_common(struct negotiation_state *ns, struct commit *commit, struct commit_list *parents; if (!o->parsed && !dont_parse) - if (repo_parse_commit(the_repository, commit)) + if (repo_parse_commit(ns->repo, commit)) continue; for (parents = commit->parents; @@ -119,7 +119,7 @@ static const struct object_id *get_rev(struct negotiation_state *ns) commit = prio_queue_get(&ns->rev_list); if (!commit) return NULL; - repo_parse_commit(the_repository, commit); + repo_parse_commit(ns->repo, commit); parents = commit->parents; commit->object.flags |= POPPED; @@ -179,7 +179,9 @@ static int ack(struct fetch_negotiator *n, struct commit *c) static void have_sent(struct fetch_negotiator *n, struct commit *c) { - if (repo_parse_commit(the_repository, c)) + struct negotiation_state *ns = n->data; + + if (repo_parse_commit(ns->repo, c)) return; mark_common(n->data, c, 0, 0); } @@ -190,7 +192,8 @@ static void release(struct fetch_negotiator *n) FREE_AND_NULL(n->data); } -void default_negotiator_init(struct fetch_negotiator *negotiator) +void default_negotiator_init(struct fetch_negotiator *negotiator, + struct repository *r) { struct negotiation_state *ns; negotiator->known_common = known_common; @@ -200,10 +203,11 @@ void default_negotiator_init(struct fetch_negotiator *negotiator) negotiator->have_sent = have_sent; negotiator->release = release; negotiator->data = CALLOC_ARRAY(ns, 1); + ns->repo = r; ns->rev_list.compare = compare_commits_by_commit_date; if (marked) - refs_for_each_ref(get_main_ref_store(the_repository), - clear_marks, NULL); + refs_for_each_ref(get_main_ref_store(r), + clear_marks, r); marked = 1; } diff --git a/negotiator/default.h b/negotiator/default.h index d23a8f2fb8..bd998eb32e 100644 --- a/negotiator/default.h +++ b/negotiator/default.h @@ -2,7 +2,9 @@ #define NEGOTIATOR_DEFAULT_H struct fetch_negotiator; +struct repository; -void default_negotiator_init(struct fetch_negotiator *negotiator); +void default_negotiator_init(struct fetch_negotiator *negotiator, + struct repository *r); #endif base-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e -- 2.56.0