Skip to content

Commit 5fd0bfe

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 d99f80d commit 5fd0bfe

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
@@ -1444,6 +1444,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
14441444
return 0;
14451445
}
14461446

1447+
struct update_clone_data {
1448+
const struct submodule *sub;
1449+
struct object_id oid;
1450+
unsigned just_cloned;
1451+
};
1452+
14471453
struct submodule_update_clone {
14481454
/* index into 'list', the list of submodules to look into for cloning */
14491455
int current;
@@ -1463,8 +1469,9 @@ struct submodule_update_clone {
14631469
const char *recursive_prefix;
14641470
const char *prefix;
14651471

1466-
/* Machine-readable status lines to be consumed by git-submodule.sh */
1467-
struct string_list projectlines;
1472+
/* to be consumed by git-submodule.sh */
1473+
struct update_clone_data *update_clone;
1474+
int update_clone_nr; int update_clone_alloc;
14681475

14691476
/* If we want to stop as fast as possible and return an error */
14701477
unsigned quickstop : 1;
@@ -1478,7 +1485,7 @@ struct submodule_update_clone {
14781485
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
14791486
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
14801487
NULL, NULL, NULL, \
1481-
STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
1488+
NULL, 0, 0, 0, NULL, 0, 0, 0}
14821489

14831490

14841491
static void next_submodule_warn_missing(struct submodule_update_clone *suc,
@@ -1572,10 +1579,12 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
15721579
strbuf_addf(&sb, "%s/.git", ce->name);
15731580
needs_cloning = !file_exists(sb.buf);
15741581

1575-
strbuf_reset(&sb);
1576-
strbuf_addf(&sb, "dummy %s %d\t%s\n",
1577-
oid_to_hex(&ce->oid), needs_cloning, ce->name);
1578-
string_list_append(&suc->projectlines, sb.buf);
1582+
ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1,
1583+
suc->update_clone_alloc);
1584+
oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid);
1585+
suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning;
1586+
suc->update_clone[suc->update_clone_nr].sub = sub;
1587+
suc->update_clone_nr++;
15791588

15801589
if (!needs_cloning)
15811590
goto cleanup;
@@ -1718,7 +1727,8 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
17181727

17191728
static int update_submodules(struct submodule_update_clone *suc)
17201729
{
1721-
struct string_list_item *item;
1730+
int i;
1731+
struct strbuf sb = STRBUF_INIT;
17221732

17231733
run_processes_parallel(suc->max_jobs,
17241734
update_clone_get_next_task,
@@ -1737,9 +1747,16 @@ static int update_submodules(struct submodule_update_clone *suc)
17371747
if (suc->quickstop)
17381748
return 1;
17391749

1740-
for_each_string_list_item(item, &suc->projectlines)
1741-
fprintf(stdout, "%s", item->string);
1750+
for (i = 0; i < suc->update_clone_nr; i++) {
1751+
strbuf_addf(&sb, "dummy %s %d\t%s\n",
1752+
oid_to_hex(&suc->update_clone[i].oid),
1753+
suc->update_clone[i].just_cloned,
1754+
suc->update_clone[i].sub->path);
1755+
fprintf(stdout, "%s", sb.buf);
1756+
strbuf_reset(&sb);
1757+
}
17421758

1759+
strbuf_release(&sb);
17431760
return 0;
17441761
}
17451762

0 commit comments

Comments
 (0)