[Outreachy PATCH v4 1/2] remote: add repo_for_each_remote()
- From
- Okhuomon Ajayi <okhuomonajayi54@gmail.com>
- Date
- Nov 4, 2026, 09:05 UTC
- Message-ID
- <20261104090534.21838-2-okhuomonajayi54@gmail.com>
- In-Reply-To
- <20261104090534.21838-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 | 18 +++++++++++------- remote.h | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/remote.c b/remote.c index 71170f36a9..f070ad5a01 100644 --- a/remote.c +++ b/remote.c @@ -869,14 +869,13 @@ 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; - i++) { - struct remote *remote = - the_repository->remote_state->remotes[i]; + int result = 0; + read_config(repo, 0); + for (int i = 0; i < repo->remote_state->remotes_nr && !result; i++) { + struct remote *remote = repo->remote_state->remotes[i]; if (!remote) continue; result = fn(remote, priv); @@ -884,6 +883,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