Skip to content

Commit 1a2e5b7

Browse files
committed
remote: preparatory patches
Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
1 parent 2cc7191 commit 1a2e5b7

3 files changed

Lines changed: 49 additions & 42 deletions

File tree

builtin/fetch.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,48 +2135,6 @@ static int get_one_remote_for_fetch(struct remote *remote, void *priv)
21352135
return 0;
21362136
}
21372137

2138-
struct remote_group_data {
2139-
const char *name;
2140-
struct string_list *list;
2141-
};
2142-
2143-
static int get_remote_group(const char *key, const char *value,
2144-
const struct config_context *ctx UNUSED,
2145-
void *priv)
2146-
{
2147-
struct remote_group_data *g = priv;
2148-
2149-
if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) {
2150-
/* split list by white space */
2151-
while (*value) {
2152-
size_t wordlen = strcspn(value, " \t\n");
2153-
2154-
if (wordlen >= 1)
2155-
string_list_append_nodup(g->list,
2156-
xstrndup(value, wordlen));
2157-
value += wordlen + (value[wordlen] != '\0');
2158-
}
2159-
}
2160-
2161-
return 0;
2162-
}
2163-
2164-
static int add_remote_or_group(const char *name, struct string_list *list)
2165-
{
2166-
int prev_nr = list->nr;
2167-
struct remote_group_data g;
2168-
g.name = name; g.list = list;
2169-
2170-
repo_config(the_repository, get_remote_group, &g);
2171-
if (list->nr == prev_nr) {
2172-
struct remote *remote = remote_get(name);
2173-
if (!remote_is_configured(remote, 0))
2174-
return 0;
2175-
string_list_append(list, remote->name);
2176-
}
2177-
return 1;
2178-
}
2179-
21802138
static void add_options_to_argv(struct strvec *argv,
21812139
const struct fetch_config *config)
21822140
{

remote.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,43 @@ int get_fetch_map(const struct ref *remote_refs,
21082108
return 0;
21092109
}
21102110

2111+
int get_remote_group(const char *key, const char *value,
2112+
const struct config_context *ctx UNUSED,
2113+
void *priv)
2114+
{
2115+
struct remote_group_data *g = priv;
2116+
2117+
if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) {
2118+
/* split list by white space */
2119+
while (*value) {
2120+
size_t wordlen = strcspn(value, " \t\n");
2121+
2122+
if (wordlen >= 1)
2123+
string_list_append_nodup(g->list,
2124+
xstrndup(value, wordlen));
2125+
value += wordlen + (value[wordlen] != '\0');
2126+
}
2127+
}
2128+
2129+
return 0;
2130+
}
2131+
2132+
int add_remote_or_group(const char *name, struct string_list *list)
2133+
{
2134+
int prev_nr = list->nr;
2135+
struct remote_group_data g;
2136+
g.name = name; g.list = list;
2137+
2138+
repo_config(the_repository, get_remote_group, &g);
2139+
if (list->nr == prev_nr) {
2140+
struct remote *remote = remote_get(name);
2141+
if (!remote_is_configured(remote, 0))
2142+
return 0;
2143+
string_list_append(list, remote->name);
2144+
}
2145+
return 1;
2146+
}
2147+
21112148
int resolve_remote_symref(struct ref *ref, struct ref *list)
21122149
{
21132150
if (!ref->symref)

remote.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@ int branch_has_merge_config(struct branch *branch);
347347

348348
int branch_merge_matches(struct branch *, int n, const char *);
349349

350+
/* list of the remote in a group as configured */
351+
struct remote_group_data {
352+
const char *name;
353+
struct string_list *list;
354+
};
355+
356+
int get_remote_group(const char *key, const char *value,
357+
const struct config_context *ctx UNUSED,
358+
void *priv);
359+
360+
int add_remote_or_group(const char *name, struct string_list *list);
361+
350362
/**
351363
* Return the fully-qualified refname of the tracking branch for `branch`.
352364
* I.e., what "branch@{upstream}" would give you. Returns NULL if no

0 commit comments

Comments
 (0)