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 <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Mar 7, 2022 at 16:14 UTC
5370b91f3fae9d7a511e23142b55082200152cef
1 file changed
+52
-47
submodule.c
+52
-47
@@ -1415,32 +1415,6 @@ static const struct submodule *get_non_gitmodules_submodule(const char *path)
1415
return (const struct submodule *) ret;
1416
}
1417
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
-
1418
static void fetch_task_release(struct fetch_task *p)
1419
{
1420
if (p->free_sub)
@@ -1467,6 +1441,57 @@ static struct repository *get_submodule_repo_for(struct repository *r,
1441
return ret;
1442
}
1443
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
+
1495
static struct fetch_task *
1496
get_fetch_task(struct submodule_parallel_fetch *spf, struct strbuf *err)
1497
{
@@ -1477,30 +1502,10 @@ get_fetch_task(struct submodule_parallel_fetch *spf, struct strbuf *err)
1502
if (!S_ISGITLINK(ce->ce_mode))
1503
continue;
1504
1480
- task = fetch_task_create(spf->r, ce->name, null_oid());
1505
+ task = fetch_task_create(spf, ce->name, null_oid());
1506
if (!task)
1507
continue;
1508
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());
1509
if (task->repo) {
1510
if (!spf->quiet)
1511
strbuf_addf(err, _("Fetching submodule %s%s\n"),