{"thread":{"id":"66682","subject":"[Outreachy PATCH] negotiator/default: stop using the_repository","startedAt":"2026-10-27T15:34:28Z","lastAt":"2026-11-03T15:50:38Z","messageCount":4,"participants":["Okhuomon Ajayi","Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"556521","messageId":"20261027153429.14131-1-okhuomonajayi54@gmail.com","threadId":"66682","inReplyTo":null,"subject":"[Outreachy PATCH] negotiator/default: stop using the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-10-27T15:34:28Z","receivedAt":"2026-10-27T15:34:28Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"The default negotiator uses the_repository to parse commits,\nclear marks, and walk refs. fetch_negotiator_init() already\nhas the repository but does not pass it down.\n\nGive default_negotiator_init() a repository parameter, store\nit on the negotiation state, and use it for those calls.\nclear_marks() receives the repository through its callback\ndata. Drop USE_THE_REPOSITORY_VARIABLE.\n\nSigned-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n---\n fetch-negotiator.c   |  2 +-\n negotiator/default.c | 26 +++++++++++++++-----------\n negotiator/default.h |  4 +++-\n 3 files changed, 19 insertions(+), 13 deletions(-)\n\ndiff --git a/fetch-negotiator.c b/fetch-negotiator.c\nindex be383367f5..1a2cf3f384 100644\n--- a/fetch-negotiator.c\n+++ b/fetch-negotiator.c\n@@ -19,7 +19,7 @@ void fetch_negotiator_init(struct repository *r,\n \t\treturn;\n \n \tcase FETCH_NEGOTIATION_CONSECUTIVE:\n-\t\tdefault_negotiator_init(negotiator);\n+\t\tdefault_negotiator_init(negotiator, r);\n \t\treturn;\n \t}\n }\ndiff --git a/negotiator/default.c b/negotiator/default.c\nindex 19cdf3808c..4684bed796 100644\n--- a/negotiator/default.c\n+++ b/negotiator/default.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"default.h\"\n #include \"../commit.h\"\n@@ -18,6 +16,7 @@\n static int marked;\n \n struct negotiation_state {\n+\tstruct repository *repo;\n \tstruct prio_queue rev_list;\n \tint non_common_revs;\n };\n@@ -28,7 +27,7 @@ static void rev_list_push(struct negotiation_state *ns,\n \tif (!(commit->object.flags & mark)) {\n \t\tcommit->object.flags |= mark;\n \n-\t\tif (repo_parse_commit(the_repository, commit))\n+\t\tif (repo_parse_commit(ns->repo, commit))\n \t\t\treturn;\n \n \t\tprio_queue_put(&ns->rev_list, commit);\n@@ -38,9 +37,10 @@ static void rev_list_push(struct negotiation_state *ns,\n \t}\n }\n \n-static int clear_marks(const struct reference *ref, void *cb_data UNUSED)\n+static int clear_marks(const struct reference *ref, void *cb_data)\n {\n-\tstruct object *o = deref_tag(the_repository, parse_object(the_repository, ref->oid),\n+\tstruct repository *r = cb_data;\n+\tstruct object *o = deref_tag(r, parse_object(r, ref->oid),\n \t\t\t\t     ref->name, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n@@ -78,7 +78,7 @@ static void mark_common(struct negotiation_state *ns, struct commit *commit,\n \t\t\tstruct commit_list *parents;\n \n \t\t\tif (!o->parsed && !dont_parse)\n-\t\t\t\tif (repo_parse_commit(the_repository, commit))\n+\t\t\t\tif (repo_parse_commit(ns->repo, commit))\n \t\t\t\t\tcontinue;\n \n \t\t\tfor (parents = commit->parents;\n@@ -119,7 +119,7 @@ static const struct object_id *get_rev(struct negotiation_state *ns)\n \t\tcommit = prio_queue_get(&ns->rev_list);\n \t\tif (!commit)\n \t\t\treturn NULL;\n-\t\trepo_parse_commit(the_repository, commit);\n+\t\trepo_parse_commit(ns->repo, commit);\n \t\tparents = commit->parents;\n \n \t\tcommit->object.flags |= POPPED;\n@@ -179,7 +179,9 @@ static int ack(struct fetch_negotiator *n, struct commit *c)\n \n static void have_sent(struct fetch_negotiator *n, struct commit *c)\n {\n-\tif (repo_parse_commit(the_repository, c))\n+\tstruct negotiation_state *ns = n->data;\n+\n+\tif (repo_parse_commit(ns->repo, c))\n \t\treturn;\n \tmark_common(n->data, c, 0, 0);\n }\n@@ -190,7 +192,8 @@ static void release(struct fetch_negotiator *n)\n \tFREE_AND_NULL(n->data);\n }\n \n-void default_negotiator_init(struct fetch_negotiator *negotiator)\n+void default_negotiator_init(struct fetch_negotiator *negotiator,\n+\t\t\t     struct repository *r)\n {\n \tstruct negotiation_state *ns;\n \tnegotiator->known_common = known_common;\n@@ -200,10 +203,11 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)\n \tnegotiator->have_sent = have_sent;\n \tnegotiator->release = release;\n \tnegotiator->data = CALLOC_ARRAY(ns, 1);\n+\tns->repo = r;\n \tns->rev_list.compare = compare_commits_by_commit_date;\n \n \tif (marked)\n-\t\trefs_for_each_ref(get_main_ref_store(the_repository),\n-\t\t\t\t  clear_marks, NULL);\n+\t\trefs_for_each_ref(get_main_ref_store(r),\n+\t\t\t\t  clear_marks, r);\n \tmarked = 1;\n }\ndiff --git a/negotiator/default.h b/negotiator/default.h\nindex d23a8f2fb8..bd998eb32e 100644\n--- a/negotiator/default.h\n+++ b/negotiator/default.h\n@@ -2,7 +2,9 @@\n #define NEGOTIATOR_DEFAULT_H\n \n struct fetch_negotiator;\n+struct repository;\n \n-void default_negotiator_init(struct fetch_negotiator *negotiator);\n+void default_negotiator_init(struct fetch_negotiator *negotiator,\n+\t\t\t     struct repository *r);\n \n #endif\n\nbase-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e\n-- \n2.56.0\n\n\n"},{"id":"557301","messageId":"CAP8UFD1BW7qEWp87j+7B12d=eOu80Yv1=Gf+ibEriV9s=4umag@mail.gmail.com","threadId":"66682","inReplyTo":"20261027153429.14131-1-okhuomonajayi54@gmail.com","subject":"Re: [Outreachy PATCH] negotiator/default: stop using the_repository","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-03T11:50:12Z","receivedAt":"2026-11-03T11:50:12Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Tue, Oct 27, 2026 at 4:37 PM Okhuomon Ajayi\n<okhuomonajayi54@gmail.com> wrote:\n\n>  static void have_sent(struct fetch_negotiator *n, struct commit *c)\n>  {\n> -       if (repo_parse_commit(the_repository, c))\n> +       struct negotiation_state *ns = n->data;\n> +\n> +       if (repo_parse_commit(ns->repo, c))\n>                 return;\n>         mark_common(n->data, c, 0, 0);\n\nAs you introduced `ns`, you might use it to simplify the above line using:\n\n         mark_common(ns, c, 0, 0);\n>  }\n\n[...]\n\n> -void default_negotiator_init(struct fetch_negotiator *negotiator);\n> +void default_negotiator_init(struct fetch_negotiator *negotiator,\n> +                            struct repository *r);\n\nMany functions have their `struct repository *r` argument as their\nfirst argument. Is there a reason why you prefered to have it as the\nsecond argument?\n\nThanks.\n\n"},{"id":"557304","messageId":"CAFpMFfDeGJGbdCx-boKAe_Ab6oPuW-aunrdqAjtSkgqgWyhqrw@mail.gmail.com","threadId":"66682","inReplyTo":"CAP8UFD1BW7qEWp87j+7B12d=eOu80Yv1=Gf+ibEriV9s=4umag@mail.gmail.com","subject":"Re: [Outreachy PATCH] negotiator/default: stop using the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-11-03T12:12:17Z","receivedAt":"2026-11-03T12:12:17Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"On Tue, Nov 3, 2026 at 12:50 PM Christian Couder\n<christian.couder@gmail.com> wrote:\n> As you introduced `ns`, you might use it to simplify the above line using:\n>\n>          mark_common(ns, c, 0, 0);\n\n\nGood point. I'll make that change in the next version.\n\n> Many functions have their `struct repository *r` argument as their\n> first argument. Is there a reason why you prefered to have it as the\n> second argument?\n\n\nNo particular reason. I'll put the repository argument first in the\nnext version.\n\nThanks!\n\n"},{"id":"557326","messageId":"20261103155038.87456-1-okhuomonajayi54@gmail.com","threadId":"66682","inReplyTo":"20261027153429.14131-1-okhuomonajayi54@gmail.com","subject":"[Outreachy PATCH v2] negotiator/default: stop using the_repository","fromName":"Okhuomon Ajayi","fromEmail":"okhuomonajayi54@gmail.com","sentAt":"2026-11-03T15:50:38Z","receivedAt":"2026-11-03T15:50:38Z","isPatch":true,"sender":{"key":"okhuomonajayi54@gmail.com","avatar":null},"body":"The default negotiator uses the_repository to parse commits,\nclear marks, and walk refs. fetch_negotiator_init() already\nhas the repository but does not pass it down.\n\nGive default_negotiator_init() a repository parameter, store\nit on the negotiation state, and use it for those calls.\nclear_marks() receives the repository through its callback\ndata. Drop USE_THE_REPOSITORY_VARIABLE.\n\nSigned-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>\n---\nChanges since v1:\n- Put the repository first in default_negotiator_init(), as\n  Christian suggested.\n- Pass ns to mark_common() in have_sent().\n\nThanks, Christian, for the review.\n\n fetch-negotiator.c   |  2 +-\n negotiator/default.c | 28 ++++++++++++++++------------\n negotiator/default.h |  4 +++-\n 3 files changed, 20 insertions(+), 14 deletions(-)\n\ndiff --git a/fetch-negotiator.c b/fetch-negotiator.c\nindex be383367f5..a5183bb3bc 100644\n--- a/fetch-negotiator.c\n+++ b/fetch-negotiator.c\n@@ -19,7 +19,7 @@ void fetch_negotiator_init(struct repository *r,\n \t\treturn;\n \n \tcase FETCH_NEGOTIATION_CONSECUTIVE:\n-\t\tdefault_negotiator_init(negotiator);\n+\t\tdefault_negotiator_init(r, negotiator);\n \t\treturn;\n \t}\n }\ndiff --git a/negotiator/default.c b/negotiator/default.c\nindex 19cdf3808c..f7cb52f10c 100644\n--- a/negotiator/default.c\n+++ b/negotiator/default.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"default.h\"\n #include \"../commit.h\"\n@@ -18,6 +16,7 @@\n static int marked;\n \n struct negotiation_state {\n+\tstruct repository *repo;\n \tstruct prio_queue rev_list;\n \tint non_common_revs;\n };\n@@ -28,7 +27,7 @@ static void rev_list_push(struct negotiation_state *ns,\n \tif (!(commit->object.flags & mark)) {\n \t\tcommit->object.flags |= mark;\n \n-\t\tif (repo_parse_commit(the_repository, commit))\n+\t\tif (repo_parse_commit(ns->repo, commit))\n \t\t\treturn;\n \n \t\tprio_queue_put(&ns->rev_list, commit);\n@@ -38,9 +37,10 @@ static void rev_list_push(struct negotiation_state *ns,\n \t}\n }\n \n-static int clear_marks(const struct reference *ref, void *cb_data UNUSED)\n+static int clear_marks(const struct reference *ref, void *cb_data)\n {\n-\tstruct object *o = deref_tag(the_repository, parse_object(the_repository, ref->oid),\n+\tstruct repository *r = cb_data;\n+\tstruct object *o = deref_tag(r, parse_object(r, ref->oid),\n \t\t\t\t     ref->name, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n@@ -78,7 +78,7 @@ static void mark_common(struct negotiation_state *ns, struct commit *commit,\n \t\t\tstruct commit_list *parents;\n \n \t\t\tif (!o->parsed && !dont_parse)\n-\t\t\t\tif (repo_parse_commit(the_repository, commit))\n+\t\t\t\tif (repo_parse_commit(ns->repo, commit))\n \t\t\t\t\tcontinue;\n \n \t\t\tfor (parents = commit->parents;\n@@ -119,7 +119,7 @@ static const struct object_id *get_rev(struct negotiation_state *ns)\n \t\tcommit = prio_queue_get(&ns->rev_list);\n \t\tif (!commit)\n \t\t\treturn NULL;\n-\t\trepo_parse_commit(the_repository, commit);\n+\t\trepo_parse_commit(ns->repo, commit);\n \t\tparents = commit->parents;\n \n \t\tcommit->object.flags |= POPPED;\n@@ -179,9 +179,11 @@ static int ack(struct fetch_negotiator *n, struct commit *c)\n \n static void have_sent(struct fetch_negotiator *n, struct commit *c)\n {\n-\tif (repo_parse_commit(the_repository, c))\n+\tstruct negotiation_state *ns = n->data;\n+\n+\tif (repo_parse_commit(ns->repo, c))\n \t\treturn;\n-\tmark_common(n->data, c, 0, 0);\n+\tmark_common(ns, c, 0, 0);\n }\n \n static void release(struct fetch_negotiator *n)\n@@ -190,7 +192,8 @@ static void release(struct fetch_negotiator *n)\n \tFREE_AND_NULL(n->data);\n }\n \n-void default_negotiator_init(struct fetch_negotiator *negotiator)\n+void default_negotiator_init(struct repository *r,\n+\t\t\t     struct fetch_negotiator *negotiator)\n {\n \tstruct negotiation_state *ns;\n \tnegotiator->known_common = known_common;\n@@ -200,10 +203,11 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)\n \tnegotiator->have_sent = have_sent;\n \tnegotiator->release = release;\n \tnegotiator->data = CALLOC_ARRAY(ns, 1);\n+\tns->repo = r;\n \tns->rev_list.compare = compare_commits_by_commit_date;\n \n \tif (marked)\n-\t\trefs_for_each_ref(get_main_ref_store(the_repository),\n-\t\t\t\t  clear_marks, NULL);\n+\t\trefs_for_each_ref(get_main_ref_store(r),\n+\t\t\t\t  clear_marks, r);\n \tmarked = 1;\n }\ndiff --git a/negotiator/default.h b/negotiator/default.h\nindex d23a8f2fb8..98bc989cff 100644\n--- a/negotiator/default.h\n+++ b/negotiator/default.h\n@@ -2,7 +2,9 @@\n #define NEGOTIATOR_DEFAULT_H\n \n struct fetch_negotiator;\n+struct repository;\n \n-void default_negotiator_init(struct fetch_negotiator *negotiator);\n+void default_negotiator_init(struct repository *r,\n+\t\t\t     struct fetch_negotiator *negotiator);\n \n #endif\n\nbase-commit: 7e34d8174dcda3435d1404c9a30bef46afe6c13e\n-- \n2.56.0\n\n\n"}]}