Skip to content

Commit

Permalink
builtin/fetch: factor submodule recurse parsing out to submodule config
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stefanbeller authored and gitster committed Jun 23, 2017
1 parent 5402b13 commit 886dc15
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
18 changes: 2 additions & 16 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ static int shown_url = 0;
static int refmap_alloc, refmap_nr;
static const char **refmap_array;

static int option_parse_recurse_submodules(const struct option *opt,
const char *arg, int unset)
{
if (unset) {
recurse_submodules = RECURSE_SUBMODULES_OFF;
} else {
if (arg)
recurse_submodules = parse_fetch_recurse_submodules_arg(opt->long_name, arg);
else
recurse_submodules = RECURSE_SUBMODULES_ON;
}
return 0;
}

static int git_fetch_config(const char *k, const char *v, void *cb)
{
if (!strcmp(k, "fetch.prune")) {
Expand Down Expand Up @@ -115,9 +101,9 @@ static struct option builtin_fetch_options[] = {
N_("number of submodules fetched in parallel")),
OPT_BOOL('p', "prune", &prune,
N_("prune remote-tracking branches no longer on remote")),
{ OPTION_CALLBACK, 0, "recurse-submodules", NULL, N_("on-demand"),
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules, N_("on-demand"),
N_("control recursive fetching of submodules"),
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
PARSE_OPT_OPTARG, option_fetch_parse_recurse_submodules },
OPT_BOOL(0, "dry-run", &dry_run,
N_("dry run")),
OPT_BOOL('k', "keep", &keep, N_("keep downloaded pack")),
Expand Down
22 changes: 22 additions & 0 deletions submodule-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "submodule-config.h"
#include "submodule.h"
#include "strbuf.h"
#include "parse-options.h"

/*
* submodule cache lookup structure
Expand Down Expand Up @@ -234,6 +235,27 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
return parse_fetch_recurse(opt, arg, 1);
}

int option_fetch_parse_recurse_submodules(const struct option *opt,
const char *arg, int unset)
{
int *v;

if (!opt->value)
return -1;

v = opt->value;

if (unset) {
*v = RECURSE_SUBMODULES_OFF;
} else {
if (arg)
*v = parse_fetch_recurse_submodules_arg(opt->long_name, arg);
else
*v = RECURSE_SUBMODULES_ON;
}
return 0;
}

static int parse_update_recurse(const char *opt, const char *arg,
int die_on_error)
{
Expand Down
3 changes: 3 additions & 0 deletions submodule-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct submodule {
};

extern int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
struct option;
extern int option_fetch_parse_recurse_submodules(const struct option *opt,
const char *arg, int unset);
extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
extern int parse_submodule_config_option(const char *var, const char *value);
Expand Down

0 comments on commit 886dc15

Please sign in to comment.