From: Okhuomon Ajayi Date: Sat, 17 Oct 2026 22:53:26 GMT Subject: [Outreachy PATCH] checkout: use repository parameter in unique_tracking_name Message-ID: <20261017225326.7827-1-okhuomonajayi54@gmail.com> The function uses the_repository to read configuration and look up the object ID of a tracking reference. Pass the repository to unique_tracking_name() and through tracking_name_data. Callers pass the_repository for now. This removes the need for USE_THE_REPOSITORY_VARIABLE in checkout.c. Signed-off-by: Okhuomon Ajayi --- builtin/checkout.c | 3 ++- builtin/worktree.c | 6 ++++-- checkout.c | 11 ++++++----- checkout.h | 4 +++- 4 files changed, 15 insertions(+), 9 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..f0fb40d48e 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,17 +50,19 @@ 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; 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.54.0