builtin/submodule--helper: store update_clone information in a struct
The information that is printed for update_submodules in 'submodule--helper update-clone' and consumed by 'git submodule update' is stored as a string per submodule. This made sense at the time of 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29), but as we want to migrate the rest of the submodule update into C, we're better off having access to the raw information in a helper struct. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 3, 2018 at 15:23 UTC
f1d15713faef54c0bcc5d35c9089efffa4c914a1
1 file changed
+27
-10
builtin/submodule--helper.c
+27
-10
@@ -1446,6 +1446,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1446
return 0;
1447
}
1448
1449
+struct update_clone_data {
1450
+ const struct submodule *sub;
1451
+ struct object_id oid;
1452
+ unsigned just_cloned;
1453
+};
1454
+
1455
struct submodule_update_clone {
1456
/* index into 'list', the list of submodules to look into for cloning */
1457
int current;
@@ -1465,8 +1471,9 @@ struct submodule_update_clone {
1471
const char *recursive_prefix;
1472
const char *prefix;
1473
1468
- /* Machine-readable status lines to be consumed by git-submodule.sh */
1469
- struct string_list projectlines;
1474
+ /* to be consumed by git-submodule.sh */
1475
+ struct update_clone_data *update_clone;
1476
+ int update_clone_nr; int update_clone_alloc;
1477
1478
/* If we want to stop as fast as possible and return an error */
1479
unsigned quickstop : 1;
@@ -1480,7 +1487,7 @@ struct submodule_update_clone {
1487
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1488
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
1489
NULL, NULL, NULL, \
1483
- STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
1490
+ NULL, 0, 0, 0, NULL, 0, 0, 0}
1491
1492
1493
static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -1574,10 +1581,12 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1581
strbuf_addf(&sb, "%s/.git", ce->name);
1582
needs_cloning = !file_exists(sb.buf);
1583
1577
- strbuf_reset(&sb);
1578
- strbuf_addf(&sb, "dummy %s %d\t%s\n",
1579
- oid_to_hex(&ce->oid), needs_cloning, ce->name);
1580
- string_list_append(&suc->projectlines, sb.buf);
1584
+ ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1,
1585
+ suc->update_clone_alloc);
1586
+ oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid);
1587
+ suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning;
1588
+ suc->update_clone[suc->update_clone_nr].sub = sub;
1589
+ suc->update_clone_nr++;
1590
1591
if (!needs_cloning)
1592
goto cleanup;
@@ -1720,7 +1729,8 @@ static int git_update_clone_config(const char *var, const char *value,
1729
1730
static int update_submodules(struct submodule_update_clone *suc)
1731
{
1723
- struct string_list_item *item;
1732
+ int i;
1733
+ struct strbuf sb = STRBUF_INIT;
1734
1735
run_processes_parallel(suc->max_jobs,
1736
update_clone_get_next_task,
@@ -1739,9 +1749,16 @@ static int update_submodules(struct submodule_update_clone *suc)
1749
if (suc->quickstop)
1750
return 1;
1751
1742
- for_each_string_list_item(item, &suc->projectlines)
1743
- fprintf(stdout, "%s", item->string);
1752
+ for (i = 0; i < suc->update_clone_nr; i++) {
1753
+ strbuf_addf(&sb, "dummy %s %d\t%s\n",
1754
+ oid_to_hex(&suc->update_clone[i].oid),
1755
+ suc->update_clone[i].just_cloned,
1756
+ suc->update_clone[i].sub->path);
1757
+ fprintf(stdout, "%s", sb.buf);
1758
+ strbuf_reset(&sb);
1759
+ }
1760
1761
+ strbuf_release(&sb);
1762
return 0;
1763
}
1764