[Outreachy PATCH v3 1/2] remote: add repo_for_each_remote()
- From
- Okhuomon Ajayi <okhuomonajayi54@gmail.com>
- Date
- Oct 23, 2026, 21:15 UTC
- Message-ID
- <20261023211533.73433-2-okhuomonajayi54@gmail.com>
- In-Reply-To
- <20261023211533.73433-1-okhuomonajayi54@gmail.com>
for_each_remote() always reads the remotes of the_repository.
Add repo_for_each_remote(), which takes a repository, and turn for_each_remote() into a wrapper that passes the_repository. Callers that are given a repository, such as unique_tracking_name() in the next patch, can then use the remotes of that repository.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com> --- remote.c | 14 ++++++++++---- remote.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/remote.c b/remote.c index 71170f36a9..d18f39d19a 100644 --- a/remote.c +++ b/remote.c @@ -869,14 +869,15 @@ int remote_is_configured(struct remote *remote, int in_repo) return !!remote->origin; } -int for_each_remote(each_remote_fn fn, void *priv) +int repo_for_each_remote(struct repository *repo, + each_remote_fn fn, void *priv) { int i, result = 0; - read_config(the_repository, 0); - for (i = 0; i < the_repository->remote_state->remotes_nr && !result; + read_config(repo, 0); + for (i = 0; i < repo->remote_state->remotes_nr && !result; i++) { struct remote *remote = - the_repository->remote_state->remotes[i]; + repo->remote_state->remotes[i]; if (!remote) continue; result = fn(remote, priv); @@ -884,6 +885,11 @@ int for_each_remote(each_remote_fn fn, void *priv) return result; } +int for_each_remote(each_remote_fn fn, void *priv) +{ + return repo_for_each_remote(the_repository, fn, priv); +} + static void handle_duplicate(struct ref *ref1, struct ref *ref2) { if (strcmp(ref1->name, ref2->name)) { diff --git a/remote.h b/remote.h index cca02033b9..2a0bf416d9 100644 --- a/remote.h +++ b/remote.h @@ -140,6 +140,8 @@ int remote_is_configured(struct remote *remote, int in_repo); typedef int each_remote_fn(struct remote *remote, void *priv); /* iterate through struct remotes */ +int repo_for_each_remote(struct repository *repo, + each_remote_fn fn, void *priv); int for_each_remote(each_remote_fn fn, void *priv); int remote_has_url(struct remote *remote, const char *url);
-- 2.56.0