v2: addressed review comments, renaming the struct, improving the commit message. v1: https://public-inbox.org/git/20180712194754.71979-1-sbeller@xxxxxxxxxx/ I thought about writing it all in one go, but the series got too large, so let's chew one bite at a time. Thanks, Stefan Stefan Beller (6): git-submodule.sh: align error reporting for update mode to use path git-submodule.sh: rename unused variables builtin/submodule--helper: factor out submodule updating builtin/submodule--helper: store update_clone information in a struct builtin/submodule--helper: factor out method to update a single submodule submodule--helper: introduce new update-module-mode helper builtin/submodule--helper.c | 152 ++++++++++++++++++++++++++++-------- git-submodule.sh | 22 +----- 2 files changed, 122 insertions(+), 52 deletions(-) -- 2.18.0.203.gfac676dfb9-goog 1: d4e1ec45740 ! 1: bbc8697a8ca git-submodule.sh: align error reporting for update mode to use path @@ -6,7 +6,6 @@ on its path, so let's do that for invalid update modes, too. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> - Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> diff --git a/git-submodule.sh b/git-submodule.sh --- a/git-submodule.sh 2: 9c5ec3fccea ! 2: 7e26af17578 git-submodule.sh: rename unused variables @@ -14,8 +14,12 @@ using its own function starting in 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29), its removal was missed. + A later patch in this series also touches the communication between + the submodule helper and git-submodule.sh, but let's have this as + a preparatory patch, as it eases the next patch, which stores the + raw data instead of the line printed for this communication. + Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> - Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c --- a/builtin/submodule--helper.c 3: a3fb4e5539f ! 3: 3e8d22b0c70 builtin/submodule--helper: factor out submodule updating @@ -7,7 +7,6 @@ most of it is still in git-submodule.sh. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> - Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c --- a/builtin/submodule--helper.c 4: e680684139d ! 4: 5e0a39015df builtin/submodule--helper: store update_clone information in a struct @@ -11,7 +11,6 @@ struct. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> - Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c --- a/builtin/submodule--helper.c @@ -20,7 +19,7 @@ return 0; } -+struct submodule_update_clone_information { ++struct update_clone_data { + const struct submodule *sub; + struct object_id oid; + unsigned just_cloned; @@ -36,8 +35,8 @@ - /* Machine-readable status lines to be consumed by git-submodule.sh */ - struct string_list projectlines; + /* to be consumed by git-submodule.sh */ -+ struct submodule_update_clone_information *submodule_lines; -+ int submodule_lines_nr; int submodule_lines_alloc; ++ struct update_clone_data *update_clone; ++ int update_clone_nr; int update_clone_alloc; /* If we want to stop as fast as possible and return an error */ unsigned quickstop : 1; @@ -58,12 +57,12 @@ - strbuf_addf(&sb, "dummy %s %d\t%s\n", - oid_to_hex(&ce->oid), needs_cloning, ce->name); - string_list_append(&suc->projectlines, sb.buf); -+ ALLOC_GROW(suc->submodule_lines, suc->submodule_lines_nr + 1, -+ suc->submodule_lines_alloc); -+ oidcpy(&suc->submodule_lines[suc->submodule_lines_nr].oid, &ce->oid); -+ suc->submodule_lines[suc->submodule_lines_nr].just_cloned = needs_cloning; -+ suc->submodule_lines[suc->submodule_lines_nr].sub = sub; -+ suc->submodule_lines_nr++; ++ ALLOC_GROW(suc->update_clone, suc->update_clone_nr + 1, ++ suc->update_clone_alloc); ++ oidcpy(&suc->update_clone[suc->update_clone_nr].oid, &ce->oid); ++ suc->update_clone[suc->update_clone_nr].just_cloned = needs_cloning; ++ suc->update_clone[suc->update_clone_nr].sub = sub; ++ suc->update_clone_nr++; if (!needs_cloning) goto cleanup; @@ -83,11 +82,11 @@ - for_each_string_list_item(item, &suc->projectlines) - fprintf(stdout, "%s", item->string); -+ for (i = 0; i < suc->submodule_lines_nr; i++) { ++ for (i = 0; i < suc->update_clone_nr; i++) { + strbuf_addf(&sb, "dummy %s %d\t%s\n", -+ oid_to_hex(&suc->submodule_lines[i].oid), -+ suc->submodule_lines[i].just_cloned, -+ suc->submodule_lines[i].sub->path); ++ oid_to_hex(&suc->update_clone[i].oid), ++ suc->update_clone[i].just_cloned, ++ suc->update_clone[i].sub->path); + fprintf(stdout, "%s", sb.buf); + strbuf_reset(&sb); + } 5: 95409e47b0d ! 5: ecee68506eb builtin/submodule--helper: factor out method to update a single submodule @@ -5,7 +5,6 @@ In a later patch we'll find this method handy. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> - Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c --- a/builtin/submodule--helper.c @@ -14,12 +13,12 @@ return 0; } -+static void update_submodule(struct submodule_update_clone_information *suci) ++static void update_submodule(struct update_clone_data *ucd) +{ + fprintf(stdout, "dummy %s %d\t%s\n", -+ oid_to_hex(&suci->oid), -+ suci->just_cloned, -+ suci->sub->path); ++ oid_to_hex(&ucd->oid), ++ ucd->just_cloned, ++ ucd->sub->path); +} + static int update_submodules(struct submodule_update_clone *suc) @@ -33,16 +32,16 @@ if (suc->quickstop) return 1; -- for (i = 0; i < suc->submodule_lines_nr; i++) { +- for (i = 0; i < suc->update_clone_nr; i++) { - strbuf_addf(&sb, "dummy %s %d\t%s\n", -- oid_to_hex(&suc->submodule_lines[i].oid), -- suc->submodule_lines[i].just_cloned, -- suc->submodule_lines[i].sub->path); +- oid_to_hex(&suc->update_clone[i].oid), +- suc->update_clone[i].just_cloned, +- suc->update_clone[i].sub->path); - fprintf(stdout, "%s", sb.buf); - strbuf_reset(&sb); - } -+ for (i = 0; i < suc->submodule_lines_nr; i++) -+ update_submodule(&suc->submodule_lines[i]); ++ for (i = 0; i < suc->update_clone_nr; i++) ++ update_submodule(&suc->update_clone[i]); - strbuf_release(&sb); return 0; 6: 05bb02e6ea8 ! 6: b80e60a9d11 submodule--helper: introduce new update-module-mode helper @@ -10,7 +10,6 @@ for arbitrary repositories. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> - Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c --- a/builtin/submodule--helper.c @@ -79,7 +78,7 @@ + return 0; +} + - struct submodule_update_clone_information { + struct update_clone_data { const struct submodule *sub; struct object_id oid; @@