1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 23:56:28 +02:00

submodule: extract get_fetch_task()

get_next_submodule() configures the parallel submodule fetch by
performing two functions:

* iterate the index to find submodules
* configure the child processes to fetch the submodules found in the
  previous step

Extract the index iterating code into an iterator function,
get_fetch_task(), so that get_next_submodule() is agnostic of how
to find submodules. This prepares for a subsequent commit will teach the
fetch machinery to also iterate through the list of changed
submodules (in addition to the index).

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Glen Choo 2022-03-07 16:14:30 -08:00 committed by Junio C Hamano
parent 6e1e0c9959
commit 73bc90d7e1

View File

@ -1389,6 +1389,7 @@ struct fetch_task {
struct repository *repo;
const struct submodule *sub;
unsigned free_sub : 1; /* Do we need to free the submodule? */
const char *default_argv; /* The default fetch mode. */
struct oid_array *commits; /* Ensure these commits are fetched */
};
@ -1466,14 +1467,11 @@ static struct repository *get_submodule_repo_for(struct repository *r,
return ret;
}
static int get_next_submodule(struct child_process *cp,
struct strbuf *err, void *data, void **task_cb)
static struct fetch_task *
get_fetch_task(struct submodule_parallel_fetch *spf, struct strbuf *err)
{
struct submodule_parallel_fetch *spf = data;
for (; spf->count < spf->r->index->cache_nr; spf->count++) {
const struct cache_entry *ce = spf->r->index->cache[spf->count];
const char *default_argv;
struct fetch_task *task;
if (!S_ISGITLINK(ce->ce_mode))
@ -1493,10 +1491,10 @@ static int get_next_submodule(struct child_process *cp,
&spf->changed_submodule_names,
task->sub->name))
continue;
default_argv = "on-demand";
task->default_argv = "on-demand";
break;
case RECURSE_SUBMODULES_ON:
default_argv = "yes";
task->default_argv = "yes";
break;
case RECURSE_SUBMODULES_OFF:
continue;
@ -1504,29 +1502,12 @@ static int get_next_submodule(struct child_process *cp,
task->repo = get_submodule_repo_for(spf->r, task->sub->path, null_oid());
if (task->repo) {
struct strbuf submodule_prefix = STRBUF_INIT;
child_process_init(cp);
cp->dir = task->repo->gitdir;
prepare_submodule_repo_env_in_gitdir(&cp->env_array);
cp->git_cmd = 1;
if (!spf->quiet)
strbuf_addf(err, _("Fetching submodule %s%s\n"),
spf->prefix, ce->name);
strvec_init(&cp->args);
strvec_pushv(&cp->args, spf->args.v);
strvec_push(&cp->args, default_argv);
strvec_push(&cp->args, "--submodule-prefix");
strbuf_addf(&submodule_prefix, "%s%s/",
spf->prefix,
task->sub->path);
strvec_push(&cp->args, submodule_prefix.buf);
spf->count++;
*task_cb = task;
strbuf_release(&submodule_prefix);
return 1;
return task;
} else {
struct strbuf empty_submodule_path = STRBUF_INIT;
@ -1550,6 +1531,36 @@ static int get_next_submodule(struct child_process *cp,
strbuf_release(&empty_submodule_path);
}
}
return NULL;
}
static int get_next_submodule(struct child_process *cp, struct strbuf *err,
void *data, void **task_cb)
{
struct submodule_parallel_fetch *spf = data;
struct fetch_task *task = get_fetch_task(spf, err);
if (task) {
struct strbuf submodule_prefix = STRBUF_INIT;
child_process_init(cp);
cp->dir = task->repo->gitdir;
prepare_submodule_repo_env_in_gitdir(&cp->env_array);
cp->git_cmd = 1;
strvec_init(&cp->args);
strvec_pushv(&cp->args, spf->args.v);
strvec_push(&cp->args, task->default_argv);
strvec_push(&cp->args, "--submodule-prefix");
strbuf_addf(&submodule_prefix, "%s%s/",
spf->prefix,
task->sub->path);
strvec_push(&cp->args, submodule_prefix.buf);
*task_cb = task;
strbuf_release(&submodule_prefix);
return 1;
}
if (spf->oid_fetch_tasks_nr) {
struct fetch_task *task =