git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[Outreachy PATCH v2] negotiator/default: stop using the_repository

From
OAOkhuomon Ajayi <okhuomonajayi54@gmail.com>
Date
Nov 3, 2026, 15:50 UTC
Message-ID
<20261103155038.87456-1-okhuomonajayi54@gmail.com>
In-Reply-To
<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 <okhuomonajayi54@gmail.com>
---
Changes since v1:
- Put the repository first in default_negotiator_init(), as
  Christian suggested.
- Pass ns to mark_common() in have_sent().
Thanks, Christian, for the review.
 fetch-negotiator.c   |  2 +-
 negotiator/default.c | 28 ++++++++++++++++------------
 negotiator/default.h |  4 +++-
 3 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/fetch-negotiator.c b/fetch-negotiator.c
index be383367f5..a5183bb3bc 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(r, negotiator);
 		return;
 	}
 }
diff --git a/negotiator/default.c b/negotiator/default.c
index 19cdf3808c..f7cb52f10c 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,9 +179,11 @@ 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);
+	mark_common(ns, c, 0, 0);
 }
 
 static void release(struct fetch_negotiator *n)
@@ -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 repository *r,
+			     struct fetch_negotiator *negotiator)
 {
 	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..98bc989cff 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 repository *r,
+			     struct fetch_negotiator *negotiator);
 
 #endif

base-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e
-- 
2.56.0
Previous: Okhuomon Ajayi
Message 4 of 4 in “negotiator/default: stop using the_repository”
  1. negotiator/default: stop using the_repositoryOkhuomon Ajayi, Oct 27, 2026
  2. Christian CouderNov 3, 2026
  3. Okhuomon AjayiNov 3, 2026
  4. negotiator/default: stop using the_repositoryOkhuomon Ajayi, Nov 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.