Skip to content

Commit 4b4aced

Browse files
hvoigtgitster
authored andcommitted
submodule: simplify decision tree whether to or not to fetch
To make extending this logic later easier. Signed-off-by: Heiko Voigt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c68f837 commit 4b4aced

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

submodule.c

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,31 @@ struct submodule_parallel_fetch {
11871187
};
11881188
#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0}
11891189

1190+
static int get_fetch_recurse_config(const struct submodule *submodule,
1191+
struct submodule_parallel_fetch *spf)
1192+
{
1193+
if (spf->command_line_option != RECURSE_SUBMODULES_DEFAULT)
1194+
return spf->command_line_option;
1195+
1196+
if (submodule) {
1197+
char *key;
1198+
const char *value;
1199+
1200+
int fetch_recurse = submodule->fetch_recurse;
1201+
key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
1202+
if (!repo_config_get_string_const(the_repository, key, &value)) {
1203+
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
1204+
}
1205+
free(key);
1206+
1207+
if (fetch_recurse != RECURSE_SUBMODULES_NONE)
1208+
/* local config overrules everything except commandline */
1209+
return fetch_recurse;
1210+
}
1211+
1212+
return spf->default_option;
1213+
}
1214+
11901215
static int get_next_submodule(struct child_process *cp,
11911216
struct strbuf *err, void *data, void **task_cb)
11921217
{
@@ -1214,46 +1239,21 @@ static int get_next_submodule(struct child_process *cp,
12141239
}
12151240
}
12161241

1217-
default_argv = "yes";
1218-
if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
1219-
int fetch_recurse = RECURSE_SUBMODULES_NONE;
1220-
1221-
if (submodule) {
1222-
char *key;
1223-
const char *value;
1224-
1225-
fetch_recurse = submodule->fetch_recurse;
1226-
key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
1227-
if (!repo_config_get_string_const(the_repository, key, &value)) {
1228-
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
1229-
}
1230-
free(key);
1231-
}
1232-
1233-
if (fetch_recurse != RECURSE_SUBMODULES_NONE) {
1234-
if (fetch_recurse == RECURSE_SUBMODULES_OFF)
1235-
continue;
1236-
if (fetch_recurse == RECURSE_SUBMODULES_ON_DEMAND) {
1237-
if (!unsorted_string_list_lookup(&changed_submodule_names,
1238-
submodule->name))
1239-
continue;
1240-
default_argv = "on-demand";
1241-
}
1242-
} else {
1243-
if (spf->default_option == RECURSE_SUBMODULES_OFF)
1244-
continue;
1245-
if (spf->default_option == RECURSE_SUBMODULES_ON_DEMAND) {
1246-
if (!unsorted_string_list_lookup(&changed_submodule_names,
1247-
submodule->name))
1248-
continue;
1249-
default_argv = "on-demand";
1250-
}
1251-
}
1252-
} else if (spf->command_line_option == RECURSE_SUBMODULES_ON_DEMAND) {
1253-
if (!unsorted_string_list_lookup(&changed_submodule_names,
1242+
switch (get_fetch_recurse_config(submodule, spf))
1243+
{
1244+
default:
1245+
case RECURSE_SUBMODULES_DEFAULT:
1246+
case RECURSE_SUBMODULES_ON_DEMAND:
1247+
if (!submodule || !unsorted_string_list_lookup(&changed_submodule_names,
12541248
submodule->name))
12551249
continue;
12561250
default_argv = "on-demand";
1251+
break;
1252+
case RECURSE_SUBMODULES_ON:
1253+
default_argv = "yes";
1254+
break;
1255+
case RECURSE_SUBMODULES_OFF:
1256+
continue;
12571257
}
12581258

12591259
strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);

0 commit comments

Comments
 (0)