]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: move remote group resolution to remote.c
authorUsman Akinyemi <usmanakinyemi202@gmail.com>
Wed, 25 Mar 2026 19:09:05 +0000 (00:39 +0530)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Mar 2026 19:35:15 +0000 (12:35 -0700)
`get_remote_group`, `add_remote_or_group`, and the `remote_group_data`
struct are currently defined as static helpers inside builtin/fetch.c.
They implement generic remote group resolution that is not specific to
fetch — they parse `remotes.<name>` config entries and resolve a name
to either a list of group members or a single configured remote.

Move them to remote.c and declare them in remote.h so that other
builtins can use the same logic without duplication.

Useful for the next patch.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
remote.c
remote.h

index 8a36cf67b5f140e957c7497aeffd8d6e58bc1389..966cc58f73015078375febad97d6ca7bdd6bd1f1 100644 (file)
@@ -2138,48 +2138,6 @@ static int get_one_remote_for_fetch(struct remote *remote, void *priv)
        return 0;
 }
 
-struct remote_group_data {
-       const char *name;
-       struct string_list *list;
-};
-
-static int get_remote_group(const char *key, const char *value,
-                           const struct config_context *ctx UNUSED,
-                           void *priv)
-{
-       struct remote_group_data *g = priv;
-
-       if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) {
-               /* split list by white space */
-               while (*value) {
-                       size_t wordlen = strcspn(value, " \t\n");
-
-                       if (wordlen >= 1)
-                               string_list_append_nodup(g->list,
-                                                  xstrndup(value, wordlen));
-                       value += wordlen + (value[wordlen] != '\0');
-               }
-       }
-
-       return 0;
-}
-
-static int add_remote_or_group(const char *name, struct string_list *list)
-{
-       int prev_nr = list->nr;
-       struct remote_group_data g;
-       g.name = name; g.list = list;
-
-       repo_config(the_repository, get_remote_group, &g);
-       if (list->nr == prev_nr) {
-               struct remote *remote = remote_get(name);
-               if (!remote_is_configured(remote, 0))
-                       return 0;
-               string_list_append(list, remote->name);
-       }
-       return 1;
-}
-
 static void add_options_to_argv(struct strvec *argv,
                                const struct fetch_config *config)
 {
index 7ca2a6501b4920587c86b70520358b55c58c6bdc..3d62384792c3231955dea80295b851b76af8b9ab 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -2114,6 +2114,43 @@ int get_fetch_map(const struct ref *remote_refs,
        return 0;
 }
 
+int get_remote_group(const char *key, const char *value,
+                           const struct config_context *ctx UNUSED,
+                           void *priv)
+{
+       struct remote_group_data *g = priv;
+
+       if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) {
+               /* split list by white space */
+               while (*value) {
+                       size_t wordlen = strcspn(value, " \t\n");
+
+                       if (wordlen >= 1)
+                               string_list_append_nodup(g->list,
+                                                  xstrndup(value, wordlen));
+                       value += wordlen + (value[wordlen] != '\0');
+               }
+       }
+
+       return 0;
+}
+
+int add_remote_or_group(const char *name, struct string_list *list)
+{
+       int prev_nr = list->nr;
+       struct remote_group_data g;
+       g.name = name; g.list = list;
+
+       repo_config(the_repository, get_remote_group, &g);
+       if (list->nr == prev_nr) {
+               struct remote *remote = remote_get(name);
+               if (!remote_is_configured(remote, 0))
+                       return 0;
+               string_list_append(list, remote->name);
+       }
+       return 1;
+}
+
 int resolve_remote_symref(struct ref *ref, struct ref *list)
 {
        if (!ref->symref)
index fc052945ee451d35510fe90404c6a7dcd0ab5b0e..8ff2bd88fa1b299e991ce5b90340f6fed53f895b 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -347,6 +347,18 @@ int branch_has_merge_config(struct branch *branch);
 
 int branch_merge_matches(struct branch *, int n, const char *);
 
+/* list of the remote in a group as configured */
+struct remote_group_data {
+       const char *name;
+       struct string_list *list;
+};
+
+int get_remote_group(const char *key, const char *value,
+                    const struct config_context *ctx,
+                    void *priv);
+
+int add_remote_or_group(const char *name, struct string_list *list);
+
 /**
  * Return the fully-qualified refname of the tracking branch for `branch`.
  * I.e., what "branch@{upstream}" would give you. Returns NULL if no