From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Harald Nordgren <haraldnordgren@gmail.com>,
Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH 1/2] remote: factor out lookup of a remote by name
Date: Fri, 02 Oct 2026 07:17:51 +0000 [thread overview]
Message-ID: <db46b1b51009ec2f9a61cc76f9a2835cd207aeda.1790925472.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2423.git.git.1790925472.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>
make_remote() looks up an existing remote in the hashmap before
creating a new one. Move that lookup into find_remote() so that code
which only wants to know whether a remote is configured can use it
without creating an entry.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
remote.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/remote.c b/remote.c
index fe62068463..6567ec91cc 100644
--- a/remote.c
+++ b/remote.c
@@ -128,23 +128,28 @@ static int remotes_hash_cmp(const void *cmp_data UNUSED,
return strcmp(a->name, b->name);
}
+static struct remote *find_remote(struct remote_state *remote_state,
+ const char *name, int len)
+{
+ struct remotes_hash_key lookup = { .str = name, .len = len };
+ struct hashmap_entry lookup_entry, *e;
+
+ hashmap_entry_init(&lookup_entry, memhash(name, len));
+ e = hashmap_get(&remote_state->remotes_hash, &lookup_entry, &lookup);
+ return e ? container_of(e, struct remote, ent) : NULL;
+}
+
static struct remote *make_remote(struct remote_state *remote_state,
const char *name, int len)
{
struct remote *ret;
- struct remotes_hash_key lookup;
- struct hashmap_entry lookup_entry, *e;
if (!len)
len = strlen(name);
- lookup.str = name;
- lookup.len = len;
- hashmap_entry_init(&lookup_entry, memhash(name, len));
-
- e = hashmap_get(&remote_state->remotes_hash, &lookup_entry, &lookup);
- if (e)
- return container_of(e, struct remote, ent);
+ ret = find_remote(remote_state, name, len);
+ if (ret)
+ return ret;
CALLOC_ARRAY(ret, 1);
ret->prune = -1; /* unspecified */
@@ -160,7 +165,7 @@ static struct remote *make_remote(struct remote_state *remote_state,
remote_state->remotes_alloc);
remote_state->remotes[remote_state->remotes_nr++] = ret;
- hashmap_entry_init(&ret->ent, lookup_entry.hash);
+ hashmap_entry_init(&ret->ent, memhash(name, len));
if (hashmap_put_entry(&remote_state->remotes_hash, ret, ent))
BUG("hashmap_put overwrote entry after hashmap_get returned NULL");
return ret;
--
gitgitgadget
next prev parent reply other threads:[~2026-10-02 7:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 7:17 [PATCH 0/2] remote: allow a list of remotes in remote.pushDefault Harald Nordgren via GitGitGadget
2026-10-02 7:17 ` Harald Nordgren via GitGitGadget [this message]
2026-10-02 7:17 ` [PATCH 2/2] " Harald Nordgren via GitGitGadget
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=db46b1b51009ec2f9a61cc76f9a2835cd207aeda.1790925472.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@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