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

[Outreachy PATCH v4 2/2] checkout: pass the repository to unique_tracking_name()

From
OAOkhuomon Ajayi <okhuomonajayi54@gmail.com>
Date
Nov 4, 2026, 09:05 UTC
Message-ID
<20261104090534.21838-3-okhuomonajayi54@gmail.com>
In-Reply-To
<20261104090534.21838-1-okhuomonajayi54@gmail.com>

unique_tracking_name() uses the_repository to read the "checkout.defaultRemote" configuration and look up the object ID of a remote-tracking branch.

Pass the repository to unique_tracking_name() and through tracking_name_data so check_tracking_name() can use it for the object lookup, and use repo_for_each_remote() so the remotes are also read from that repository. Update the three callers to pass the_repository.

This removes the need for USE_THE_REPOSITORY_VARIABLE in checkout.c.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/checkout.c |  3 ++-
 builtin/worktree.c |  6 ++++--
 checkout.c         | 13 +++++++------
 checkout.h         |  4 +++-
 4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2d575a4f57..bad49368b9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1389,7 +1389,8 @@ static char *parse_remote_branch(const char *arg,
 	int num_matches = 0;
 	struct string_list matched_remote_names = STRING_LIST_INIT_DUP;
 
-	char *remote = unique_tracking_name(arg, rev, &num_matches,
+	char *remote = unique_tracking_name(the_repository, arg, rev,
+					    &num_matches,
 					    &matched_remote_names);
 
 	if (remote && could_be_checkout_paths) {
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 77ecd0f71f..203456bd23 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -802,7 +802,8 @@ static char *dwim_branch(const struct add_opts *opts, const char *path, char **n
 		int num_matches = 0;
 		struct string_list matched_remote_names = STRING_LIST_INIT_DUP;
 
-		remote = unique_tracking_name(*new_branch, &oid, &num_matches,
+		remote = unique_tracking_name(the_repository, *new_branch,
+					      &oid, &num_matches,
 					      &matched_remote_names);
 		if (!remote && num_matches > 1) {
 			if (!opts->quiet &&
@@ -938,7 +939,8 @@ static int add(int ac, const char **av, const char *prefix,
 			int num_matches = 0;
 			struct string_list matched_remote_names = STRING_LIST_INIT_DUP;
 
-			remote = unique_tracking_name(branch, &oid, &num_matches,
+			remote = unique_tracking_name(the_repository, branch,
+						      &oid, &num_matches,
 						      &matched_remote_names);
 			if (remote) {
 				new_branch = branch;
diff --git a/checkout.c b/checkout.c
index a0d0229435..8a4812df8d 100644
--- a/checkout.c
+++ b/checkout.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "object-name.h"
 #include "remote.h"
@@ -11,6 +9,7 @@
 #include "string-list.h"
 
 struct tracking_name_data {
+	struct repository *repo;
 	/* const */ char *src_ref;
 	char *dst_ref;
 	struct object_id *dst_oid;
@@ -30,7 +29,7 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
 	memset(&query, 0, sizeof(struct refspec_item));
 	query.src = cb->src_ref;
 	if (remote_find_tracking(remote, &query) ||
-	    repo_get_oid(the_repository, query.dst, cb->dst_oid)) {
+	    repo_get_oid(cb->repo, query.dst, cb->dst_oid)) {
 		free(query.dst);
 		return 0;
 	}
@@ -51,21 +50,23 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
 	return 0;
 }
 
-char *unique_tracking_name(const char *name, struct object_id *oid,
+char *unique_tracking_name(struct repository *repo,
+			   const char *name, struct object_id *oid,
 			   int *dwim_remotes_matched,
 			   struct string_list *dwim_remote_names)
 {
 	struct tracking_name_data cb_data = TRACKING_NAME_DATA_INIT;
 	const char *default_remote = NULL;
 
-	if (!repo_config_get_string_tmp(the_repository,
+	if (!repo_config_get_string_tmp(repo,
 					"checkout.defaultremote",
 					&default_remote))
 		cb_data.default_remote = default_remote;
+	cb_data.repo = repo;
 	cb_data.src_ref = xstrfmt("refs/heads/%s", name);
 	cb_data.dst_oid = oid;
 	cb_data.remote_names = dwim_remote_names;
-	for_each_remote(check_tracking_name, &cb_data);
+	repo_for_each_remote(repo, check_tracking_name, &cb_data);
 	if (dwim_remotes_matched)
 		*dwim_remotes_matched = cb_data.num_matches;
 	free(cb_data.src_ref);
diff --git a/checkout.h b/checkout.h
index 0b185a0fc9..25fe7dfb7c 100644
--- a/checkout.h
+++ b/checkout.h
@@ -3,6 +3,7 @@
 
 #include "hash.h"
 
+struct repository;
 struct string_list;
 
 /*
@@ -10,7 +11,8 @@ struct string_list;
  * tracking branch.  Return the name of the remote if such a branch
  * exists, NULL otherwise.
  */
-char *unique_tracking_name(const char *name,
+char *unique_tracking_name(struct repository *repo,
+			   const char *name,
 			   struct object_id *oid,
 			   int *dwim_remotes_matched,
 			   struct string_list *dwim_remote_names);
-- 
2.56.0
Previous: Okhuomon Ajayi
Message 14 of 14 in “checkout: use repository parameter in unique_tracking_name”
  1. checkout: use repository parameter in unique_tracking_nameOkhuomon Ajayi, Oct 17, 2026
  2. Usman AkinyemiOct 22, 2026
  3. Okhuomon AjayiOct 22, 2026
  4. checkout: pass the repository to unique_tracking_name()Okhuomon Ajayi, Oct 22, 2026
  5. Junio C HamanoOct 22, 2026
  6. Junio C HamanoOct 22, 2026
  7. Okhuomon AjayiOct 22, 2026
  8. 0/2 checkout: make unique_tracking_name() use the given repositoryOkhuomon Ajayi, Oct 23, 2026
  9. 1/2 remote: add repo_for_each_remote()Okhuomon Ajayi, Oct 23, 2026
  10. Christian CouderNov 3, 2026
  11. 2/2 checkout: pass the repository to unique_tracking_name()Okhuomon Ajayi, Oct 23, 2026
  12. 0/2 checkout: make unique_tracking_name() use the given repositoryOkhuomon Ajayi, Nov 4, 2026
  13. 1/2 remote: add repo_for_each_remote()Okhuomon Ajayi, Nov 4, 2026
  14. 2/2 checkout: pass the repository to unique_tracking_name()Okhuomon Ajayi, Nov 4, 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.