Git development
 help / color / mirror / Atom feed
From: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, christian.couder@gmail.com,
	usmanakinyemi202@gmail.com, siddharthasthana31@gmail.com,
	kaartic.sivaraam@gmail.com,
	Okhuomon Ajayi <okhuomonajayi54@gmail.com>
Subject: [Outreachy PATCH v3 1/2] remote: add repo_for_each_remote()
Date: Fri, 23 Oct 2026 22:15:32 +0100	[thread overview]
Message-ID: <20261023211533.73433-2-okhuomonajayi54@gmail.com> (raw)
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


  reply	other threads:[~2026-10-23 21:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17 22:53 [Outreachy PATCH] checkout: use repository parameter in unique_tracking_name Okhuomon Ajayi
2026-10-22  9:41 ` Usman Akinyemi
2026-10-22 10:26   ` Okhuomon Ajayi
2026-10-22 10:56 ` [Outreachy PATCH v2] checkout: pass the repository to unique_tracking_name() Okhuomon Ajayi
2026-10-22 18:51   ` Junio C Hamano
2026-10-22 19:30     ` Junio C Hamano
2026-10-22 21:23     ` Okhuomon Ajayi
2026-10-23 21:15   ` [Outreachy PATCH v3 0/2] checkout: make unique_tracking_name() use the given repository Okhuomon Ajayi
2026-10-23 21:15     ` Okhuomon Ajayi [this message]
2026-10-23 21:15     ` [Outreachy PATCH v3 2/2] checkout: pass the repository to unique_tracking_name() Okhuomon Ajayi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261023211533.73433-2-okhuomonajayi54@gmail.com \
    --to=okhuomonajayi54@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=siddharthasthana31@gmail.com \
    --cc=usmanakinyemi202@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox