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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Jun 23, 2017 at 12:13 UTC
886dc154d8086dffb16e0830a1db2f024758fe52
3 files changed
+27
-16
builtin/fetch.c
+2
-16
@@ -53,20 +53,6 @@ static int shown_url = 0;
53
static int refmap_alloc, refmap_nr;
54
static const char **refmap_array;
55
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
-
56
static int git_fetch_config(const char *k, const char *v, void *cb)
57
{
58
if (!strcmp(k, "fetch.prune")) {
@@ -115,9 +101,9 @@ static struct option builtin_fetch_options[] = {
101
N_("number of submodules fetched in parallel")),
102
OPT_BOOL('p', "prune", &prune,
103
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"),
105
N_("control recursive fetching of submodules"),
120
- PARSE_OPT_OPTARG, option_parse_recurse_submodules },
106
+ PARSE_OPT_OPTARG, option_fetch_parse_recurse_submodules },
107
OPT_BOOL(0, "dry-run", &dry_run,
108
N_("dry run")),
109
OPT_BOOL('k', "keep", &keep, N_("keep downloaded pack")),
submodule-config.c
+22
@@ -2,6 +2,7 @@
2
#include "submodule-config.h"
3
#include "submodule.h"
4
#include "strbuf.h"
5
+#include "parse-options.h"
6
7
/*
8
* submodule cache lookup structure
@@ -234,6 +235,27 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
235
return parse_fetch_recurse(opt, arg, 1);
236
}
237
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
+
259
static int parse_update_recurse(const char *opt, const char *arg,
260
int die_on_error)
261
{
submodule-config.h
+3
@@ -23,6 +23,9 @@ struct submodule {
23
};
24
25
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);
29
extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
30
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
31
extern int parse_submodule_config_option(const char *var, const char *value);