Skip to content

Commit f1d1571

Browse files
stefanbellergitster
authored andcommitted
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 4830868 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90efe59 commit f1d1571

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

builtin/submodule--helper.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
14461446
return 0;
14471447
}
14481448

1449+
struct update_clone_data {
1450+
const struct submodule *sub;
1451+
struct object_id oid;
1452+
unsigned just_cloned;
1453+
};
1454+
14491455
struct submodule_update_clone {
14501456
/* index into 'list', the list of submodules to look into for cloning */
14511457
int current;
@@ -1465,8 +1471,9 @@ struct submodule_update_clone {
14651471
const char *recursive_prefix;
14661472
const char *prefix;
14671473

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;
14701477

14711478
/* If we want to stop as fast as possible and return an error */
14721479
unsigned quickstop : 1;
@@ -1480,7 +1487,7 @@ struct submodule_update_clone {
14801487
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
14811488
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
14821489
NULL, NULL, NULL, \
1483-
STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
1490+
NULL, 0, 0, 0, NULL, 0, 0, 0}
14841491

14851492

14861493
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,
15741581
strbuf_addf(&sb, "%s/.git", ce->name);
15751582
needs_cloning = !file_exists(sb.buf);
15761583

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++;
15811590

15821591
if (!needs_cloning)
15831592
goto cleanup;
@@ -1720,7 +1729,8 @@ static int git_update_clone_config(const char *var, const char *value,
17201729

17211730
static int update_submodules(struct submodule_update_clone *suc)
17221731
{
1723-
struct string_list_item *item;
1732+
int i;
1733+
struct strbuf sb = STRBUF_INIT;
17241734

17251735
run_processes_parallel(suc->max_jobs,
17261736
update_clone_get_next_task,
@@ -1739,9 +1749,16 @@ static int update_submodules(struct submodule_update_clone *suc)
17391749
if (suc->quickstop)
17401750
return 1;
17411751

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+
}
17441760

1761+
strbuf_release(&sb);
17451762
return 0;
17461763
}
17471764

0 commit comments

Comments
 (0)