Skip to content

Commit 886dc15

Browse files
stefanbellergitster
authored andcommitted
builtin/fetch: factor submodule recurse parsing out to submodule config
Later we want to access this parsing in builtin/pull as well. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5402b13 commit 886dc15

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

builtin/fetch.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ static int shown_url = 0;
5353
static int refmap_alloc, refmap_nr;
5454
static const char **refmap_array;
5555

56-
static int option_parse_recurse_submodules(const struct option *opt,
57-
const char *arg, int unset)
58-
{
59-
if (unset) {
60-
recurse_submodules = RECURSE_SUBMODULES_OFF;
61-
} else {
62-
if (arg)
63-
recurse_submodules = parse_fetch_recurse_submodules_arg(opt->long_name, arg);
64-
else
65-
recurse_submodules = RECURSE_SUBMODULES_ON;
66-
}
67-
return 0;
68-
}
69-
7056
static int git_fetch_config(const char *k, const char *v, void *cb)
7157
{
7258
if (!strcmp(k, "fetch.prune")) {
@@ -115,9 +101,9 @@ static struct option builtin_fetch_options[] = {
115101
N_("number of submodules fetched in parallel")),
116102
OPT_BOOL('p', "prune", &prune,
117103
N_("prune remote-tracking branches no longer on remote")),
118-
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"),
104+
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, N_("on-demand"),
119105
N_("control recursive fetching of submodules"),
120-
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
106+
PARSE_OPT_OPTARG, option_fetch_parse_recurse_submodules },
121107
OPT_BOOL(0, "dry-run", &dry_run,
122108
N_("dry run")),
123109
OPT_BOOL('k', "keep", &keep, N_("keep downloaded pack")),

submodule-config.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "submodule-config.h"
33
#include "submodule.h"
44
#include "strbuf.h"
5+
#include "parse-options.h"
56

67
/*
78
* submodule cache lookup structure
@@ -234,6 +235,27 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
234235
return parse_fetch_recurse(opt, arg, 1);
235236
}
236237

238+
int option_fetch_parse_recurse_submodules(const struct option *opt,
239+
const char *arg, int unset)
240+
{
241+
int *v;
242+
243+
if (!opt->value)
244+
return -1;
245+
246+
v = opt->value;
247+
248+
if (unset) {
249+
*v = RECURSE_SUBMODULES_OFF;
250+
} else {
251+
if (arg)
252+
*v = parse_fetch_recurse_submodules_arg(opt->long_name, arg);
253+
else
254+
*v = RECURSE_SUBMODULES_ON;
255+
}
256+
return 0;
257+
}
258+
237259
static int parse_update_recurse(const char *opt, const char *arg,
238260
int die_on_error)
239261
{

submodule-config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct submodule {
2323
};
2424

2525
extern int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
26+
struct option;
27+
extern int option_fetch_parse_recurse_submodules(const struct option *opt,
28+
const char *arg, int unset);
2629
extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
2730
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
2831
extern int parse_submodule_config_option(const char *var, const char *value);

0 commit comments

Comments
 (0)