Skip to content

Commit 5370b91

Browse files
chooglengitster
authored andcommitted
submodule: move logic into fetch_task_create()
get_fetch_task() gets a fetch task by iterating the index; a future commit will introduce a similar function, get_fetch_task_from_changed(), that gets a fetch task from the list of changed submodules. Both functions are similar in that they need to: * create a fetch task * initialize the submodule repo for the fetch task * determine the default recursion mode Move all of this logic into fetch_task_create() so that it is no longer split between fetch_task_create() and get_fetch_task(). This will make it easier to share code with get_fetch_task_from_changed(). Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73bc90d commit 5370b91

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

submodule.c

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,32 +1415,6 @@ static const struct submodule *get_non_gitmodules_submodule(const char *path)
14151415
return (const struct submodule *) ret;
14161416
}
14171417

1418-
static struct fetch_task *fetch_task_create(struct repository *r,
1419-
const char *path,
1420-
const struct object_id *treeish_name)
1421-
{
1422-
struct fetch_task *task = xmalloc(sizeof(*task));
1423-
memset(task, 0, sizeof(*task));
1424-
1425-
task->sub = submodule_from_path(r, treeish_name, path);
1426-
if (!task->sub) {
1427-
/*
1428-
* No entry in .gitmodules? Technically not a submodule,
1429-
* but historically we supported repositories that happen to be
1430-
* in-place where a gitlink is. Keep supporting them.
1431-
*/
1432-
task->sub = get_non_gitmodules_submodule(path);
1433-
if (!task->sub) {
1434-
free(task);
1435-
return NULL;
1436-
}
1437-
1438-
task->free_sub = 1;
1439-
}
1440-
1441-
return task;
1442-
}
1443-
14441418
static void fetch_task_release(struct fetch_task *p)
14451419
{
14461420
if (p->free_sub)
@@ -1467,6 +1441,57 @@ static struct repository *get_submodule_repo_for(struct repository *r,
14671441
return ret;
14681442
}
14691443

1444+
static struct fetch_task *fetch_task_create(struct submodule_parallel_fetch *spf,
1445+
const char *path,
1446+
const struct object_id *treeish_name)
1447+
{
1448+
struct fetch_task *task = xmalloc(sizeof(*task));
1449+
memset(task, 0, sizeof(*task));
1450+
1451+
task->sub = submodule_from_path(spf->r, treeish_name, path);
1452+
1453+
if (!task->sub) {
1454+
/*
1455+
* No entry in .gitmodules? Technically not a submodule,
1456+
* but historically we supported repositories that happen to be
1457+
* in-place where a gitlink is. Keep supporting them.
1458+
*/
1459+
task->sub = get_non_gitmodules_submodule(path);
1460+
if (!task->sub)
1461+
goto cleanup;
1462+
1463+
task->free_sub = 1;
1464+
}
1465+
1466+
switch (get_fetch_recurse_config(task->sub, spf))
1467+
{
1468+
default:
1469+
case RECURSE_SUBMODULES_DEFAULT:
1470+
case RECURSE_SUBMODULES_ON_DEMAND:
1471+
if (!task->sub ||
1472+
!string_list_lookup(
1473+
&spf->changed_submodule_names,
1474+
task->sub->name))
1475+
goto cleanup;
1476+
task->default_argv = "on-demand";
1477+
break;
1478+
case RECURSE_SUBMODULES_ON:
1479+
task->default_argv = "yes";
1480+
break;
1481+
case RECURSE_SUBMODULES_OFF:
1482+
goto cleanup;
1483+
}
1484+
1485+
task->repo = get_submodule_repo_for(spf->r, path, treeish_name);
1486+
1487+
return task;
1488+
1489+
cleanup:
1490+
fetch_task_release(task);
1491+
free(task);
1492+
return NULL;
1493+
}
1494+
14701495
static struct fetch_task *
14711496
get_fetch_task(struct submodule_parallel_fetch *spf, struct strbuf *err)
14721497
{
@@ -1477,30 +1502,10 @@ get_fetch_task(struct submodule_parallel_fetch *spf, struct strbuf *err)
14771502
if (!S_ISGITLINK(ce->ce_mode))
14781503
continue;
14791504

1480-
task = fetch_task_create(spf->r, ce->name, null_oid());
1505+
task = fetch_task_create(spf, ce->name, null_oid());
14811506
if (!task)
14821507
continue;
14831508

1484-
switch (get_fetch_recurse_config(task->sub, spf))
1485-
{
1486-
default:
1487-
case RECURSE_SUBMODULES_DEFAULT:
1488-
case RECURSE_SUBMODULES_ON_DEMAND:
1489-
if (!task->sub ||
1490-
!string_list_lookup(
1491-
&spf->changed_submodule_names,
1492-
task->sub->name))
1493-
continue;
1494-
task->default_argv = "on-demand";
1495-
break;
1496-
case RECURSE_SUBMODULES_ON:
1497-
task->default_argv = "yes";
1498-
break;
1499-
case RECURSE_SUBMODULES_OFF:
1500-
continue;
1501-
}
1502-
1503-
task->repo = get_submodule_repo_for(spf->r, task->sub->path, null_oid());
15041509
if (task->repo) {
15051510
if (!spf->quiet)
15061511
strbuf_addf(err, _("Fetching submodule %s%s\n"),

0 commit comments

Comments
 (0)