From: Stefan Beller <sbeller@google.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>
Subject: [PATCH v2 4/6] builtin/submodule--helper: store update_clone information in a struct
Date: Mon, 16 Jul 2018 17:26:52 -0700 [thread overview]
Message-ID: <20180717002654.120375-5-sbeller@google.com> (raw)
In-Reply-To: <20180717002654.120375-1-sbeller@google.com>
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>
---
builtin/submodule--helper.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 96929ba1096..fb54936efc7 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1444,6 +1444,12 @@ static int module_clone(int argc, const char **argv, const char *prefix)
return 0;
}
+struct update_clone_data {
+ const struct submodule *sub;
+ struct object_id oid;
+ unsigned just_cloned;
+};
+
struct submodule_update_clone {
/* index into 'list', the list of submodules to look into for cloning */
int current;
@@ -1463,8 +1469,9 @@ struct submodule_update_clone {
const char *recursive_prefix;
const char *prefix;
- /* Machine-readable status lines to be consumed by git-submodule.sh */
- struct string_list projectlines;
+ /* to be consumed by git-submodule.sh */
+ 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;
@@ -1478,7 +1485,7 @@ struct submodule_update_clone {
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
NULL, NULL, NULL, \
- STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
+ NULL, 0, 0, 0, NULL, 0, 0, 0}
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,
strbuf_addf(&sb, "%s/.git", ce->name);
needs_cloning = !file_exists(sb.buf);
- strbuf_reset(&sb);
- 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->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;
@@ -1718,7 +1727,8 @@ static int gitmodules_update_clone_config(const char *var, const char *value,
static int update_submodules(struct submodule_update_clone *suc)
{
- struct string_list_item *item;
+ int i;
+ struct strbuf sb = STRBUF_INIT;
run_processes_parallel(suc->max_jobs,
update_clone_get_next_task,
@@ -1737,9 +1747,16 @@ static int update_submodules(struct submodule_update_clone *suc)
if (suc->quickstop)
return 1;
- for_each_string_list_item(item, &suc->projectlines)
- fprintf(stdout, "%s", item->string);
+ for (i = 0; i < suc->update_clone_nr; i++) {
+ strbuf_addf(&sb, "dummy %s %d\t%s\n",
+ 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);
+ }
+ strbuf_release(&sb);
return 0;
}
--
2.18.0.203.gfac676dfb9-goog
next prev parent reply other threads:[~2018-07-17 0:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-17 0:26 [PATCH v2 0/6] git-submodule.sh: convert part of cmd_update to C Stefan Beller
2018-07-17 0:26 ` [PATCH v2 1/6] git-submodule.sh: align error reporting for update mode to use path Stefan Beller
2018-07-17 0:26 ` [PATCH v2 2/6] git-submodule.sh: rename unused variables Stefan Beller
2018-07-17 0:26 ` [PATCH v2 3/6] builtin/submodule--helper: factor out submodule updating Stefan Beller
2018-07-17 0:26 ` Stefan Beller [this message]
2018-07-17 0:26 ` [PATCH v2 5/6] builtin/submodule--helper: factor out method to update a single submodule Stefan Beller
2018-07-17 0:26 ` [PATCH v2 6/6] submodule--helper: introduce new update-module-mode helper Stefan Beller
2018-07-17 7:59 ` SZEDER Gábor
2018-07-17 21:44 ` Junio C Hamano
2018-07-17 18:39 ` [PATCH v2 0/6] git-submodule.sh: convert part of cmd_update to C Junio C Hamano
2018-07-17 18:53 ` Stefan Beller
2018-07-17 18:59 ` Eric Sunshine
2018-07-18 19:34 ` Stefan Beller
2018-07-18 19:55 ` Eric Sunshine
2018-07-18 21:57 ` Junio C Hamano
2018-07-17 19:51 ` Junio C Hamano
2018-07-17 20:56 ` Stefan Beller
2018-07-17 21:39 ` Junio C Hamano
2018-07-26 10:47 ` Johannes Schindelin
2018-07-26 18:14 ` Stefan Beller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180717002654.120375-5-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.