git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCHv17 00/11] Expose submodule parallelism to the user
@ 2016-02-25  3:06 Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 01/11] submodule-config: keep update strategy around Stefan Beller
                   ` (11 more replies)
  0 siblings, 12 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This replaces origin/sb/submodule-parallel-update and applies on
origin/sb/submodule-parallel-fetch.

Thanks Jonathan for review!

* fixing all the small nits of v16 found by Jonathan!

Thanks,
Stefan

Interdiff to v15: (current origin/sb/submodule-parallel-update)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 32254cd..9d94406 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -259,32 +259,36 @@ struct submodule_update_clone {
 	/* index into 'list', the list of submodules to look into for cloning */
 	int current;
 	struct module_list list;
-	int warn_if_uninitialized : 1;
-	/* update parameter passed via commandline*/
+	unsigned warn_if_uninitialized : 1;
+
+	/* update parameter passed via commandline */
 	struct submodule_update_strategy update;
+
 	/* configuration parameters which are passed on to the children */
 	int quiet;
 	const char *reference;
 	const char *depth;
 	const char *recursive_prefix;
 	const char *prefix;
-	/* lines to be output */
+
+	/* Machine-readable status lines to be consumed by git-submodule.sh */
 	struct string_list projectlines;
+
 	/* If we want to stop as fast as possible and return an error */
-	int quickstop : 1;
+	unsigned quickstop : 1;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
 	SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
 	STRING_LIST_INIT_DUP, 0}
 
 /**
- * Inspect if 'ce' needs to be cloned. If so, prepare the 'child' to be running
- * the clone and return non zero.
+ * Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
+ * run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
  */
 static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 					   struct child_process *child,
 					   struct submodule_update_clone *suc,
-					   struct strbuf *err)
+					   struct strbuf *out)
 {
 	const struct submodule *sub = NULL;
 	struct strbuf displaypath_sb = STRBUF_INIT;
@@ -295,10 +299,10 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 
 	if (ce_stage(ce)) {
 		if (suc->recursive_prefix) {
-			strbuf_addf(err, "Skipping unmerged submodule %s/%s\n",
+			strbuf_addf(out, "Skipping unmerged submodule %s/%s\n",
 				    suc->recursive_prefix, ce->name);
 		} else {
-			strbuf_addf(err, "Skipping unmerged submodule %s\n",
+			strbuf_addf(out, "Skipping unmerged submodule %s\n",
 				    ce->name);
 		}
 		goto cleanup;
@@ -315,7 +319,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 	if (suc->update.type == SM_UPDATE_NONE
 	    || (suc->update.type == SM_UPDATE_UNSPECIFIED
 		&& sub->update_strategy.type == SM_UPDATE_NONE)) {
-		strbuf_addf(err, "Skipping submodule '%s'\n",
+		strbuf_addf(out, "Skipping submodule '%s'\n",
 			    displaypath);
 		goto cleanup;
 	}
@@ -330,11 +334,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 	git_config_get_string(sb.buf, &url);
 	if (!url) {
 		/*
-		 * Only mention uninitialized submodules when its
+		 * Only mention uninitialized submodules when their
 		 * path have been specified
 		 */
 		if (suc->warn_if_uninitialized)
-			strbuf_addf(err, _("Submodule path '%s' not initialized\n"
+			strbuf_addf(out, _("Submodule path '%s' not initialized\n"
 				    "Maybe you want to use 'update --init'?\n"),
 				    displaypath);
 		goto cleanup;
@@ -435,7 +439,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
 
 	struct option module_update_clone_options[] = {
-		OPT_STRING(0, "prefix", &prefix,
+		OPT_STRING(0, "prefix", &suc.prefix,
 			   N_("path"),
 			   N_("path into the working tree")),
 		OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix,
@@ -460,7 +464,6 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"),
 		NULL
 	};
-	suc.prefix = prefix;
 
 	argc = parse_options(argc, argv, prefix, module_update_clone_options,
 			     git_submodule_helper_usage, 0);
@@ -475,8 +478,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	if (pathspec.nr)
 		suc.warn_if_uninitialized = 1;
 
-	gitmodules_config();
 	/* Overlay the parsed .gitmodules file with .git/config */
+	gitmodules_config();
 	git_config(submodule_config, NULL);
 
 	if (max_jobs < 0)
diff --git a/run-command.c b/run-command.c
index 8abaae4..6fad42f 100644
--- a/run-command.c
+++ b/run-command.c
@@ -897,29 +897,29 @@ struct parallel_processes {
 	struct pollfd *pfd;
 
 	unsigned shutdown : 1;
-	unsigned ended_with_newline: 1;
 
 	int output_owner;
 	struct strbuf buffered_output; /* of finished children */
 };
 
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
 	int i;
 
-	strbuf_addstr(err, "Starting a child failed:");
+	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
 
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
@@ -928,9 +928,10 @@ int default_task_finished(int result,
 	if (!result)
 		return 0;
 
-	strbuf_addf(err, "A child failed with return code %d:", result);
+	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
@@ -980,7 +981,6 @@ static void pp_init(struct parallel_processes *pp,
 	pp->nr_processes = 0;
 	pp->output_owner = 0;
 	pp->shutdown = 0;
-	pp->ended_with_newline = 1;
 	pp->children = xcalloc(n, sizeof(*pp->children));
 	pp->pfd = xcalloc(n, sizeof(*pp->pfd));
 	strbuf_init(&pp->buffered_output, 0);
@@ -1013,7 +1013,7 @@ static void pp_cleanup(struct parallel_processes *pp)
 	 * When get_next_task added messages to the buffer in its last
 	 * iteration, the buffered output is non empty.
 	 */
-	fputs(pp->buffered_output.buf, stderr);
+	strbuf_write(&pp->buffered_output, stderr);
 	strbuf_release(&pp->buffered_output);
 
 	sigchain_pop_common();
@@ -1055,7 +1055,6 @@ static int pp_start_one(struct parallel_processes *pp)
 					 pp->data,
 					 &pp->children[i].data);
 		strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
-		strbuf_addch(&pp->buffered_output, '\n');
 		strbuf_reset(&pp->children[i].err);
 		if (code)
 			pp->shutdown = 1;
@@ -1098,11 +1097,9 @@ static void pp_buffer_stderr(struct parallel_processes *pp, int output_timeout)
 static void pp_output(struct parallel_processes *pp)
 {
 	int i = pp->output_owner;
-	size_t len = pp->children[i].err.len;
-	if (pp->children[i].state == GIT_CP_WORKING && len) {
-		fputs(pp->children[i].err.buf, stderr);
-		pp->ended_with_newline =
-			(pp->children[i].err.buf[len - 1] == '\n');
+	if (pp->children[i].state == GIT_CP_WORKING &&
+	    pp->children[i].err.len) {
+		strbuf_write(&pp->children[i].err, stderr);
 		strbuf_reset(&pp->children[i].err);
 	}
 }
@@ -1112,7 +1109,6 @@ static int pp_collect_finished(struct parallel_processes *pp)
 	int i, code;
 	int n = pp->max_processes;
 	int result = 0;
-	ssize_t len;
 
 	while (pp->nr_processes > 0) {
 		for (i = 0; i < pp->max_processes; i++)
@@ -1137,22 +1133,15 @@ static int pp_collect_finished(struct parallel_processes *pp)
 		pp->pfd[i].fd = -1;
 		child_process_init(&pp->children[i].process);
 
-		len = pp->children[i].err.len - 1;
-		if (len >= 0 && pp->children[i].err.buf[len] != '\n')
-			strbuf_addch(&pp->children[i].err, '\n');
-
 		if (i != pp->output_owner) {
 			strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
 			strbuf_reset(&pp->children[i].err);
 		} else {
-			if (len == -1 && !pp->ended_with_newline)
-				strbuf_addch(&pp->children[i].err, '\n');
-			fputs(pp->children[i].err.buf, stderr);
+			strbuf_write(&pp->children[i].err, stderr);
 			strbuf_reset(&pp->children[i].err);
-			pp->ended_with_newline = 1;
 
 			/* Output all other finished child processes */
-			fputs(pp->buffered_output.buf, stderr);
+			strbuf_write(&pp->buffered_output, stderr);
 			strbuf_reset(&pp->buffered_output);
 
 			/*
diff --git a/run-command.h b/run-command.h
index a054fa6..2bd8fee 100644
--- a/run-command.h
+++ b/run-command.h
@@ -139,7 +139,7 @@ int in_async(void);
  * return the negative signal number.
  */
 typedef int (*get_next_task_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void **pp_task_cb);
 
@@ -148,7 +148,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * a new process.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -159,7 +159,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * the negative signal number.
  */
 typedef int (*start_failure_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -168,7 +168,7 @@ typedef int (*start_failure_fn)(struct child_process *cp,
  * exact command which failed.
  */
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
@@ -176,7 +176,7 @@ int default_start_failure(struct child_process *cp,
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -188,7 +188,7 @@ int default_start_failure(struct child_process *cp,
  */
 typedef int (*task_finished_fn)(int result,
 				struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -198,7 +198,7 @@ typedef int (*task_finished_fn)(int result,
  */
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
diff --git a/strbuf.c b/strbuf.c
index 38686ff..71345cd 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 	return cnt;
 }
 
+ssize_t strbuf_write(struct strbuf *sb, FILE *f)
+{
+	return fwrite(sb->buf, 1, sb->len, f);
+}
+
+
 #define STRBUF_MAXLINK (2*PATH_MAX)
 
 int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
diff --git a/strbuf.h b/strbuf.h
index 2bf90e7..d4f2aa1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -387,6 +387,12 @@ extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint
 extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
 
 /**
+ * Write the whole content of the strbuf to the stream not stopping at
+ * NUL bytes.
+ */
+extern ssize_t strbuf_write(struct strbuf *sb, FILE *stream);
+
+/**
  * Read a line from a FILE *, overwriting the existing contents
  * of the strbuf. The second argument specifies the line
  * terminator character, typically `'\n'`.
diff --git a/submodule.c b/submodule.c
index 8fbc847..051f722 100644
--- a/submodule.c
+++ b/submodule.c
@@ -219,7 +219,7 @@ void gitmodules_config(void)
 int parse_submodule_update_strategy(const char *value,
 		struct submodule_update_strategy *dst)
 {
-	free((void *)dst->command);
+	free((void*)dst->command);
 	dst->command = NULL;
 	if (!strcmp(value, "none"))
 		dst->type = SM_UPDATE_NONE;
diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh
index 5c6822c..12228b4 100755
--- a/t/t0061-run-command.sh
+++ b/t/t0061-run-command.sh
@@ -77,32 +77,6 @@ test_expect_success 'run_command runs in parallel with more tasks than jobs avai
 	test_cmp expect actual
 '
 
-test_expect_success 'run_command ensures each command ends in LF' '
-	test-run-command run-command-parallel 3 sh -c "printf \"%s\n%s\" Hello World" 2>actual &&
-	test_cmp expect actual
-'
-
-cat >expect <<-EOF
-preloaded output of a child
-preloaded output of a child
-preloaded output of a child
-preloaded output of a child
-EOF
-
-test_expect_success 'run_command ensures each command ends in LF when output is only in starting cb' '
-	test-run-command run-command-parallel 3 sh -c true  2>actual &&
-	test_cmp expect actual
-'
-
-cat >expect <<-EOF
-EOF
-
-test_expect_success 'run_command ensures each command ends in LF except when there is no output' '
-	test-run-command run-command-parallel-silent 3 sh -c true  2>actual &&
-	test_cmp expect actual
-'
-
-
 cat >expect <<-EOF
 preloaded output of a child
 asking for a quick stop
diff --git a/test-run-command.c b/test-run-command.c
index ca1ee97..fbe0a27 100644
--- a/test-run-command.c
+++ b/test-run-command.c
@@ -31,20 +31,6 @@ static int parallel_next(struct child_process *cp,
 	return 1;
 }
 
-static int parallel_next_silent(struct child_process *cp,
-			 struct strbuf *err,
-			 void *cb,
-			 void **task_cb)
-{
-	struct child_process *d = cb;
-	if (number_callbacks >= 4)
-		return 0;
-
-	argv_array_pushv(&cp->args, d->argv);
-	number_callbacks++;
-	return 1;
-}
-
 static int no_job(struct child_process *cp,
 		  struct strbuf *err,
 		  void *cb,
@@ -85,10 +71,6 @@ int main(int argc, char **argv)
 	jobs = atoi(argv[2]);
 	proc.argv = (const char **)argv + 3;
 
-	if (!strcmp(argv[1], "run-command-parallel-silent"))
-		exit(run_processes_parallel(jobs, parallel_next_silent,
-					    NULL, NULL, &proc));
-
 	if (!strcmp(argv[1], "run-command-parallel"))
 		exit(run_processes_parallel(jobs, parallel_next,
 					    NULL, NULL, &proc));



Stefan Beller (11):
  submodule-config: keep update strategy around
  submodule-config: drop check against NULL
  fetching submodules: respect `submodule.fetchJobs` config option
  submodule update: direct error message to stderr
  run_processes_parallel: treat output of children as byte array
  run-command: expose default_{start_failure, task_finished}
  run_processes_parallel: rename parameters for the callbacks
  run_processes_parallel: correctly terminate callbacks with an LF
  git submodule update: have a dedicated helper for cloning
  submodule update: expose parallelism to the user
  clone: allow an explicit argument for parallel submodule clones

 Documentation/config.txt        |   6 +
 Documentation/git-clone.txt     |   6 +-
 Documentation/git-submodule.txt |   7 +-
 builtin/clone.c                 |  19 ++-
 builtin/fetch.c                 |   2 +-
 builtin/submodule--helper.c     | 254 ++++++++++++++++++++++++++++++++++++++++
 git-submodule.sh                |  56 ++++-----
 run-command.c                   |  36 +++---
 run-command.h                   |  29 ++++-
 strbuf.c                        |   6 +
 strbuf.h                        |   6 +
 submodule-config.c              |  19 ++-
 submodule-config.h              |   2 +
 submodule.c                     |  37 +++++-
 submodule.h                     |  18 +++
 t/t5526-fetch-submodules.sh     |  14 +++
 t/t7400-submodule-basic.sh      |   4 +-
 t/t7406-submodule-update.sh     |  27 +++++
 18 files changed, 477 insertions(+), 71 deletions(-)

-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 01/11] submodule-config: keep update strategy around
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25 18:06   ` Junio C Hamano
  2016-02-25  3:06 ` [PATCHv17 02/11] submodule-config: drop check against NULL Stefan Beller
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Currently submodule.<name>.update is only handled by git-submodule.sh.
C code will start to need to make use of that value as more of the
functionality of git-submodule.sh moves into library code in C.

Add the update field to 'struct submodule' and populate it so it can
be read as sm->update or from sm->update_command.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule-config.c | 13 +++++++++++++
 submodule-config.h |  2 ++
 submodule.c        | 21 +++++++++++++++++++++
 submodule.h        | 16 ++++++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/submodule-config.c b/submodule-config.c
index afe0ea8..a5cd2ee 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -59,6 +59,7 @@ static void free_one_config(struct submodule_entry *entry)
 {
 	free((void *) entry->config->path);
 	free((void *) entry->config->name);
+	free((void *) entry->config->update_strategy.command);
 	free(entry->config);
 }
 
@@ -194,6 +195,8 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
 
 	submodule->path = NULL;
 	submodule->url = NULL;
+	submodule->update_strategy.type = SM_UPDATE_UNSPECIFIED;
+	submodule->update_strategy.command = NULL;
 	submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
 	submodule->ignore = NULL;
 
@@ -311,6 +314,16 @@ static int parse_config(const char *var, const char *value, void *data)
 			free((void *) submodule->url);
 			submodule->url = xstrdup(value);
 		}
+	} else if (!strcmp(item.buf, "update")) {
+		if (!value)
+			ret = config_error_nonbool(var);
+		else if (!me->overwrite &&
+			 submodule->update_strategy.type != SM_UPDATE_UNSPECIFIED)
+			warn_multiple_config(me->commit_sha1, submodule->name,
+					     "update");
+		else if (parse_submodule_update_strategy(value,
+			 &submodule->update_strategy) < 0)
+				die(_("invalid value for %s"), var);
 	}
 
 	strbuf_release(&name);
diff --git a/submodule-config.h b/submodule-config.h
index 9061e4e..092ebfc 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -2,6 +2,7 @@
 #define SUBMODULE_CONFIG_CACHE_H
 
 #include "hashmap.h"
+#include "submodule.h"
 #include "strbuf.h"
 
 /*
@@ -14,6 +15,7 @@ struct submodule {
 	const char *url;
 	int fetch_recurse;
 	const char *ignore;
+	struct submodule_update_strategy update_strategy;
 	/* the sha1 blob id of the responsible .gitmodules file */
 	unsigned char gitmodules_sha1[20];
 };
diff --git a/submodule.c b/submodule.c
index b83939c..b38dd51 100644
--- a/submodule.c
+++ b/submodule.c
@@ -210,6 +210,27 @@ void gitmodules_config(void)
 	}
 }
 
+int parse_submodule_update_strategy(const char *value,
+		struct submodule_update_strategy *dst)
+{
+	free((void*)dst->command);
+	dst->command = NULL;
+	if (!strcmp(value, "none"))
+		dst->type = SM_UPDATE_NONE;
+	else if (!strcmp(value, "checkout"))
+		dst->type = SM_UPDATE_CHECKOUT;
+	else if (!strcmp(value, "rebase"))
+		dst->type = SM_UPDATE_REBASE;
+	else if (!strcmp(value, "merge"))
+		dst->type = SM_UPDATE_MERGE;
+	else if (skip_prefix(value, "!", &value)) {
+		dst->type = SM_UPDATE_COMMAND;
+		dst->command = xstrdup(value);
+	} else
+		return -1;
+	return 0;
+}
+
 void handle_ignore_submodules_arg(struct diff_options *diffopt,
 				  const char *arg)
 {
diff --git a/submodule.h b/submodule.h
index cbc0003..3464500 100644
--- a/submodule.h
+++ b/submodule.h
@@ -13,6 +13,20 @@ enum {
 	RECURSE_SUBMODULES_ON = 2
 };
 
+enum submodule_update_type {
+	SM_UPDATE_UNSPECIFIED = 0,
+	SM_UPDATE_CHECKOUT,
+	SM_UPDATE_REBASE,
+	SM_UPDATE_MERGE,
+	SM_UPDATE_NONE,
+	SM_UPDATE_COMMAND
+};
+
+struct submodule_update_strategy {
+	enum submodule_update_type type;
+	const char *command;
+};
+
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
 int remove_path_from_gitmodules(const char *path);
@@ -21,6 +35,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 		const char *path);
 int submodule_config(const char *var, const char *value, void *cb);
 void gitmodules_config(void);
+int parse_submodule_update_strategy(const char *value,
+		struct submodule_update_strategy *dst);
 void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);
 void show_submodule_summary(FILE *f, const char *path,
 		const char *line_prefix,
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 02/11] submodule-config: drop check against NULL
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 01/11] submodule-config: keep update strategy around Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Adhere to the common coding style of Git and not check explicitly
for NULL throughout the file. There are still other occurrences in the
code base but that is usually inside of conditions with side effects.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule-config.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index a5cd2ee..9fa2269 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -267,7 +267,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	if (!strcmp(item.buf, "path")) {
 		if (!value)
 			ret = config_error_nonbool(var);
-		else if (!me->overwrite && submodule->path != NULL)
+		else if (!me->overwrite && submodule->path)
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"path");
 		else {
@@ -291,7 +291,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	} else if (!strcmp(item.buf, "ignore")) {
 		if (!value)
 			ret = config_error_nonbool(var);
-		else if (!me->overwrite && submodule->ignore != NULL)
+		else if (!me->overwrite && submodule->ignore)
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"ignore");
 		else if (strcmp(value, "untracked") &&
@@ -307,7 +307,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	} else if (!strcmp(item.buf, "url")) {
 		if (!value) {
 			ret = config_error_nonbool(var);
-		} else if (!me->overwrite && submodule->url != NULL) {
+		} else if (!me->overwrite && submodule->url) {
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"url");
 		} else {
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 03/11] fetching submodules: respect `submodule.fetchJobs` config option
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 01/11] submodule-config: keep update strategy around Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 02/11] submodule-config: drop check against NULL Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 04/11] submodule update: direct error message to stderr Stefan Beller
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This allows to configure fetching and updating in parallel
without having the command line option.

This moved the responsibility to determine how many parallel processes
to start from builtin/fetch to submodule.c as we need a way to communicate
"The user did not specify the number of parallel processes in the command
line options" in the builtin fetch. The submodule code takes care of
the precedence (CLI > config > default).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/config.txt    |  6 ++++++
 builtin/fetch.c             |  2 +-
 submodule.c                 | 16 +++++++++++++++-
 submodule.h                 |  2 ++
 t/t5526-fetch-submodules.sh | 14 ++++++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2d06b11..3b02732 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2646,6 +2646,12 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+submodule.fetchJobs::
+	Specifies how many submodules are fetched/cloned at the same time.
+	A positive integer allows up to that number of submodules fetched
+	in parallel. A value of 0 will give some reasonable default.
+	If unset, it defaults to 1.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 586840d..5aa1c2d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -37,7 +37,7 @@ static int prune = -1; /* unspecified */
 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int tags = TAGS_DEFAULT, unshallow, update_shallow;
-static int max_children = 1;
+static int max_children = -1;
 static const char *depth;
 static const char *upload_pack;
 static struct strbuf default_rla = STRBUF_INIT;
diff --git a/submodule.c b/submodule.c
index b38dd51..051f722 100644
--- a/submodule.c
+++ b/submodule.c
@@ -15,6 +15,7 @@
 #include "thread-utils.h"
 
 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
+static int parallel_jobs = 1;
 static struct string_list changed_submodule_paths;
 static int initialized_fetch_ref_tips;
 static struct sha1_array ref_tips_before_fetch;
@@ -169,7 +170,12 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
 int submodule_config(const char *var, const char *value, void *cb)
 {
-	if (starts_with(var, "submodule."))
+	if (!strcmp(var, "submodule.fetchjobs")) {
+		parallel_jobs = git_config_int(var, value);
+		if (parallel_jobs < 0)
+			die(_("negative values not allowed for submodule.fetchJobs"));
+		return 0;
+	} else if (starts_with(var, "submodule."))
 		return parse_submodule_config_option(var, value);
 	else if (!strcmp(var, "fetch.recursesubmodules")) {
 		config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
@@ -772,6 +778,9 @@ int fetch_populated_submodules(const struct argv_array *options,
 	argv_array_push(&spf.args, "--recurse-submodules-default");
 	/* default value, "--submodule-prefix" and its value are added later */
 
+	if (max_parallel_jobs < 0)
+		max_parallel_jobs = parallel_jobs;
+
 	calculate_changed_submodule_paths();
 	run_processes_parallel(max_parallel_jobs,
 			       get_next_submodule,
@@ -1118,3 +1127,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	strbuf_release(&rel_path);
 	free((void *)real_work_tree);
 }
+
+int parallel_submodules(void)
+{
+	return parallel_jobs;
+}
diff --git a/submodule.h b/submodule.h
index 3464500..3166608 100644
--- a/submodule.h
+++ b/submodule.h
@@ -26,6 +26,7 @@ struct submodule_update_strategy {
 	enum submodule_update_type type;
 	const char *command;
 };
+#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
 
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
@@ -57,5 +58,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+int parallel_submodules(void);
 
 #endif
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh
index 1241146..954d0e4 100755
--- a/t/t5526-fetch-submodules.sh
+++ b/t/t5526-fetch-submodules.sh
@@ -471,4 +471,18 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
 	test_i18ncmp expect.err actual.err
 '
 
+test_expect_success 'fetching submodules respects parallel settings' '
+	git config fetch.recurseSubmodules true &&
+	(
+		cd downstream &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
+		grep "7 tasks" trace.out &&
+		git config submodule.fetchJobs 8 &&
+		GIT_TRACE=$(pwd)/trace.out git fetch &&
+		grep "8 tasks" trace.out &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
+		grep "9 tasks" trace.out
+	)
+'
+
 test_done
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 04/11] submodule update: direct error message to stderr
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (2 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Reroute the error message for specified but initialized submodules
to stderr instead of stdout.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh           | 4 ++--
 t/t7400-submodule-basic.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 9bc5c5f..9ee86d4 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -693,7 +693,7 @@ cmd_update()
 
 		if test "$update_module" = "none"
 		then
-			echo "Skipping submodule '$displaypath'"
+			echo >&2 "Skipping submodule '$displaypath'"
 			continue
 		fi
 
@@ -702,7 +702,7 @@ cmd_update()
 			# Only mention uninitialized submodules when its
 			# path have been specified
 			test "$#" != "0" &&
-			say "$(eval_gettext "Submodule path '\$displaypath' not initialized
+			say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
 Maybe you want to use 'update --init'?")"
 			continue
 		fi
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 540771c..5991e3c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -462,7 +462,7 @@ test_expect_success 'update --init' '
 	git config --remove-section submodule.example &&
 	test_must_fail git config submodule.example.url &&
 
-	git submodule update init > update.out &&
+	git submodule update init 2> update.out &&
 	cat update.out &&
 	test_i18ngrep "not initialized" update.out &&
 	test_must_fail git rev-parse --resolve-git-dir init/.git &&
@@ -480,7 +480,7 @@ test_expect_success 'update --init from subdirectory' '
 	mkdir -p sub &&
 	(
 		cd sub &&
-		git submodule update ../init >update.out &&
+		git submodule update ../init 2>update.out &&
 		cat update.out &&
 		test_i18ngrep "not initialized" update.out &&
 		test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (3 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 04/11] submodule update: direct error message to stderr Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25 18:16   ` Junio C Hamano
  2016-02-25  3:06 ` [PATCHv17 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

We do not want the output to be interrupted by a NUL byte, so we
cannot use raw fputs. Introduce strbuf_write to avoid having long
arguments in run-command.c.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 8 ++++----
 strbuf.c      | 6 ++++++
 strbuf.h      | 6 ++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/run-command.c b/run-command.c
index 51fd72c..2f8f222 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1011,7 +1011,7 @@ static void pp_cleanup(struct parallel_processes *pp)
 	 * When get_next_task added messages to the buffer in its last
 	 * iteration, the buffered output is non empty.
 	 */
-	fputs(pp->buffered_output.buf, stderr);
+	strbuf_write(&pp->buffered_output, stderr);
 	strbuf_release(&pp->buffered_output);
 
 	sigchain_pop_common();
@@ -1097,7 +1097,7 @@ static void pp_output(struct parallel_processes *pp)
 	int i = pp->output_owner;
 	if (pp->children[i].state == GIT_CP_WORKING &&
 	    pp->children[i].err.len) {
-		fputs(pp->children[i].err.buf, stderr);
+		strbuf_write(&pp->children[i].err, stderr);
 		strbuf_reset(&pp->children[i].err);
 	}
 }
@@ -1135,11 +1135,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
 			strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
 			strbuf_reset(&pp->children[i].err);
 		} else {
-			fputs(pp->children[i].err.buf, stderr);
+			strbuf_write(&pp->children[i].err, stderr);
 			strbuf_reset(&pp->children[i].err);
 
 			/* Output all other finished child processes */
-			fputs(pp->buffered_output.buf, stderr);
+			strbuf_write(&pp->buffered_output, stderr);
 			strbuf_reset(&pp->buffered_output);
 
 			/*
diff --git a/strbuf.c b/strbuf.c
index 38686ff..71345cd 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 	return cnt;
 }
 
+ssize_t strbuf_write(struct strbuf *sb, FILE *f)
+{
+	return fwrite(sb->buf, 1, sb->len, f);
+}
+
+
 #define STRBUF_MAXLINK (2*PATH_MAX)
 
 int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
diff --git a/strbuf.h b/strbuf.h
index 2bf90e7..d4f2aa1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -387,6 +387,12 @@ extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint
 extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
 
 /**
+ * Write the whole content of the strbuf to the stream not stopping at
+ * NUL bytes.
+ */
+extern ssize_t strbuf_write(struct strbuf *sb, FILE *stream);
+
+/**
  * Read a line from a FILE *, overwriting the existing contents
  * of the strbuf. The second argument specifies the line
  * terminator character, typically `'\n'`.
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 06/11] run-command: expose default_{start_failure, task_finished}
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (4 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

We want to reuse the error reporting facilities in a later patch.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 18 +++++++++---------
 run-command.h | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/run-command.c b/run-command.c
index 2f8f222..c9b13cf 100644
--- a/run-command.c
+++ b/run-command.c
@@ -902,10 +902,10 @@ struct parallel_processes {
 	struct strbuf buffered_output; /* of finished children */
 };
 
-static int default_start_failure(struct child_process *cp,
-				 struct strbuf *err,
-				 void *pp_cb,
-				 void *pp_task_cb)
+int default_start_failure(struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb)
 {
 	int i;
 
@@ -916,11 +916,11 @@ static int default_start_failure(struct child_process *cp,
 	return 0;
 }
 
-static int default_task_finished(int result,
-				 struct child_process *cp,
-				 struct strbuf *err,
-				 void *pp_cb,
-				 void *pp_task_cb)
+int default_task_finished(int result,
+			  struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb)
 {
 	int i;
 
diff --git a/run-command.h b/run-command.h
index d5a57f9..a054fa6 100644
--- a/run-command.h
+++ b/run-command.h
@@ -164,6 +164,15 @@ typedef int (*start_failure_fn)(struct child_process *cp,
 				void *pp_task_cb);
 
 /**
+ * If a command fails to start, then print an error message stating the
+ * exact command which failed.
+ */
+int default_start_failure(struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb);
+
+/**
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
@@ -184,6 +193,16 @@ typedef int (*task_finished_fn)(int result,
 				void *pp_task_cb);
 
 /**
+ * If the child process returns with a non zero error code, print
+ * an error message of the exact command which failed.
+ */
+int default_task_finished(int result,
+			  struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb);
+
+/**
  * Runs up to n processes at the same time. Whenever a process can be
  * started, the callback get_next_task_fn is called to obtain the data
  * required to start another child process.
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 07/11] run_processes_parallel: rename parameters for the callbacks
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (5 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

The refs code has a similar pattern of passing around 'struct strbuf *err',
which is strictly used for error reporting. This is not the case here,
as the strbuf is used to accumulate all the output (whether it is error
or not) for the user. Rename it to 'out'.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 12 ++++++------
 run-command.h | 14 +++++++-------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/run-command.c b/run-command.c
index c9b13cf..d2964e1 100644
--- a/run-command.c
+++ b/run-command.c
@@ -903,22 +903,22 @@ struct parallel_processes {
 };
 
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
 	int i;
 
-	strbuf_addstr(err, "Starting a child failed:");
+	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
 
 	return 0;
 }
 
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
@@ -927,9 +927,9 @@ int default_task_finished(int result,
 	if (!result)
 		return 0;
 
-	strbuf_addf(err, "A child failed with return code %d:", result);
+	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
 
 	return 0;
 }
diff --git a/run-command.h b/run-command.h
index a054fa6..2bd8fee 100644
--- a/run-command.h
+++ b/run-command.h
@@ -139,7 +139,7 @@ int in_async(void);
  * return the negative signal number.
  */
 typedef int (*get_next_task_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void **pp_task_cb);
 
@@ -148,7 +148,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * a new process.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -159,7 +159,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * the negative signal number.
  */
 typedef int (*start_failure_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -168,7 +168,7 @@ typedef int (*start_failure_fn)(struct child_process *cp,
  * exact command which failed.
  */
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
@@ -176,7 +176,7 @@ int default_start_failure(struct child_process *cp,
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -188,7 +188,7 @@ int default_start_failure(struct child_process *cp,
  */
 typedef int (*task_finished_fn)(int result,
 				struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -198,7 +198,7 @@ typedef int (*task_finished_fn)(int result,
  */
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 08/11] run_processes_parallel: correctly terminate callbacks with an LF
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (6 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

As the strbufs passed around collect all output to the user, and there
is no post processing involved we need to care about the line ending
ourselves.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/run-command.c b/run-command.c
index d2964e1..6fad42f 100644
--- a/run-command.c
+++ b/run-command.c
@@ -912,6 +912,7 @@ int default_start_failure(struct child_process *cp,
 	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
 		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
@@ -930,6 +931,7 @@ int default_task_finished(int result,
 	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
 		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 09/11] git submodule update: have a dedicated helper for cloning
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (7 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 10/11] submodule update: expose parallelism to the user Stefan Beller
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This introduces a new helper function in git submodule--helper
which takes care of cloning all submodules, which we want to
parallelize eventually.

Some tests (such as empty URL, update_mode=none) are required in the
helper to make the decision for cloning. These checks have been
moved into the C function as well (no need to repeat them in the
shell script).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 248 ++++++++++++++++++++++++++++++++++++++++++++
 git-submodule.sh            |  47 +++------
 2 files changed, 261 insertions(+), 34 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f4c3eff..408ac94 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -255,6 +255,253 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+struct submodule_update_clone {
+	/* index into 'list', the list of submodules to look into for cloning */
+	int current;
+	struct module_list list;
+	unsigned warn_if_uninitialized : 1;
+
+	/* update parameter passed via commandline */
+	struct submodule_update_strategy update;
+
+	/* configuration parameters which are passed on to the children */
+	int quiet;
+	const char *reference;
+	const char *depth;
+	const char *recursive_prefix;
+	const char *prefix;
+
+	/* Machine-readable status lines to be consumed by git-submodule.sh */
+	struct string_list projectlines;
+
+	/* If we want to stop as fast as possible and return an error */
+	unsigned quickstop : 1;
+};
+#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
+	SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
+	STRING_LIST_INIT_DUP, 0}
+
+/**
+ * Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
+ * run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
+ */
+static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
+					   struct child_process *child,
+					   struct submodule_update_clone *suc,
+					   struct strbuf *out)
+{
+	const struct submodule *sub = NULL;
+	struct strbuf displaypath_sb = STRBUF_INIT;
+	struct strbuf sb = STRBUF_INIT;
+	const char *displaypath = NULL;
+	char *url = NULL;
+	int needs_cloning = 0;
+
+	if (ce_stage(ce)) {
+		if (suc->recursive_prefix) {
+			strbuf_addf(out, "Skipping unmerged submodule %s/%s\n",
+				    suc->recursive_prefix, ce->name);
+		} else {
+			strbuf_addf(out, "Skipping unmerged submodule %s\n",
+				    ce->name);
+		}
+		goto cleanup;
+	}
+
+	sub = submodule_from_path(null_sha1, ce->name);
+
+	if (suc->recursive_prefix)
+		displaypath = relative_path(suc->recursive_prefix,
+					    ce->name, &displaypath_sb);
+	else
+		displaypath = ce->name;
+
+	if (suc->update.type == SM_UPDATE_NONE
+	    || (suc->update.type == SM_UPDATE_UNSPECIFIED
+		&& sub->update_strategy.type == SM_UPDATE_NONE)) {
+		strbuf_addf(out, "Skipping submodule '%s'\n",
+			    displaypath);
+		goto cleanup;
+	}
+
+	/*
+	 * Looking up the url in .git/config.
+	 * We must not fall back to .gitmodules as we only want
+	 * to process configured submodules.
+	 */
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "submodule.%s.url", sub->name);
+	git_config_get_string(sb.buf, &url);
+	if (!url) {
+		/*
+		 * Only mention uninitialized submodules when their
+		 * path have been specified
+		 */
+		if (suc->warn_if_uninitialized)
+			strbuf_addf(out, _("Submodule path '%s' not initialized\n"
+				    "Maybe you want to use 'update --init'?\n"),
+				    displaypath);
+		goto cleanup;
+	}
+
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "%s/.git", ce->name);
+	needs_cloning = !file_exists(sb.buf);
+
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode,
+			sha1_to_hex(ce->sha1), ce_stage(ce),
+			needs_cloning, ce->name);
+	string_list_append(&suc->projectlines, sb.buf);
+
+	if (!needs_cloning)
+		goto cleanup;
+
+	child->git_cmd = 1;
+	child->no_stdin = 1;
+	child->stdout_to_stderr = 1;
+	child->err = -1;
+	argv_array_push(&child->args, "submodule--helper");
+	argv_array_push(&child->args, "clone");
+	if (suc->quiet)
+		argv_array_push(&child->args, "--quiet");
+	if (suc->prefix)
+		argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
+	argv_array_pushl(&child->args, "--path", sub->path, NULL);
+	argv_array_pushl(&child->args, "--name", sub->name, NULL);
+	argv_array_pushl(&child->args, "--url", url, NULL);
+	if (suc->reference)
+		argv_array_push(&child->args, suc->reference);
+	if (suc->depth)
+		argv_array_push(&child->args, suc->depth);
+
+cleanup:
+	free(url);
+	strbuf_reset(&displaypath_sb);
+	strbuf_reset(&sb);
+
+	return needs_cloning;
+}
+
+static int update_clone_get_next_task(struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void **void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	for (; suc->current < suc->list.nr; suc->current++) {
+		const struct cache_entry *ce = suc->list.entries[suc->current];
+		if (prepare_to_clone_next_submodule(ce, child, suc, err)) {
+			suc->current++;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+static int update_clone_start_failure(struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void *void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	default_start_failure(child, err, suc_cb, void_task_cb);
+	suc->quickstop = 1;
+
+	return 1;
+}
+
+static int update_clone_task_finished(int result,
+				      struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void *void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	if (!result)
+		return 0;
+
+	default_task_finished(result, child, err, suc_cb, void_task_cb);
+	suc->quickstop = 1;
+
+	return 1;
+}
+
+static int update_clone(int argc, const char **argv, const char *prefix)
+{
+	const char *update = NULL;
+	struct string_list_item *item;
+	struct pathspec pathspec;
+	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
+
+	struct option module_update_clone_options[] = {
+		OPT_STRING(0, "prefix", &suc.prefix,
+			   N_("path"),
+			   N_("path into the working tree")),
+		OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix,
+			   N_("path"),
+			   N_("path into the working tree, across nested "
+			      "submodule boundaries")),
+		OPT_STRING(0, "update", &update,
+			   N_("string"),
+			   N_("rebase, merge, checkout or none")),
+		OPT_STRING(0, "reference", &suc.reference, N_("repo"),
+			   N_("reference repository")),
+		OPT_STRING(0, "depth", &suc.depth, "<depth>",
+			   N_("Create a shallow clone truncated to the "
+			      "specified number of revisions")),
+		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
+		OPT_END()
+	};
+
+	const char *const git_submodule_helper_usage[] = {
+		N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"),
+		NULL
+	};
+
+	argc = parse_options(argc, argv, prefix, module_update_clone_options,
+			     git_submodule_helper_usage, 0);
+
+	if (update)
+		if (parse_submodule_update_strategy(update, &suc.update) < 0)
+			die(_("bad value for update parameter"));
+
+	if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0)
+		return 1;
+
+	if (pathspec.nr)
+		suc.warn_if_uninitialized = 1;
+
+	/* Overlay the parsed .gitmodules file with .git/config */
+	gitmodules_config();
+	git_config(submodule_config, NULL);
+
+	run_processes_parallel(1,
+			       update_clone_get_next_task,
+			       update_clone_start_failure,
+			       update_clone_task_finished,
+			       &suc);
+
+	/*
+	 * We saved the output and put it out all at once now.
+	 * That means:
+	 * - the listener does not have to interleave their (checkout)
+	 *   work with our fetching.  The writes involved in a
+	 *   checkout involve more straightforward sequential I/O.
+	 * - the listener can avoid doing any work if fetching failed.
+	 */
+	if (suc.quickstop)
+		return 1;
+
+	for_each_string_list_item(item, &suc.projectlines)
+		utf8_fprintf(stdout, "%s", item->string);
+
+	return 0;
+}
+
 struct cmd_struct {
 	const char *cmd;
 	int (*fn)(int, const char **, const char *);
@@ -264,6 +511,7 @@ static struct cmd_struct commands[] = {
 	{"list", module_list},
 	{"name", module_name},
 	{"clone", module_clone},
+	{"update-clone", update_clone}
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
diff --git a/git-submodule.sh b/git-submodule.sh
index 9ee86d4..a6a82d2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -664,17 +664,20 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
-	cloned_modules=
-	git submodule--helper list --prefix "$wt_prefix" "$@" | {
+	{
+	git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
+		${wt_prefix:+--prefix "$wt_prefix"} \
+		${prefix:+--recursive-prefix "$prefix"} \
+		${update:+--update "$update"} \
+		${reference:+--reference "$reference"} \
+		${depth:+--depth "$depth"} \
+		"$@" || echo "#unmatched"
+	} | {
 	err=
-	while read mode sha1 stage sm_path
+	while read mode sha1 stage just_cloned sm_path
 	do
 		die_if_unmatched "$mode"
-		if test "$stage" = U
-		then
-			echo >&2 "Skipping unmerged submodule $prefix$sm_path"
-			continue
-		fi
+
 		name=$(git submodule--helper name "$sm_path") || exit
 		url=$(git config submodule."$name".url)
 		branch=$(get_submodule_config "$name" branch master)
@@ -691,27 +694,10 @@ cmd_update()
 
 		displaypath=$(relative_path "$prefix$sm_path")
 
-		if test "$update_module" = "none"
-		then
-			echo >&2 "Skipping submodule '$displaypath'"
-			continue
-		fi
-
-		if test -z "$url"
-		then
-			# Only mention uninitialized submodules when its
-			# path have been specified
-			test "$#" != "0" &&
-			say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
-Maybe you want to use 'update --init'?")"
-			continue
-		fi
-
-		if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
+		if test $just_cloned -eq 1
 		then
-			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
-			cloned_modules="$cloned_modules;$name"
 			subsha1=
+			update_module=checkout
 		else
 			subsha1=$(clear_local_git_env; cd "$sm_path" &&
 				git rev-parse --verify HEAD) ||
@@ -751,13 +737,6 @@ Maybe you want to use 'update --init'?")"
 				die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
 			fi
 
-			# Is this something we just cloned?
-			case ";$cloned_modules;" in
-			*";$name;"*)
-				# then there is no local change to integrate
-				update_module=checkout ;;
-			esac
-
 			must_die_on_failure=
 			case "$update_module" in
 			checkout)
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 10/11] submodule update: expose parallelism to the user
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (8 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25  3:06 ` [PATCHv17 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
  2016-02-25 22:26 ` [PATCHv17 00/11] Expose submodule parallelism to the user Junio C Hamano
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Expose possible parallelism either via the "--jobs" CLI parameter or
the "submodule.fetchJobs" setting.

By having the variable initialized to -1, we make sure 0 can be passed
into the parallel processing machine, which will then pick as many parallel
workers as there are CPUs.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/git-submodule.txt |  7 ++++++-
 builtin/submodule--helper.c     |  8 +++++++-
 git-submodule.sh                |  9 +++++++++
 t/t7406-submodule-update.sh     | 12 ++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 1572f05..13adebf 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -16,7 +16,7 @@ SYNOPSIS
 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
 	      [-f|--force] [--rebase|--merge] [--reference <repository>]
-	      [--depth <depth>] [--recursive] [--] [<path>...]
+	      [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
 	      [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach [--recursive] <command>
@@ -377,6 +377,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
 	clone with a history truncated to the specified number of revisions.
 	See linkgit:git-clone[1]
 
+-j <n>::
+--jobs <n>::
+	This option is only valid for the update command.
+	Clone new submodules in parallel with as many jobs.
+	Defaults to the `submodule.fetchJobs` option.
 
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 408ac94..9d94406 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -433,6 +433,7 @@ static int update_clone_task_finished(int result,
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
 	const char *update = NULL;
+	int max_jobs = -1;
 	struct string_list_item *item;
 	struct pathspec pathspec;
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
@@ -453,6 +454,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
+		OPT_INTEGER('j', "jobs", &max_jobs,
+			    N_("parallel jobs")),
 		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
 		OPT_END()
 	};
@@ -479,7 +482,10 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	gitmodules_config();
 	git_config(submodule_config, NULL);
 
-	run_processes_parallel(1,
+	if (max_jobs < 0)
+		max_jobs = parallel_submodules();
+
+	run_processes_parallel(max_jobs,
 			       update_clone_get_next_task,
 			       update_clone_start_failure,
 			       update_clone_task_finished,
diff --git a/git-submodule.sh b/git-submodule.sh
index a6a82d2..86018ee 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -645,6 +645,14 @@ cmd_update()
 		--depth=*)
 			depth=$1
 			;;
+		-j|--jobs)
+			case "$2" in '') usage ;; esac
+			jobs="--jobs=$2"
+			shift
+			;;
+		--jobs=*)
+			jobs=$1
+			;;
 		--)
 			shift
 			break
@@ -671,6 +679,7 @@ cmd_update()
 		${update:+--update "$update"} \
 		${reference:+--reference "$reference"} \
 		${depth:+--depth "$depth"} \
+		${jobs:+$jobs} \
 		"$@" || echo "#unmatched"
 	} | {
 	err=
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index dda3929..7fd5142 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -774,4 +774,16 @@ test_expect_success 'submodule update --recursive drops module name before recur
 	 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
 	)
 '
+
+test_expect_success 'submodule update can be run in parallel' '
+	(cd super2 &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
+	 grep "7 tasks" trace.out &&
+	 git config submodule.fetchJobs 8 &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update &&
+	 grep "8 tasks" trace.out &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
+	 grep "9 tasks" trace.out
+	)
+'
 test_done
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv17 11/11] clone: allow an explicit argument for parallel submodule clones
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (9 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 10/11] submodule update: expose parallelism to the user Stefan Beller
@ 2016-02-25  3:06 ` Stefan Beller
  2016-02-25 22:26 ` [PATCHv17 00/11] Expose submodule parallelism to the user Junio C Hamano
  11 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25  3:06 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Just pass it along to "git submodule update", which may pick reasonable
defaults if you don't specify an explicit number.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/git-clone.txt |  6 +++++-
 builtin/clone.c             | 19 +++++++++++++------
 t/t7406-submodule-update.sh | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 6bf000d..6db7b6d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 	  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
 	  [--dissociate] [--separate-git-dir <git dir>]
 	  [--depth <depth>] [--[no-]single-branch]
-	  [--recursive | --recurse-submodules] [--] <repository>
+	  [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>
 	  [<directory>]
 
 DESCRIPTION
@@ -221,6 +221,10 @@ objects from the source repository into a pack in the cloned repository.
 	The result is Git repository can be separated from working
 	tree.
 
+-j <n>::
+--jobs <n>::
+	The number of submodules fetched at the same time.
+	Defaults to the `submodule.fetchJobs` option.
 
 <repository>::
 	The (possibly remote) repository to clone from.  See the
diff --git a/builtin/clone.c b/builtin/clone.c
index a0b3cd9..b004fb4 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -50,6 +50,7 @@ static int option_progress = -1;
 static struct string_list option_config;
 static struct string_list option_reference;
 static int option_dissociate;
+static int max_jobs = -1;
 
 static struct option builtin_clone_options[] = {
 	OPT__VERBOSITY(&option_verbosity),
@@ -72,6 +73,8 @@ static struct option builtin_clone_options[] = {
 		    N_("initialize submodules in the clone")),
 	OPT_BOOL(0, "recurse-submodules", &option_recursive,
 		    N_("initialize submodules in the clone")),
+	OPT_INTEGER('j', "jobs", &max_jobs,
+		    N_("number of submodules cloned in parallel")),
 	OPT_STRING(0, "template", &option_template, N_("template-directory"),
 		   N_("directory from which templates will be used")),
 	OPT_STRING_LIST(0, "reference", &option_reference, N_("repo"),
@@ -95,10 +98,6 @@ static struct option builtin_clone_options[] = {
 	OPT_END()
 };
 
-static const char *argv_submodule[] = {
-	"submodule", "update", "--init", "--recursive", NULL
-};
-
 static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
 {
 	static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@ -724,8 +723,16 @@ static int checkout(void)
 	err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
 			   sha1_to_hex(sha1), "1", NULL);
 
-	if (!err && option_recursive)
-		err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);
+	if (!err && option_recursive) {
+		struct argv_array args = ARGV_ARRAY_INIT;
+		argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
+
+		if (max_jobs != -1)
+			argv_array_pushf(&args, "--jobs=%d", max_jobs);
+
+		err = run_command_v_opt(args.argv, RUN_GIT_CMD);
+		argv_array_clear(&args);
+	}
 
 	return err;
 }
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 7fd5142..090891e 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -786,4 +786,19 @@ test_expect_success 'submodule update can be run in parallel' '
 	 grep "9 tasks" trace.out
 	)
 '
+
+test_expect_success 'git clone passes the parallel jobs config on to submodules' '
+	test_when_finished "rm -rf super4" &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
+	grep "7 tasks" trace.out &&
+	rm -rf super4 &&
+	git config --global submodule.fetchJobs 8 &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
+	grep "8 tasks" trace.out &&
+	rm -rf super4 &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
+	grep "9 tasks" trace.out &&
+	rm -rf super4
+'
+
 test_done
-- 
2.7.2.373.g1655498.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv17 01/11] submodule-config: keep update strategy around
  2016-02-25  3:06 ` [PATCHv17 01/11] submodule-config: keep update strategy around Stefan Beller
@ 2016-02-25 18:06   ` Junio C Hamano
  2016-02-25 18:21     ` Stefan Beller
  0 siblings, 1 reply; 59+ messages in thread
From: Junio C Hamano @ 2016-02-25 18:06 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder

Stefan Beller <sbeller@google.com> writes:

> +int parse_submodule_update_strategy(const char *value,
> +		struct submodule_update_strategy *dst)
> +{
> +	free((void*)dst->command);

	free((void *)dst->command);

"git tbdiff" is quite handy; it didn't spot any other lossage of
local tweak that was in 'pu', which is good.

Thanks, will replace.

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array
  2016-02-25  3:06 ` [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
@ 2016-02-25 18:16   ` Junio C Hamano
  2016-02-25 20:35     ` Stefan Beller
  0 siblings, 1 reply; 59+ messages in thread
From: Junio C Hamano @ 2016-02-25 18:16 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder

Stefan Beller <sbeller@google.com> writes:

> @@ -1135,11 +1135,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
>  			strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
>  			strbuf_reset(&pp->children[i].err);
>  		} else {
> -			fputs(pp->children[i].err.buf, stderr);
> +			strbuf_write(&pp->children[i].err, stderr);
>  			strbuf_reset(&pp->children[i].err);
>  
>  			/* Output all other finished child processes */
> -			fputs(pp->buffered_output.buf, stderr);
> +			strbuf_write(&pp->buffered_output, stderr);
>  			strbuf_reset(&pp->buffered_output);
>  
>  			/*
> diff --git a/strbuf.c b/strbuf.c
> index 38686ff..71345cd 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
>  	return cnt;
>  }
>  
> +ssize_t strbuf_write(struct strbuf *sb, FILE *f)
> +{
> +	return fwrite(sb->buf, 1, sb->len, f);
> +}

Whenever I see a call to a function that takes size and nmemb
separately, I get worried about the case where nmemb is zero.
Hopefully everybody implements such a fwrite() as a no-op?

This may not matter in this patch as no caller checks the return
value from this function, but shouldn't the callers be a bit more
careful checking errors in the first place?

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv17 01/11] submodule-config: keep update strategy around
  2016-02-25 18:06   ` Junio C Hamano
@ 2016-02-25 18:21     ` Stefan Beller
  0 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 18:21 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git@vger.kernel.org, Jens Lehmann, Jeff King, Eric Sunshine,
	Jonathan Nieder

On Thu, Feb 25, 2016 at 10:06 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> +int parse_submodule_update_strategy(const char *value,
>> +             struct submodule_update_strategy *dst)
>> +{
>> +     free((void*)dst->command);
>
>         free((void *)dst->command);
>
> "git tbdiff" is quite handy; it didn't spot any other lossage of
> local tweak that was in 'pu', which is good.
>
> Thanks, will replace.


I usually use git diff <localbranch>.. origin/sb/feature to generate
the interdiffs,
so if you tweak things and I take these tweaks, then the interdiff is
not complete.

On the other hand if I miss the tweak, such a diff shows a revert of the tweak.

I remember applying this tweak; not sure how it got lost again.

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array
  2016-02-25 18:16   ` Junio C Hamano
@ 2016-02-25 20:35     ` Stefan Beller
  0 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 20:35 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git@vger.kernel.org, Jens Lehmann, Jeff King, Eric Sunshine,
	Jonathan Nieder

On Thu, Feb 25, 2016 at 10:16 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> @@ -1135,11 +1135,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
>>                       strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
>>                       strbuf_reset(&pp->children[i].err);
>>               } else {
>> -                     fputs(pp->children[i].err.buf, stderr);
>> +                     strbuf_write(&pp->children[i].err, stderr);
>>                       strbuf_reset(&pp->children[i].err);
>>
>>                       /* Output all other finished child processes */
>> -                     fputs(pp->buffered_output.buf, stderr);
>> +                     strbuf_write(&pp->buffered_output, stderr);
>>                       strbuf_reset(&pp->buffered_output);
>>
>>                       /*
>> diff --git a/strbuf.c b/strbuf.c
>> index 38686ff..71345cd 100644
>> --- a/strbuf.c
>> +++ b/strbuf.c
>> @@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
>>       return cnt;
>>  }
>>
>> +ssize_t strbuf_write(struct strbuf *sb, FILE *f)
>> +{
>> +     return fwrite(sb->buf, 1, sb->len, f);
>> +}
>
> Whenever I see a call to a function that takes size and nmemb
> separately, I get worried about the case where nmemb is zero.
> Hopefully everybody implements such a fwrite() as a no-op?
>
> This may not matter in this patch as no caller checks the return
> value from this function, but shouldn't the callers be a bit more
> careful checking errors in the first place?

If there is no other comment on the series, I plan on sending a patch
to fix this up afterwards to not further collide with the refs backend series.

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv17 00/11] Expose submodule parallelism to the user
  2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
                   ` (10 preceding siblings ...)
  2016-02-25  3:06 ` [PATCHv17 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
@ 2016-02-25 22:26 ` Junio C Hamano
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
  11 siblings, 1 reply; 59+ messages in thread
From: Junio C Hamano @ 2016-02-25 22:26 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder

Stefan Beller <sbeller@google.com> writes:

> This replaces origin/sb/submodule-parallel-update and applies on
> origin/sb/submodule-parallel-fetch.

This round, when applied directly on top of 62104ba1 (submodules:
allow parallel fetching, add tests and documentation, 2015-12-15),
seems to break 7400 (43, 45, 78) and 7406 (3-5), at least.

^ permalink raw reply	[flat|nested] 59+ messages in thread

* [PATCHv18 00/11] Expose
  2016-02-25 22:26 ` [PATCHv17 00/11] Expose submodule parallelism to the user Junio C Hamano
@ 2016-02-25 23:08   ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 01/11] submodule-config: keep update strategy around Stefan Beller
                       ` (13 more replies)
  0 siblings, 14 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

* fixes the test breakage (which was caused by a last minute fix :/ to the
  prefix variable handling)
* include the separately sent patch to not call fwrite in case of length 0

Thanks,
Stefan

Interdiff to v17:

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 9d94406..882aeca 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -465,14 +465,14 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		NULL
 	};
 
-	argc = parse_options(argc, argv, prefix, module_update_clone_options,
+	argc = parse_options(argc, argv, suc.prefix, module_update_clone_options,
 			     git_submodule_helper_usage, 0);
 
 	if (update)
 		if (parse_submodule_update_strategy(update, &suc.update) < 0)
 			die(_("bad value for update parameter"));
 
-	if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0)
+	if (module_list_compute(argc, argv, suc.prefix, &pathspec, &suc.list) < 0)
 		return 1;
 
 	if (pathspec.nr)
diff --git a/strbuf.c b/strbuf.c
index 71345cd..5f6da82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -397,7 +397,7 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 
 ssize_t strbuf_write(struct strbuf *sb, FILE *f)
 {
-	return fwrite(sb->buf, 1, sb->len, f);
+	return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
 }
 
Stefan Beller (11):
  submodule-config: keep update strategy around
  submodule-config: drop check against NULL
  fetching submodules: respect `submodule.fetchJobs` config option
  submodule update: direct error message to stderr
  run_processes_parallel: treat output of children as byte array
  run-command: expose default_{start_failure, task_finished}
  run_processes_parallel: rename parameters for the callbacks
  run_processes_parallel: correctly terminate callbacks with an LF
  git submodule update: have a dedicated helper for cloning
  submodule update: expose parallelism to the user
  clone: allow an explicit argument for parallel submodule clones

 Documentation/config.txt        |   6 +
 Documentation/git-clone.txt     |   6 +-
 Documentation/git-submodule.txt |   7 +-
 builtin/clone.c                 |  19 ++-
 builtin/fetch.c                 |   2 +-
 builtin/submodule--helper.c     | 254 ++++++++++++++++++++++++++++++++++++++++
 git-submodule.sh                |  56 ++++-----
 run-command.c                   |  36 +++---
 run-command.h                   |  29 ++++-
 strbuf.c                        |   6 +
 strbuf.h                        |   6 +
 submodule-config.c              |  19 ++-
 submodule-config.h              |   2 +
 submodule.c                     |  37 +++++-
 submodule.h                     |  18 +++
 t/t5526-fetch-submodules.sh     |  14 +++
 t/t7400-submodule-basic.sh      |   4 +-
 t/t7406-submodule-update.sh     |  27 +++++
 18 files changed, 477 insertions(+), 71 deletions(-)

-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 01/11] submodule-config: keep update strategy around
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 02/11] submodule-config: drop check against NULL Stefan Beller
                       ` (12 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Currently submodule.<name>.update is only handled by git-submodule.sh.
C code will start to need to make use of that value as more of the
functionality of git-submodule.sh moves into library code in C.

Add the update field to 'struct submodule' and populate it so it can
be read as sm->update or from sm->update_command.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule-config.c | 13 +++++++++++++
 submodule-config.h |  2 ++
 submodule.c        | 21 +++++++++++++++++++++
 submodule.h        | 16 ++++++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/submodule-config.c b/submodule-config.c
index afe0ea8..a5cd2ee 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -59,6 +59,7 @@ static void free_one_config(struct submodule_entry *entry)
 {
 	free((void *) entry->config->path);
 	free((void *) entry->config->name);
+	free((void *) entry->config->update_strategy.command);
 	free(entry->config);
 }
 
@@ -194,6 +195,8 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
 
 	submodule->path = NULL;
 	submodule->url = NULL;
+	submodule->update_strategy.type = SM_UPDATE_UNSPECIFIED;
+	submodule->update_strategy.command = NULL;
 	submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
 	submodule->ignore = NULL;
 
@@ -311,6 +314,16 @@ static int parse_config(const char *var, const char *value, void *data)
 			free((void *) submodule->url);
 			submodule->url = xstrdup(value);
 		}
+	} else if (!strcmp(item.buf, "update")) {
+		if (!value)
+			ret = config_error_nonbool(var);
+		else if (!me->overwrite &&
+			 submodule->update_strategy.type != SM_UPDATE_UNSPECIFIED)
+			warn_multiple_config(me->commit_sha1, submodule->name,
+					     "update");
+		else if (parse_submodule_update_strategy(value,
+			 &submodule->update_strategy) < 0)
+				die(_("invalid value for %s"), var);
 	}
 
 	strbuf_release(&name);
diff --git a/submodule-config.h b/submodule-config.h
index 9061e4e..092ebfc 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -2,6 +2,7 @@
 #define SUBMODULE_CONFIG_CACHE_H
 
 #include "hashmap.h"
+#include "submodule.h"
 #include "strbuf.h"
 
 /*
@@ -14,6 +15,7 @@ struct submodule {
 	const char *url;
 	int fetch_recurse;
 	const char *ignore;
+	struct submodule_update_strategy update_strategy;
 	/* the sha1 blob id of the responsible .gitmodules file */
 	unsigned char gitmodules_sha1[20];
 };
diff --git a/submodule.c b/submodule.c
index b83939c..b38dd51 100644
--- a/submodule.c
+++ b/submodule.c
@@ -210,6 +210,27 @@ void gitmodules_config(void)
 	}
 }
 
+int parse_submodule_update_strategy(const char *value,
+		struct submodule_update_strategy *dst)
+{
+	free((void*)dst->command);
+	dst->command = NULL;
+	if (!strcmp(value, "none"))
+		dst->type = SM_UPDATE_NONE;
+	else if (!strcmp(value, "checkout"))
+		dst->type = SM_UPDATE_CHECKOUT;
+	else if (!strcmp(value, "rebase"))
+		dst->type = SM_UPDATE_REBASE;
+	else if (!strcmp(value, "merge"))
+		dst->type = SM_UPDATE_MERGE;
+	else if (skip_prefix(value, "!", &value)) {
+		dst->type = SM_UPDATE_COMMAND;
+		dst->command = xstrdup(value);
+	} else
+		return -1;
+	return 0;
+}
+
 void handle_ignore_submodules_arg(struct diff_options *diffopt,
 				  const char *arg)
 {
diff --git a/submodule.h b/submodule.h
index cbc0003..3464500 100644
--- a/submodule.h
+++ b/submodule.h
@@ -13,6 +13,20 @@ enum {
 	RECURSE_SUBMODULES_ON = 2
 };
 
+enum submodule_update_type {
+	SM_UPDATE_UNSPECIFIED = 0,
+	SM_UPDATE_CHECKOUT,
+	SM_UPDATE_REBASE,
+	SM_UPDATE_MERGE,
+	SM_UPDATE_NONE,
+	SM_UPDATE_COMMAND
+};
+
+struct submodule_update_strategy {
+	enum submodule_update_type type;
+	const char *command;
+};
+
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
 int remove_path_from_gitmodules(const char *path);
@@ -21,6 +35,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 		const char *path);
 int submodule_config(const char *var, const char *value, void *cb);
 void gitmodules_config(void);
+int parse_submodule_update_strategy(const char *value,
+		struct submodule_update_strategy *dst);
 void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);
 void show_submodule_summary(FILE *f, const char *path,
 		const char *line_prefix,
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 02/11] submodule-config: drop check against NULL
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 01/11] submodule-config: keep update strategy around Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
                       ` (11 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Adhere to the common coding style of Git and not check explicitly
for NULL throughout the file. There are still other occurrences in the
code base but that is usually inside of conditions with side effects.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule-config.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index a5cd2ee..9fa2269 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -267,7 +267,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	if (!strcmp(item.buf, "path")) {
 		if (!value)
 			ret = config_error_nonbool(var);
-		else if (!me->overwrite && submodule->path != NULL)
+		else if (!me->overwrite && submodule->path)
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"path");
 		else {
@@ -291,7 +291,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	} else if (!strcmp(item.buf, "ignore")) {
 		if (!value)
 			ret = config_error_nonbool(var);
-		else if (!me->overwrite && submodule->ignore != NULL)
+		else if (!me->overwrite && submodule->ignore)
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"ignore");
 		else if (strcmp(value, "untracked") &&
@@ -307,7 +307,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	} else if (!strcmp(item.buf, "url")) {
 		if (!value) {
 			ret = config_error_nonbool(var);
-		} else if (!me->overwrite && submodule->url != NULL) {
+		} else if (!me->overwrite && submodule->url) {
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"url");
 		} else {
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 03/11] fetching submodules: respect `submodule.fetchJobs` config option
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 01/11] submodule-config: keep update strategy around Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 02/11] submodule-config: drop check against NULL Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 04/11] submodule update: direct error message to stderr Stefan Beller
                       ` (10 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This allows to configure fetching and updating in parallel
without having the command line option.

This moved the responsibility to determine how many parallel processes
to start from builtin/fetch to submodule.c as we need a way to communicate
"The user did not specify the number of parallel processes in the command
line options" in the builtin fetch. The submodule code takes care of
the precedence (CLI > config > default).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/config.txt    |  6 ++++++
 builtin/fetch.c             |  2 +-
 submodule.c                 | 16 +++++++++++++++-
 submodule.h                 |  2 ++
 t/t5526-fetch-submodules.sh | 14 ++++++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2d06b11..3b02732 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2646,6 +2646,12 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+submodule.fetchJobs::
+	Specifies how many submodules are fetched/cloned at the same time.
+	A positive integer allows up to that number of submodules fetched
+	in parallel. A value of 0 will give some reasonable default.
+	If unset, it defaults to 1.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 586840d..5aa1c2d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -37,7 +37,7 @@ static int prune = -1; /* unspecified */
 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int tags = TAGS_DEFAULT, unshallow, update_shallow;
-static int max_children = 1;
+static int max_children = -1;
 static const char *depth;
 static const char *upload_pack;
 static struct strbuf default_rla = STRBUF_INIT;
diff --git a/submodule.c b/submodule.c
index b38dd51..051f722 100644
--- a/submodule.c
+++ b/submodule.c
@@ -15,6 +15,7 @@
 #include "thread-utils.h"
 
 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
+static int parallel_jobs = 1;
 static struct string_list changed_submodule_paths;
 static int initialized_fetch_ref_tips;
 static struct sha1_array ref_tips_before_fetch;
@@ -169,7 +170,12 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
 int submodule_config(const char *var, const char *value, void *cb)
 {
-	if (starts_with(var, "submodule."))
+	if (!strcmp(var, "submodule.fetchjobs")) {
+		parallel_jobs = git_config_int(var, value);
+		if (parallel_jobs < 0)
+			die(_("negative values not allowed for submodule.fetchJobs"));
+		return 0;
+	} else if (starts_with(var, "submodule."))
 		return parse_submodule_config_option(var, value);
 	else if (!strcmp(var, "fetch.recursesubmodules")) {
 		config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
@@ -772,6 +778,9 @@ int fetch_populated_submodules(const struct argv_array *options,
 	argv_array_push(&spf.args, "--recurse-submodules-default");
 	/* default value, "--submodule-prefix" and its value are added later */
 
+	if (max_parallel_jobs < 0)
+		max_parallel_jobs = parallel_jobs;
+
 	calculate_changed_submodule_paths();
 	run_processes_parallel(max_parallel_jobs,
 			       get_next_submodule,
@@ -1118,3 +1127,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	strbuf_release(&rel_path);
 	free((void *)real_work_tree);
 }
+
+int parallel_submodules(void)
+{
+	return parallel_jobs;
+}
diff --git a/submodule.h b/submodule.h
index 3464500..3166608 100644
--- a/submodule.h
+++ b/submodule.h
@@ -26,6 +26,7 @@ struct submodule_update_strategy {
 	enum submodule_update_type type;
 	const char *command;
 };
+#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
 
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
@@ -57,5 +58,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+int parallel_submodules(void);
 
 #endif
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh
index 1241146..954d0e4 100755
--- a/t/t5526-fetch-submodules.sh
+++ b/t/t5526-fetch-submodules.sh
@@ -471,4 +471,18 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
 	test_i18ncmp expect.err actual.err
 '
 
+test_expect_success 'fetching submodules respects parallel settings' '
+	git config fetch.recurseSubmodules true &&
+	(
+		cd downstream &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
+		grep "7 tasks" trace.out &&
+		git config submodule.fetchJobs 8 &&
+		GIT_TRACE=$(pwd)/trace.out git fetch &&
+		grep "8 tasks" trace.out &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
+		grep "9 tasks" trace.out
+	)
+'
+
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 04/11] submodule update: direct error message to stderr
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (2 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
                       ` (9 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Reroute the error message for specified but initialized submodules
to stderr instead of stdout.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh           | 4 ++--
 t/t7400-submodule-basic.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 9bc5c5f..9ee86d4 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -693,7 +693,7 @@ cmd_update()
 
 		if test "$update_module" = "none"
 		then
-			echo "Skipping submodule '$displaypath'"
+			echo >&2 "Skipping submodule '$displaypath'"
 			continue
 		fi
 
@@ -702,7 +702,7 @@ cmd_update()
 			# Only mention uninitialized submodules when its
 			# path have been specified
 			test "$#" != "0" &&
-			say "$(eval_gettext "Submodule path '\$displaypath' not initialized
+			say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
 Maybe you want to use 'update --init'?")"
 			continue
 		fi
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 540771c..5991e3c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -462,7 +462,7 @@ test_expect_success 'update --init' '
 	git config --remove-section submodule.example &&
 	test_must_fail git config submodule.example.url &&
 
-	git submodule update init > update.out &&
+	git submodule update init 2> update.out &&
 	cat update.out &&
 	test_i18ngrep "not initialized" update.out &&
 	test_must_fail git rev-parse --resolve-git-dir init/.git &&
@@ -480,7 +480,7 @@ test_expect_success 'update --init from subdirectory' '
 	mkdir -p sub &&
 	(
 		cd sub &&
-		git submodule update ../init >update.out &&
+		git submodule update ../init 2>update.out &&
 		cat update.out &&
 		test_i18ngrep "not initialized" update.out &&
 		test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 05/11] run_processes_parallel: treat output of children as byte array
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (3 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 04/11] submodule update: direct error message to stderr Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
                       ` (8 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

We do not want the output to be interrupted by a NUL byte, so we
cannot use raw fputs. Introduce strbuf_write to avoid having long
arguments in run-command.c.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 8 ++++----
 strbuf.c      | 6 ++++++
 strbuf.h      | 6 ++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/run-command.c b/run-command.c
index 51fd72c..2f8f222 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1011,7 +1011,7 @@ static void pp_cleanup(struct parallel_processes *pp)
 	 * When get_next_task added messages to the buffer in its last
 	 * iteration, the buffered output is non empty.
 	 */
-	fputs(pp->buffered_output.buf, stderr);
+	strbuf_write(&pp->buffered_output, stderr);
 	strbuf_release(&pp->buffered_output);
 
 	sigchain_pop_common();
@@ -1097,7 +1097,7 @@ static void pp_output(struct parallel_processes *pp)
 	int i = pp->output_owner;
 	if (pp->children[i].state == GIT_CP_WORKING &&
 	    pp->children[i].err.len) {
-		fputs(pp->children[i].err.buf, stderr);
+		strbuf_write(&pp->children[i].err, stderr);
 		strbuf_reset(&pp->children[i].err);
 	}
 }
@@ -1135,11 +1135,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
 			strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
 			strbuf_reset(&pp->children[i].err);
 		} else {
-			fputs(pp->children[i].err.buf, stderr);
+			strbuf_write(&pp->children[i].err, stderr);
 			strbuf_reset(&pp->children[i].err);
 
 			/* Output all other finished child processes */
-			fputs(pp->buffered_output.buf, stderr);
+			strbuf_write(&pp->buffered_output, stderr);
 			strbuf_reset(&pp->buffered_output);
 
 			/*
diff --git a/strbuf.c b/strbuf.c
index 38686ff..5f6da82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 	return cnt;
 }
 
+ssize_t strbuf_write(struct strbuf *sb, FILE *f)
+{
+	return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
+}
+
+
 #define STRBUF_MAXLINK (2*PATH_MAX)
 
 int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
diff --git a/strbuf.h b/strbuf.h
index 2bf90e7..d4f2aa1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -387,6 +387,12 @@ extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint
 extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
 
 /**
+ * Write the whole content of the strbuf to the stream not stopping at
+ * NUL bytes.
+ */
+extern ssize_t strbuf_write(struct strbuf *sb, FILE *stream);
+
+/**
  * Read a line from a FILE *, overwriting the existing contents
  * of the strbuf. The second argument specifies the line
  * terminator character, typically `'\n'`.
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 06/11] run-command: expose default_{start_failure, task_finished}
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (4 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
                       ` (7 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

We want to reuse the error reporting facilities in a later patch.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 18 +++++++++---------
 run-command.h | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/run-command.c b/run-command.c
index 2f8f222..c9b13cf 100644
--- a/run-command.c
+++ b/run-command.c
@@ -902,10 +902,10 @@ struct parallel_processes {
 	struct strbuf buffered_output; /* of finished children */
 };
 
-static int default_start_failure(struct child_process *cp,
-				 struct strbuf *err,
-				 void *pp_cb,
-				 void *pp_task_cb)
+int default_start_failure(struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb)
 {
 	int i;
 
@@ -916,11 +916,11 @@ static int default_start_failure(struct child_process *cp,
 	return 0;
 }
 
-static int default_task_finished(int result,
-				 struct child_process *cp,
-				 struct strbuf *err,
-				 void *pp_cb,
-				 void *pp_task_cb)
+int default_task_finished(int result,
+			  struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb)
 {
 	int i;
 
diff --git a/run-command.h b/run-command.h
index d5a57f9..a054fa6 100644
--- a/run-command.h
+++ b/run-command.h
@@ -164,6 +164,15 @@ typedef int (*start_failure_fn)(struct child_process *cp,
 				void *pp_task_cb);
 
 /**
+ * If a command fails to start, then print an error message stating the
+ * exact command which failed.
+ */
+int default_start_failure(struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb);
+
+/**
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
@@ -184,6 +193,16 @@ typedef int (*task_finished_fn)(int result,
 				void *pp_task_cb);
 
 /**
+ * If the child process returns with a non zero error code, print
+ * an error message of the exact command which failed.
+ */
+int default_task_finished(int result,
+			  struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb);
+
+/**
  * Runs up to n processes at the same time. Whenever a process can be
  * started, the callback get_next_task_fn is called to obtain the data
  * required to start another child process.
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 07/11] run_processes_parallel: rename parameters for the callbacks
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (5 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
                       ` (6 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

The refs code has a similar pattern of passing around 'struct strbuf *err',
which is strictly used for error reporting. This is not the case here,
as the strbuf is used to accumulate all the output (whether it is error
or not) for the user. Rename it to 'out'.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 12 ++++++------
 run-command.h | 14 +++++++-------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/run-command.c b/run-command.c
index c9b13cf..d2964e1 100644
--- a/run-command.c
+++ b/run-command.c
@@ -903,22 +903,22 @@ struct parallel_processes {
 };
 
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
 	int i;
 
-	strbuf_addstr(err, "Starting a child failed:");
+	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
 
 	return 0;
 }
 
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
@@ -927,9 +927,9 @@ int default_task_finished(int result,
 	if (!result)
 		return 0;
 
-	strbuf_addf(err, "A child failed with return code %d:", result);
+	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
 
 	return 0;
 }
diff --git a/run-command.h b/run-command.h
index a054fa6..2bd8fee 100644
--- a/run-command.h
+++ b/run-command.h
@@ -139,7 +139,7 @@ int in_async(void);
  * return the negative signal number.
  */
 typedef int (*get_next_task_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void **pp_task_cb);
 
@@ -148,7 +148,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * a new process.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -159,7 +159,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * the negative signal number.
  */
 typedef int (*start_failure_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -168,7 +168,7 @@ typedef int (*start_failure_fn)(struct child_process *cp,
  * exact command which failed.
  */
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
@@ -176,7 +176,7 @@ int default_start_failure(struct child_process *cp,
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -188,7 +188,7 @@ int default_start_failure(struct child_process *cp,
  */
 typedef int (*task_finished_fn)(int result,
 				struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -198,7 +198,7 @@ typedef int (*task_finished_fn)(int result,
  */
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 08/11] run_processes_parallel: correctly terminate callbacks with an LF
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (6 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
                       ` (5 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

As the strbufs passed around collect all output to the user, and there
is no post processing involved we need to care about the line ending
ourselves.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/run-command.c b/run-command.c
index d2964e1..6fad42f 100644
--- a/run-command.c
+++ b/run-command.c
@@ -912,6 +912,7 @@ int default_start_failure(struct child_process *cp,
 	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
 		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
@@ -930,6 +931,7 @@ int default_task_finished(int result,
 	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
 		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 09/11] git submodule update: have a dedicated helper for cloning
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (7 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 10/11] submodule update: expose parallelism to the user Stefan Beller
                       ` (4 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This introduces a new helper function in git submodule--helper
which takes care of cloning all submodules, which we want to
parallelize eventually.

Some tests (such as empty URL, update_mode=none) are required in the
helper to make the decision for cloning. These checks have been
moved into the C function as well (no need to repeat them in the
shell script).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 248 ++++++++++++++++++++++++++++++++++++++++++++
 git-submodule.sh            |  47 +++------
 2 files changed, 261 insertions(+), 34 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f4c3eff..c852554 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -255,6 +255,253 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+struct submodule_update_clone {
+	/* index into 'list', the list of submodules to look into for cloning */
+	int current;
+	struct module_list list;
+	unsigned warn_if_uninitialized : 1;
+
+	/* update parameter passed via commandline */
+	struct submodule_update_strategy update;
+
+	/* configuration parameters which are passed on to the children */
+	int quiet;
+	const char *reference;
+	const char *depth;
+	const char *recursive_prefix;
+	const char *prefix;
+
+	/* Machine-readable status lines to be consumed by git-submodule.sh */
+	struct string_list projectlines;
+
+	/* If we want to stop as fast as possible and return an error */
+	unsigned quickstop : 1;
+};
+#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
+	SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
+	STRING_LIST_INIT_DUP, 0}
+
+/**
+ * Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
+ * run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
+ */
+static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
+					   struct child_process *child,
+					   struct submodule_update_clone *suc,
+					   struct strbuf *out)
+{
+	const struct submodule *sub = NULL;
+	struct strbuf displaypath_sb = STRBUF_INIT;
+	struct strbuf sb = STRBUF_INIT;
+	const char *displaypath = NULL;
+	char *url = NULL;
+	int needs_cloning = 0;
+
+	if (ce_stage(ce)) {
+		if (suc->recursive_prefix) {
+			strbuf_addf(out, "Skipping unmerged submodule %s/%s\n",
+				    suc->recursive_prefix, ce->name);
+		} else {
+			strbuf_addf(out, "Skipping unmerged submodule %s\n",
+				    ce->name);
+		}
+		goto cleanup;
+	}
+
+	sub = submodule_from_path(null_sha1, ce->name);
+
+	if (suc->recursive_prefix)
+		displaypath = relative_path(suc->recursive_prefix,
+					    ce->name, &displaypath_sb);
+	else
+		displaypath = ce->name;
+
+	if (suc->update.type == SM_UPDATE_NONE
+	    || (suc->update.type == SM_UPDATE_UNSPECIFIED
+		&& sub->update_strategy.type == SM_UPDATE_NONE)) {
+		strbuf_addf(out, "Skipping submodule '%s'\n",
+			    displaypath);
+		goto cleanup;
+	}
+
+	/*
+	 * Looking up the url in .git/config.
+	 * We must not fall back to .gitmodules as we only want
+	 * to process configured submodules.
+	 */
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "submodule.%s.url", sub->name);
+	git_config_get_string(sb.buf, &url);
+	if (!url) {
+		/*
+		 * Only mention uninitialized submodules when their
+		 * path have been specified
+		 */
+		if (suc->warn_if_uninitialized)
+			strbuf_addf(out, _("Submodule path '%s' not initialized\n"
+				    "Maybe you want to use 'update --init'?\n"),
+				    displaypath);
+		goto cleanup;
+	}
+
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "%s/.git", ce->name);
+	needs_cloning = !file_exists(sb.buf);
+
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode,
+			sha1_to_hex(ce->sha1), ce_stage(ce),
+			needs_cloning, ce->name);
+	string_list_append(&suc->projectlines, sb.buf);
+
+	if (!needs_cloning)
+		goto cleanup;
+
+	child->git_cmd = 1;
+	child->no_stdin = 1;
+	child->stdout_to_stderr = 1;
+	child->err = -1;
+	argv_array_push(&child->args, "submodule--helper");
+	argv_array_push(&child->args, "clone");
+	if (suc->quiet)
+		argv_array_push(&child->args, "--quiet");
+	if (suc->prefix)
+		argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
+	argv_array_pushl(&child->args, "--path", sub->path, NULL);
+	argv_array_pushl(&child->args, "--name", sub->name, NULL);
+	argv_array_pushl(&child->args, "--url", url, NULL);
+	if (suc->reference)
+		argv_array_push(&child->args, suc->reference);
+	if (suc->depth)
+		argv_array_push(&child->args, suc->depth);
+
+cleanup:
+	free(url);
+	strbuf_reset(&displaypath_sb);
+	strbuf_reset(&sb);
+
+	return needs_cloning;
+}
+
+static int update_clone_get_next_task(struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void **void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	for (; suc->current < suc->list.nr; suc->current++) {
+		const struct cache_entry *ce = suc->list.entries[suc->current];
+		if (prepare_to_clone_next_submodule(ce, child, suc, err)) {
+			suc->current++;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+static int update_clone_start_failure(struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void *void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	default_start_failure(child, err, suc_cb, void_task_cb);
+	suc->quickstop = 1;
+
+	return 1;
+}
+
+static int update_clone_task_finished(int result,
+				      struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void *void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	if (!result)
+		return 0;
+
+	default_task_finished(result, child, err, suc_cb, void_task_cb);
+	suc->quickstop = 1;
+
+	return 1;
+}
+
+static int update_clone(int argc, const char **argv, const char *prefix)
+{
+	const char *update = NULL;
+	struct string_list_item *item;
+	struct pathspec pathspec;
+	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
+
+	struct option module_update_clone_options[] = {
+		OPT_STRING(0, "prefix", &suc.prefix,
+			   N_("path"),
+			   N_("path into the working tree")),
+		OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix,
+			   N_("path"),
+			   N_("path into the working tree, across nested "
+			      "submodule boundaries")),
+		OPT_STRING(0, "update", &update,
+			   N_("string"),
+			   N_("rebase, merge, checkout or none")),
+		OPT_STRING(0, "reference", &suc.reference, N_("repo"),
+			   N_("reference repository")),
+		OPT_STRING(0, "depth", &suc.depth, "<depth>",
+			   N_("Create a shallow clone truncated to the "
+			      "specified number of revisions")),
+		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
+		OPT_END()
+	};
+
+	const char *const git_submodule_helper_usage[] = {
+		N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"),
+		NULL
+	};
+
+	argc = parse_options(argc, argv, suc.prefix, module_update_clone_options,
+			     git_submodule_helper_usage, 0);
+
+	if (update)
+		if (parse_submodule_update_strategy(update, &suc.update) < 0)
+			die(_("bad value for update parameter"));
+
+	if (module_list_compute(argc, argv, suc.prefix, &pathspec, &suc.list) < 0)
+		return 1;
+
+	if (pathspec.nr)
+		suc.warn_if_uninitialized = 1;
+
+	/* Overlay the parsed .gitmodules file with .git/config */
+	gitmodules_config();
+	git_config(submodule_config, NULL);
+
+	run_processes_parallel(1,
+			       update_clone_get_next_task,
+			       update_clone_start_failure,
+			       update_clone_task_finished,
+			       &suc);
+
+	/*
+	 * We saved the output and put it out all at once now.
+	 * That means:
+	 * - the listener does not have to interleave their (checkout)
+	 *   work with our fetching.  The writes involved in a
+	 *   checkout involve more straightforward sequential I/O.
+	 * - the listener can avoid doing any work if fetching failed.
+	 */
+	if (suc.quickstop)
+		return 1;
+
+	for_each_string_list_item(item, &suc.projectlines)
+		utf8_fprintf(stdout, "%s", item->string);
+
+	return 0;
+}
+
 struct cmd_struct {
 	const char *cmd;
 	int (*fn)(int, const char **, const char *);
@@ -264,6 +511,7 @@ static struct cmd_struct commands[] = {
 	{"list", module_list},
 	{"name", module_name},
 	{"clone", module_clone},
+	{"update-clone", update_clone}
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
diff --git a/git-submodule.sh b/git-submodule.sh
index 9ee86d4..a6a82d2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -664,17 +664,20 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
-	cloned_modules=
-	git submodule--helper list --prefix "$wt_prefix" "$@" | {
+	{
+	git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
+		${wt_prefix:+--prefix "$wt_prefix"} \
+		${prefix:+--recursive-prefix "$prefix"} \
+		${update:+--update "$update"} \
+		${reference:+--reference "$reference"} \
+		${depth:+--depth "$depth"} \
+		"$@" || echo "#unmatched"
+	} | {
 	err=
-	while read mode sha1 stage sm_path
+	while read mode sha1 stage just_cloned sm_path
 	do
 		die_if_unmatched "$mode"
-		if test "$stage" = U
-		then
-			echo >&2 "Skipping unmerged submodule $prefix$sm_path"
-			continue
-		fi
+
 		name=$(git submodule--helper name "$sm_path") || exit
 		url=$(git config submodule."$name".url)
 		branch=$(get_submodule_config "$name" branch master)
@@ -691,27 +694,10 @@ cmd_update()
 
 		displaypath=$(relative_path "$prefix$sm_path")
 
-		if test "$update_module" = "none"
-		then
-			echo >&2 "Skipping submodule '$displaypath'"
-			continue
-		fi
-
-		if test -z "$url"
-		then
-			# Only mention uninitialized submodules when its
-			# path have been specified
-			test "$#" != "0" &&
-			say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
-Maybe you want to use 'update --init'?")"
-			continue
-		fi
-
-		if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
+		if test $just_cloned -eq 1
 		then
-			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
-			cloned_modules="$cloned_modules;$name"
 			subsha1=
+			update_module=checkout
 		else
 			subsha1=$(clear_local_git_env; cd "$sm_path" &&
 				git rev-parse --verify HEAD) ||
@@ -751,13 +737,6 @@ Maybe you want to use 'update --init'?")"
 				die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
 			fi
 
-			# Is this something we just cloned?
-			case ";$cloned_modules;" in
-			*";$name;"*)
-				# then there is no local change to integrate
-				update_module=checkout ;;
-			esac
-
 			must_die_on_failure=
 			case "$update_module" in
 			checkout)
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 10/11] submodule update: expose parallelism to the user
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (8 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:08     ` [PATCHv18 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
                       ` (3 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Expose possible parallelism either via the "--jobs" CLI parameter or
the "submodule.fetchJobs" setting.

By having the variable initialized to -1, we make sure 0 can be passed
into the parallel processing machine, which will then pick as many parallel
workers as there are CPUs.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/git-submodule.txt |  7 ++++++-
 builtin/submodule--helper.c     |  8 +++++++-
 git-submodule.sh                |  9 +++++++++
 t/t7406-submodule-update.sh     | 12 ++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 1572f05..13adebf 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -16,7 +16,7 @@ SYNOPSIS
 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
 	      [-f|--force] [--rebase|--merge] [--reference <repository>]
-	      [--depth <depth>] [--recursive] [--] [<path>...]
+	      [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
 	      [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach [--recursive] <command>
@@ -377,6 +377,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
 	clone with a history truncated to the specified number of revisions.
 	See linkgit:git-clone[1]
 
+-j <n>::
+--jobs <n>::
+	This option is only valid for the update command.
+	Clone new submodules in parallel with as many jobs.
+	Defaults to the `submodule.fetchJobs` option.
 
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c852554..882aeca 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -433,6 +433,7 @@ static int update_clone_task_finished(int result,
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
 	const char *update = NULL;
+	int max_jobs = -1;
 	struct string_list_item *item;
 	struct pathspec pathspec;
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
@@ -453,6 +454,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
+		OPT_INTEGER('j', "jobs", &max_jobs,
+			    N_("parallel jobs")),
 		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
 		OPT_END()
 	};
@@ -479,7 +482,10 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	gitmodules_config();
 	git_config(submodule_config, NULL);
 
-	run_processes_parallel(1,
+	if (max_jobs < 0)
+		max_jobs = parallel_submodules();
+
+	run_processes_parallel(max_jobs,
 			       update_clone_get_next_task,
 			       update_clone_start_failure,
 			       update_clone_task_finished,
diff --git a/git-submodule.sh b/git-submodule.sh
index a6a82d2..86018ee 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -645,6 +645,14 @@ cmd_update()
 		--depth=*)
 			depth=$1
 			;;
+		-j|--jobs)
+			case "$2" in '') usage ;; esac
+			jobs="--jobs=$2"
+			shift
+			;;
+		--jobs=*)
+			jobs=$1
+			;;
 		--)
 			shift
 			break
@@ -671,6 +679,7 @@ cmd_update()
 		${update:+--update "$update"} \
 		${reference:+--reference "$reference"} \
 		${depth:+--depth "$depth"} \
+		${jobs:+$jobs} \
 		"$@" || echo "#unmatched"
 	} | {
 	err=
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index dda3929..7fd5142 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -774,4 +774,16 @@ test_expect_success 'submodule update --recursive drops module name before recur
 	 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
 	)
 '
+
+test_expect_success 'submodule update can be run in parallel' '
+	(cd super2 &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
+	 grep "7 tasks" trace.out &&
+	 git config submodule.fetchJobs 8 &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update &&
+	 grep "8 tasks" trace.out &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
+	 grep "9 tasks" trace.out
+	)
+'
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv18 11/11] clone: allow an explicit argument for parallel submodule clones
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (9 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 10/11] submodule update: expose parallelism to the user Stefan Beller
@ 2016-02-25 23:08     ` Stefan Beller
  2016-02-25 23:11     ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (2 subsequent siblings)
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:08 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Just pass it along to "git submodule update", which may pick reasonable
defaults if you don't specify an explicit number.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/git-clone.txt |  6 +++++-
 builtin/clone.c             | 19 +++++++++++++------
 t/t7406-submodule-update.sh | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 6bf000d..6db7b6d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 	  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
 	  [--dissociate] [--separate-git-dir <git dir>]
 	  [--depth <depth>] [--[no-]single-branch]
-	  [--recursive | --recurse-submodules] [--] <repository>
+	  [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>
 	  [<directory>]
 
 DESCRIPTION
@@ -221,6 +221,10 @@ objects from the source repository into a pack in the cloned repository.
 	The result is Git repository can be separated from working
 	tree.
 
+-j <n>::
+--jobs <n>::
+	The number of submodules fetched at the same time.
+	Defaults to the `submodule.fetchJobs` option.
 
 <repository>::
 	The (possibly remote) repository to clone from.  See the
diff --git a/builtin/clone.c b/builtin/clone.c
index a0b3cd9..b004fb4 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -50,6 +50,7 @@ static int option_progress = -1;
 static struct string_list option_config;
 static struct string_list option_reference;
 static int option_dissociate;
+static int max_jobs = -1;
 
 static struct option builtin_clone_options[] = {
 	OPT__VERBOSITY(&option_verbosity),
@@ -72,6 +73,8 @@ static struct option builtin_clone_options[] = {
 		    N_("initialize submodules in the clone")),
 	OPT_BOOL(0, "recurse-submodules", &option_recursive,
 		    N_("initialize submodules in the clone")),
+	OPT_INTEGER('j', "jobs", &max_jobs,
+		    N_("number of submodules cloned in parallel")),
 	OPT_STRING(0, "template", &option_template, N_("template-directory"),
 		   N_("directory from which templates will be used")),
 	OPT_STRING_LIST(0, "reference", &option_reference, N_("repo"),
@@ -95,10 +98,6 @@ static struct option builtin_clone_options[] = {
 	OPT_END()
 };
 
-static const char *argv_submodule[] = {
-	"submodule", "update", "--init", "--recursive", NULL
-};
-
 static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
 {
 	static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@ -724,8 +723,16 @@ static int checkout(void)
 	err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
 			   sha1_to_hex(sha1), "1", NULL);
 
-	if (!err && option_recursive)
-		err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);
+	if (!err && option_recursive) {
+		struct argv_array args = ARGV_ARRAY_INIT;
+		argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
+
+		if (max_jobs != -1)
+			argv_array_pushf(&args, "--jobs=%d", max_jobs);
+
+		err = run_command_v_opt(args.argv, RUN_GIT_CMD);
+		argv_array_clear(&args);
+	}
 
 	return err;
 }
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 7fd5142..090891e 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -786,4 +786,19 @@ test_expect_success 'submodule update can be run in parallel' '
 	 grep "9 tasks" trace.out
 	)
 '
+
+test_expect_success 'git clone passes the parallel jobs config on to submodules' '
+	test_when_finished "rm -rf super4" &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
+	grep "7 tasks" trace.out &&
+	rm -rf super4 &&
+	git config --global submodule.fetchJobs 8 &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
+	grep "8 tasks" trace.out &&
+	rm -rf super4 &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
+	grep "9 tasks" trace.out &&
+	rm -rf super4
+'
+
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv18 00/11] Expose
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (10 preceding siblings ...)
  2016-02-25 23:08     ` [PATCHv18 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
@ 2016-02-25 23:11     ` Stefan Beller
  2016-02-25 23:19     ` Jonathan Nieder
  2016-02-25 23:25     ` [PATCHv18 00/11] Expose Jonathan Nieder
  13 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:11 UTC (permalink / raw)
  To: Stefan Beller, git@vger.kernel.org, Jens Lehmann, Junio C Hamano
  Cc: Jeff King, Eric Sunshine, Jonathan Nieder

On Thu, Feb 25, 2016 at 3:08 PM, Stefan Beller <sbeller@google.com> wrote:
Subject: Expose

...  submodule parallelism to the user


Does git-send-email cache information after invoking it? i.e. Am I not supposed
to edit the patch files after invoking git send-mail, before
confirming to send them
out actually?

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv18 00/11] Expose
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (11 preceding siblings ...)
  2016-02-25 23:11     ` [PATCHv18 00/11] Expose Stefan Beller
@ 2016-02-25 23:19     ` Jonathan Nieder
  2016-02-25 23:25       ` Stefan Beller
  2016-02-25 23:25     ` [PATCHv18 00/11] Expose Jonathan Nieder
  13 siblings, 1 reply; 59+ messages in thread
From: Jonathan Nieder @ 2016-02-25 23:19 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jens.Lehmann, gitster, peff, sunshine

Stefan Beller wrote:

> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -465,14 +465,14 @@ static int update_clone(int argc, const char **argv, const char *prefix)
>  		NULL
>  	};
>  
> -	argc = parse_options(argc, argv, prefix, module_update_clone_options,
> +	argc = parse_options(argc, argv, suc.prefix, module_update_clone_options,
>  			     git_submodule_helper_usage, 0);

I would have expected this to use 'parse_options(argc, argv, prefix, ...' since
I wouldn't expect a command-specific --prefix= parameter to affect the
interpretation of relative filenames in other parameters.

Now that I look around more, it seems that other submodule--helper subcommands
have the same strange behavior of overwriting the 'prefix' var.  So I take
back my suggestion of using a different variable --- that can be addressed in a
separate patch that deals with them all at once.

Sorry to flip-flop like this,
Jonathan

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv18 00/11] Expose
  2016-02-25 23:19     ` Jonathan Nieder
@ 2016-02-25 23:25       ` Stefan Beller
  2016-02-25 23:35         ` Jonathan Nieder
  0 siblings, 1 reply; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:25 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: git@vger.kernel.org, Jens Lehmann, Junio C Hamano, Jeff King,
	Eric Sunshine

On Thu, Feb 25, 2016 at 3:19 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Stefan Beller wrote:
>
>> --- a/builtin/submodule--helper.c
>> +++ b/builtin/submodule--helper.c
>> @@ -465,14 +465,14 @@ static int update_clone(int argc, const char **argv, const char *prefix)
>>               NULL
>>       };
>>
>> -     argc = parse_options(argc, argv, prefix, module_update_clone_options,
>> +     argc = parse_options(argc, argv, suc.prefix, module_update_clone_options,
>>                            git_submodule_helper_usage, 0);
>
> I would have expected this to use 'parse_options(argc, argv, prefix, ...' since
> I wouldn't expect a command-specific --prefix= parameter to affect the
> interpretation of relative filenames in other parameters.
>
> Now that I look around more, it seems that other submodule--helper subcommands
> have the same strange behavior of overwriting the 'prefix' var.  So I take
> back my suggestion of using a different variable --- that can be addressed in a
> separate patch that deals with them all at once.
>
> Sorry to flip-flop like this,
> Jonathan

I plan to fix that up in all the submodule--helper commands once this
long running series is in,
but for now we want to keep it consistently awkward?

The way all submodule helper commands are currently "working" is

    (in git submodule.h:)
    wt_prefix=$(git rev-parse --show=prefix)
    cd_to_toplevel
    git submodule--helper <command> --prefix $wt_prefix

which makes the command a bit awkward with having the prefix in the
signature and the
prefix as an option. the prefix as given in the signature ought to be
empty for now and
we always rely on the prefix option.

I plan to replace that to be

    git -C $wt_prefix submodule--helper <command>

which then doesn't carry a prefix option, but can rely on the prefix
from its function
signature.

So I flip-flop that change of 'prefix' back to the way all submodule
helper operate for
now and then send a cleanup once this series is done.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv18 00/11] Expose
  2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
                       ` (12 preceding siblings ...)
  2016-02-25 23:19     ` Jonathan Nieder
@ 2016-02-25 23:25     ` Jonathan Nieder
  13 siblings, 0 replies; 59+ messages in thread
From: Jonathan Nieder @ 2016-02-25 23:25 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jens.Lehmann, gitster, peff, sunshine

Stefan Beller wrote:

> Interdiff to v17:

Except for the bit about 'prefix',

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv18 00/11] Expose
  2016-02-25 23:25       ` Stefan Beller
@ 2016-02-25 23:35         ` Jonathan Nieder
  2016-02-25 23:39           ` Junio C Hamano
  0 siblings, 1 reply; 59+ messages in thread
From: Jonathan Nieder @ 2016-02-25 23:35 UTC (permalink / raw)
  To: Stefan Beller
  Cc: git@vger.kernel.org, Jens Lehmann, Junio C Hamano, Jeff King,
	Eric Sunshine

Stefan Beller wrote:
> On Thu, Feb 25, 2016 at 3:19 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:

> > Now that I look around more, it seems that other submodule--helper subcommands
> > have the same strange behavior of overwriting the 'prefix' var.  So I take
> > back my suggestion of using a different variable --- that can be addressed in a
> > separate patch that deals with them all at once.
[...]
> I plan to fix that up in all the submodule--helper commands once this
> long running series is in,
> but for now we want to keep it consistently awkward?

Exactly.

> I plan to replace that to be
>
>     git -C $wt_prefix submodule--helper <command>
>
> which then doesn't carry a prefix option, but can rely on the prefix from its function
> signature.

Interesting --- git sets a GIT_PREFIX environment variable (in the
same spirit as GIT_WORK_TREE) but doesn't read it.  Using -C is
probably the simplest way to go.

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv18 00/11] Expose
  2016-02-25 23:35         ` Jonathan Nieder
@ 2016-02-25 23:39           ` Junio C Hamano
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
  0 siblings, 1 reply; 59+ messages in thread
From: Junio C Hamano @ 2016-02-25 23:39 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Stefan Beller, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine

On Thu, Feb 25, 2016 at 3:35 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Interesting --- git sets a GIT_PREFIX environment variable (in the
> same spirit as GIT_WORK_TREE) but doesn't read it.

I think that is because it is meant for helping end-user scripts that
are called by us;
they would not know where the end user started the process in, as one
of the first
things we do is to find the top of the working tree and go there.

^ permalink raw reply	[flat|nested] 59+ messages in thread

* [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-25 23:39           ` Junio C Hamano
@ 2016-02-25 23:48             ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 01/11] submodule-config: keep update strategy around Stefan Beller
                                 ` (12 more replies)
  0 siblings, 13 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Thanks Jonathan (and all the other cc'd reviewers) for bearing
yet another revision!

I changed the prefix handling back again as it is more consistent.

Once this series is landed, I plan to refactor the prefix handling for 
all the submodule--helper commands.

Thanks,
Stefan

Interdiff to v18:

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 882aeca..0272c98 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -439,7 +439,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
 
 	struct option module_update_clone_options[] = {
-		OPT_STRING(0, "prefix", &suc.prefix,
+		OPT_STRING(0, "prefix", &prefix,
 			   N_("path"),
 			   N_("path into the working tree")),
 		OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix,
@@ -464,15 +464,16 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"),
 		NULL
 	};
+	suc.prefix = prefix;
 
-	argc = parse_options(argc, argv, suc.prefix, module_update_clone_options,
+	argc = parse_options(argc, argv, prefix, module_update_clone_options,
 			     git_submodule_helper_usage, 0);
 
 	if (update)
 		if (parse_submodule_update_strategy(update, &suc.update) < 0)
 			die(_("bad value for update parameter"));
 
-	if (module_list_compute(argc, argv, suc.prefix, &pathspec, &suc.list) < 0)
+	if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0)
 		return 1;
 
 	if (pathspec.nr)


Stefan Beller (11):
  submodule-config: keep update strategy around
  submodule-config: drop check against NULL
  fetching submodules: respect `submodule.fetchJobs` config option
  submodule update: direct error message to stderr
  run_processes_parallel: treat output of children as byte array
  run-command: expose default_{start_failure, task_finished}
  run_processes_parallel: rename parameters for the callbacks
  run_processes_parallel: correctly terminate callbacks with an LF
  git submodule update: have a dedicated helper for cloning
  submodule update: expose parallelism to the user
  clone: allow an explicit argument for parallel submodule clones

 Documentation/config.txt        |   6 +
 Documentation/git-clone.txt     |   6 +-
 Documentation/git-submodule.txt |   7 +-
 builtin/clone.c                 |  19 ++-
 builtin/fetch.c                 |   2 +-
 builtin/submodule--helper.c     | 255 ++++++++++++++++++++++++++++++++++++++++
 git-submodule.sh                |  56 ++++-----
 run-command.c                   |  36 +++---
 run-command.h                   |  29 ++++-
 strbuf.c                        |   6 +
 strbuf.h                        |   6 +
 submodule-config.c              |  19 ++-
 submodule-config.h              |   2 +
 submodule.c                     |  37 +++++-
 submodule.h                     |  18 +++
 t/t5526-fetch-submodules.sh     |  14 +++
 t/t7400-submodule-basic.sh      |   4 +-
 t/t7406-submodule-update.sh     |  27 +++++
 18 files changed, 478 insertions(+), 71 deletions(-)

-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 01/11] submodule-config: keep update strategy around
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 02/11] submodule-config: drop check against NULL Stefan Beller
                                 ` (11 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Currently submodule.<name>.update is only handled by git-submodule.sh.
C code will start to need to make use of that value as more of the
functionality of git-submodule.sh moves into library code in C.

Add the update field to 'struct submodule' and populate it so it can
be read as sm->update or from sm->update_command.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule-config.c | 13 +++++++++++++
 submodule-config.h |  2 ++
 submodule.c        | 21 +++++++++++++++++++++
 submodule.h        | 16 ++++++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/submodule-config.c b/submodule-config.c
index afe0ea8..a5cd2ee 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -59,6 +59,7 @@ static void free_one_config(struct submodule_entry *entry)
 {
 	free((void *) entry->config->path);
 	free((void *) entry->config->name);
+	free((void *) entry->config->update_strategy.command);
 	free(entry->config);
 }
 
@@ -194,6 +195,8 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
 
 	submodule->path = NULL;
 	submodule->url = NULL;
+	submodule->update_strategy.type = SM_UPDATE_UNSPECIFIED;
+	submodule->update_strategy.command = NULL;
 	submodule->fetch_recurse = RECURSE_SUBMODULES_NONE;
 	submodule->ignore = NULL;
 
@@ -311,6 +314,16 @@ static int parse_config(const char *var, const char *value, void *data)
 			free((void *) submodule->url);
 			submodule->url = xstrdup(value);
 		}
+	} else if (!strcmp(item.buf, "update")) {
+		if (!value)
+			ret = config_error_nonbool(var);
+		else if (!me->overwrite &&
+			 submodule->update_strategy.type != SM_UPDATE_UNSPECIFIED)
+			warn_multiple_config(me->commit_sha1, submodule->name,
+					     "update");
+		else if (parse_submodule_update_strategy(value,
+			 &submodule->update_strategy) < 0)
+				die(_("invalid value for %s"), var);
 	}
 
 	strbuf_release(&name);
diff --git a/submodule-config.h b/submodule-config.h
index 9061e4e..092ebfc 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -2,6 +2,7 @@
 #define SUBMODULE_CONFIG_CACHE_H
 
 #include "hashmap.h"
+#include "submodule.h"
 #include "strbuf.h"
 
 /*
@@ -14,6 +15,7 @@ struct submodule {
 	const char *url;
 	int fetch_recurse;
 	const char *ignore;
+	struct submodule_update_strategy update_strategy;
 	/* the sha1 blob id of the responsible .gitmodules file */
 	unsigned char gitmodules_sha1[20];
 };
diff --git a/submodule.c b/submodule.c
index b83939c..b38dd51 100644
--- a/submodule.c
+++ b/submodule.c
@@ -210,6 +210,27 @@ void gitmodules_config(void)
 	}
 }
 
+int parse_submodule_update_strategy(const char *value,
+		struct submodule_update_strategy *dst)
+{
+	free((void*)dst->command);
+	dst->command = NULL;
+	if (!strcmp(value, "none"))
+		dst->type = SM_UPDATE_NONE;
+	else if (!strcmp(value, "checkout"))
+		dst->type = SM_UPDATE_CHECKOUT;
+	else if (!strcmp(value, "rebase"))
+		dst->type = SM_UPDATE_REBASE;
+	else if (!strcmp(value, "merge"))
+		dst->type = SM_UPDATE_MERGE;
+	else if (skip_prefix(value, "!", &value)) {
+		dst->type = SM_UPDATE_COMMAND;
+		dst->command = xstrdup(value);
+	} else
+		return -1;
+	return 0;
+}
+
 void handle_ignore_submodules_arg(struct diff_options *diffopt,
 				  const char *arg)
 {
diff --git a/submodule.h b/submodule.h
index cbc0003..3464500 100644
--- a/submodule.h
+++ b/submodule.h
@@ -13,6 +13,20 @@ enum {
 	RECURSE_SUBMODULES_ON = 2
 };
 
+enum submodule_update_type {
+	SM_UPDATE_UNSPECIFIED = 0,
+	SM_UPDATE_CHECKOUT,
+	SM_UPDATE_REBASE,
+	SM_UPDATE_MERGE,
+	SM_UPDATE_NONE,
+	SM_UPDATE_COMMAND
+};
+
+struct submodule_update_strategy {
+	enum submodule_update_type type;
+	const char *command;
+};
+
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
 int remove_path_from_gitmodules(const char *path);
@@ -21,6 +35,8 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 		const char *path);
 int submodule_config(const char *var, const char *value, void *cb);
 void gitmodules_config(void);
+int parse_submodule_update_strategy(const char *value,
+		struct submodule_update_strategy *dst);
 void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);
 void show_submodule_summary(FILE *f, const char *path,
 		const char *line_prefix,
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 02/11] submodule-config: drop check against NULL
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 01/11] submodule-config: keep update strategy around Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
                                 ` (10 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Adhere to the common coding style of Git and not check explicitly
for NULL throughout the file. There are still other occurrences in the
code base but that is usually inside of conditions with side effects.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule-config.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index a5cd2ee..9fa2269 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -267,7 +267,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	if (!strcmp(item.buf, "path")) {
 		if (!value)
 			ret = config_error_nonbool(var);
-		else if (!me->overwrite && submodule->path != NULL)
+		else if (!me->overwrite && submodule->path)
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"path");
 		else {
@@ -291,7 +291,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	} else if (!strcmp(item.buf, "ignore")) {
 		if (!value)
 			ret = config_error_nonbool(var);
-		else if (!me->overwrite && submodule->ignore != NULL)
+		else if (!me->overwrite && submodule->ignore)
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"ignore");
 		else if (strcmp(value, "untracked") &&
@@ -307,7 +307,7 @@ static int parse_config(const char *var, const char *value, void *data)
 	} else if (!strcmp(item.buf, "url")) {
 		if (!value) {
 			ret = config_error_nonbool(var);
-		} else if (!me->overwrite && submodule->url != NULL) {
+		} else if (!me->overwrite && submodule->url) {
 			warn_multiple_config(me->commit_sha1, submodule->name,
 					"url");
 		} else {
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 03/11] fetching submodules: respect `submodule.fetchJobs` config option
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 01/11] submodule-config: keep update strategy around Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 02/11] submodule-config: drop check against NULL Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 04/11] submodule update: direct error message to stderr Stefan Beller
                                 ` (9 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This allows to configure fetching and updating in parallel
without having the command line option.

This moved the responsibility to determine how many parallel processes
to start from builtin/fetch to submodule.c as we need a way to communicate
"The user did not specify the number of parallel processes in the command
line options" in the builtin fetch. The submodule code takes care of
the precedence (CLI > config > default).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/config.txt    |  6 ++++++
 builtin/fetch.c             |  2 +-
 submodule.c                 | 16 +++++++++++++++-
 submodule.h                 |  2 ++
 t/t5526-fetch-submodules.sh | 14 ++++++++++++++
 5 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2d06b11..3b02732 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2646,6 +2646,12 @@ submodule.<name>.ignore::
 	"--ignore-submodules" option. The 'git submodule' commands are not
 	affected by this setting.
 
+submodule.fetchJobs::
+	Specifies how many submodules are fetched/cloned at the same time.
+	A positive integer allows up to that number of submodules fetched
+	in parallel. A value of 0 will give some reasonable default.
+	If unset, it defaults to 1.
+
 tag.sort::
 	This variable controls the sort ordering of tags when displayed by
 	linkgit:git-tag[1]. Without the "--sort=<value>" option provided, the
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 586840d..5aa1c2d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -37,7 +37,7 @@ static int prune = -1; /* unspecified */
 static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int tags = TAGS_DEFAULT, unshallow, update_shallow;
-static int max_children = 1;
+static int max_children = -1;
 static const char *depth;
 static const char *upload_pack;
 static struct strbuf default_rla = STRBUF_INIT;
diff --git a/submodule.c b/submodule.c
index b38dd51..051f722 100644
--- a/submodule.c
+++ b/submodule.c
@@ -15,6 +15,7 @@
 #include "thread-utils.h"
 
 static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
+static int parallel_jobs = 1;
 static struct string_list changed_submodule_paths;
 static int initialized_fetch_ref_tips;
 static struct sha1_array ref_tips_before_fetch;
@@ -169,7 +170,12 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 
 int submodule_config(const char *var, const char *value, void *cb)
 {
-	if (starts_with(var, "submodule."))
+	if (!strcmp(var, "submodule.fetchjobs")) {
+		parallel_jobs = git_config_int(var, value);
+		if (parallel_jobs < 0)
+			die(_("negative values not allowed for submodule.fetchJobs"));
+		return 0;
+	} else if (starts_with(var, "submodule."))
 		return parse_submodule_config_option(var, value);
 	else if (!strcmp(var, "fetch.recursesubmodules")) {
 		config_fetch_recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
@@ -772,6 +778,9 @@ int fetch_populated_submodules(const struct argv_array *options,
 	argv_array_push(&spf.args, "--recurse-submodules-default");
 	/* default value, "--submodule-prefix" and its value are added later */
 
+	if (max_parallel_jobs < 0)
+		max_parallel_jobs = parallel_jobs;
+
 	calculate_changed_submodule_paths();
 	run_processes_parallel(max_parallel_jobs,
 			       get_next_submodule,
@@ -1118,3 +1127,8 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 	strbuf_release(&rel_path);
 	free((void *)real_work_tree);
 }
+
+int parallel_submodules(void)
+{
+	return parallel_jobs;
+}
diff --git a/submodule.h b/submodule.h
index 3464500..3166608 100644
--- a/submodule.h
+++ b/submodule.h
@@ -26,6 +26,7 @@ struct submodule_update_strategy {
 	enum submodule_update_type type;
 	const char *command;
 };
+#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
 
 int is_staging_gitmodules_ok(void);
 int update_path_in_gitmodules(const char *oldpath, const char *newpath);
@@ -57,5 +58,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+int parallel_submodules(void);
 
 #endif
diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh
index 1241146..954d0e4 100755
--- a/t/t5526-fetch-submodules.sh
+++ b/t/t5526-fetch-submodules.sh
@@ -471,4 +471,18 @@ test_expect_success "don't fetch submodule when newly recorded commits are alrea
 	test_i18ncmp expect.err actual.err
 '
 
+test_expect_success 'fetching submodules respects parallel settings' '
+	git config fetch.recurseSubmodules true &&
+	(
+		cd downstream &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 7 &&
+		grep "7 tasks" trace.out &&
+		git config submodule.fetchJobs 8 &&
+		GIT_TRACE=$(pwd)/trace.out git fetch &&
+		grep "8 tasks" trace.out &&
+		GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
+		grep "9 tasks" trace.out
+	)
+'
+
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 04/11] submodule update: direct error message to stderr
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (2 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
                                 ` (8 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Reroute the error message for specified but initialized submodules
to stderr instead of stdout.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 git-submodule.sh           | 4 ++--
 t/t7400-submodule-basic.sh | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 9bc5c5f..9ee86d4 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -693,7 +693,7 @@ cmd_update()
 
 		if test "$update_module" = "none"
 		then
-			echo "Skipping submodule '$displaypath'"
+			echo >&2 "Skipping submodule '$displaypath'"
 			continue
 		fi
 
@@ -702,7 +702,7 @@ cmd_update()
 			# Only mention uninitialized submodules when its
 			# path have been specified
 			test "$#" != "0" &&
-			say "$(eval_gettext "Submodule path '\$displaypath' not initialized
+			say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
 Maybe you want to use 'update --init'?")"
 			continue
 		fi
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 540771c..5991e3c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -462,7 +462,7 @@ test_expect_success 'update --init' '
 	git config --remove-section submodule.example &&
 	test_must_fail git config submodule.example.url &&
 
-	git submodule update init > update.out &&
+	git submodule update init 2> update.out &&
 	cat update.out &&
 	test_i18ngrep "not initialized" update.out &&
 	test_must_fail git rev-parse --resolve-git-dir init/.git &&
@@ -480,7 +480,7 @@ test_expect_success 'update --init from subdirectory' '
 	mkdir -p sub &&
 	(
 		cd sub &&
-		git submodule update ../init >update.out &&
+		git submodule update ../init 2>update.out &&
 		cat update.out &&
 		test_i18ngrep "not initialized" update.out &&
 		test_must_fail git rev-parse --resolve-git-dir ../init/.git &&
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 05/11] run_processes_parallel: treat output of children as byte array
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (3 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 04/11] submodule update: direct error message to stderr Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
                                 ` (7 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

We do not want the output to be interrupted by a NUL byte, so we
cannot use raw fputs. Introduce strbuf_write to avoid having long
arguments in run-command.c.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 8 ++++----
 strbuf.c      | 6 ++++++
 strbuf.h      | 6 ++++++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/run-command.c b/run-command.c
index 51fd72c..2f8f222 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1011,7 +1011,7 @@ static void pp_cleanup(struct parallel_processes *pp)
 	 * When get_next_task added messages to the buffer in its last
 	 * iteration, the buffered output is non empty.
 	 */
-	fputs(pp->buffered_output.buf, stderr);
+	strbuf_write(&pp->buffered_output, stderr);
 	strbuf_release(&pp->buffered_output);
 
 	sigchain_pop_common();
@@ -1097,7 +1097,7 @@ static void pp_output(struct parallel_processes *pp)
 	int i = pp->output_owner;
 	if (pp->children[i].state == GIT_CP_WORKING &&
 	    pp->children[i].err.len) {
-		fputs(pp->children[i].err.buf, stderr);
+		strbuf_write(&pp->children[i].err, stderr);
 		strbuf_reset(&pp->children[i].err);
 	}
 }
@@ -1135,11 +1135,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
 			strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
 			strbuf_reset(&pp->children[i].err);
 		} else {
-			fputs(pp->children[i].err.buf, stderr);
+			strbuf_write(&pp->children[i].err, stderr);
 			strbuf_reset(&pp->children[i].err);
 
 			/* Output all other finished child processes */
-			fputs(pp->buffered_output.buf, stderr);
+			strbuf_write(&pp->buffered_output, stderr);
 			strbuf_reset(&pp->buffered_output);
 
 			/*
diff --git a/strbuf.c b/strbuf.c
index 38686ff..5f6da82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -395,6 +395,12 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
 	return cnt;
 }
 
+ssize_t strbuf_write(struct strbuf *sb, FILE *f)
+{
+	return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
+}
+
+
 #define STRBUF_MAXLINK (2*PATH_MAX)
 
 int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint)
diff --git a/strbuf.h b/strbuf.h
index 2bf90e7..d4f2aa1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -387,6 +387,12 @@ extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint
 extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
 
 /**
+ * Write the whole content of the strbuf to the stream not stopping at
+ * NUL bytes.
+ */
+extern ssize_t strbuf_write(struct strbuf *sb, FILE *stream);
+
+/**
  * Read a line from a FILE *, overwriting the existing contents
  * of the strbuf. The second argument specifies the line
  * terminator character, typically `'\n'`.
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 06/11] run-command: expose default_{start_failure, task_finished}
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (4 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
                                 ` (6 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

We want to reuse the error reporting facilities in a later patch.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 18 +++++++++---------
 run-command.h | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/run-command.c b/run-command.c
index 2f8f222..c9b13cf 100644
--- a/run-command.c
+++ b/run-command.c
@@ -902,10 +902,10 @@ struct parallel_processes {
 	struct strbuf buffered_output; /* of finished children */
 };
 
-static int default_start_failure(struct child_process *cp,
-				 struct strbuf *err,
-				 void *pp_cb,
-				 void *pp_task_cb)
+int default_start_failure(struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb)
 {
 	int i;
 
@@ -916,11 +916,11 @@ static int default_start_failure(struct child_process *cp,
 	return 0;
 }
 
-static int default_task_finished(int result,
-				 struct child_process *cp,
-				 struct strbuf *err,
-				 void *pp_cb,
-				 void *pp_task_cb)
+int default_task_finished(int result,
+			  struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb)
 {
 	int i;
 
diff --git a/run-command.h b/run-command.h
index d5a57f9..a054fa6 100644
--- a/run-command.h
+++ b/run-command.h
@@ -164,6 +164,15 @@ typedef int (*start_failure_fn)(struct child_process *cp,
 				void *pp_task_cb);
 
 /**
+ * If a command fails to start, then print an error message stating the
+ * exact command which failed.
+ */
+int default_start_failure(struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb);
+
+/**
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
@@ -184,6 +193,16 @@ typedef int (*task_finished_fn)(int result,
 				void *pp_task_cb);
 
 /**
+ * If the child process returns with a non zero error code, print
+ * an error message of the exact command which failed.
+ */
+int default_task_finished(int result,
+			  struct child_process *cp,
+			  struct strbuf *err,
+			  void *pp_cb,
+			  void *pp_task_cb);
+
+/**
  * Runs up to n processes at the same time. Whenever a process can be
  * started, the callback get_next_task_fn is called to obtain the data
  * required to start another child process.
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 07/11] run_processes_parallel: rename parameters for the callbacks
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (5 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
                                 ` (5 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

The refs code has a similar pattern of passing around 'struct strbuf *err',
which is strictly used for error reporting. This is not the case here,
as the strbuf is used to accumulate all the output (whether it is error
or not) for the user. Rename it to 'out'.

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 12 ++++++------
 run-command.h | 14 +++++++-------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/run-command.c b/run-command.c
index c9b13cf..d2964e1 100644
--- a/run-command.c
+++ b/run-command.c
@@ -903,22 +903,22 @@ struct parallel_processes {
 };
 
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
 	int i;
 
-	strbuf_addstr(err, "Starting a child failed:");
+	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
 
 	return 0;
 }
 
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb)
 {
@@ -927,9 +927,9 @@ int default_task_finished(int result,
 	if (!result)
 		return 0;
 
-	strbuf_addf(err, "A child failed with return code %d:", result);
+	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
-		strbuf_addf(err, " %s", cp->argv[i]);
+		strbuf_addf(out, " %s", cp->argv[i]);
 
 	return 0;
 }
diff --git a/run-command.h b/run-command.h
index a054fa6..2bd8fee 100644
--- a/run-command.h
+++ b/run-command.h
@@ -139,7 +139,7 @@ int in_async(void);
  * return the negative signal number.
  */
 typedef int (*get_next_task_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void **pp_task_cb);
 
@@ -148,7 +148,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * a new process.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -159,7 +159,7 @@ typedef int (*get_next_task_fn)(struct child_process *cp,
  * the negative signal number.
  */
 typedef int (*start_failure_fn)(struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -168,7 +168,7 @@ typedef int (*start_failure_fn)(struct child_process *cp,
  * exact command which failed.
  */
 int default_start_failure(struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
@@ -176,7 +176,7 @@ int default_start_failure(struct child_process *cp,
  * This callback is called on every child process that finished processing.
  *
  * You must not write to stdout or stderr in this function. Add your
- * message to the strbuf err instead, which will be printed without
+ * message to the strbuf out instead, which will be printed without
  * messing up the output of the other parallel processes.
  *
  * pp_cb is the callback cookie as passed into run_processes_parallel,
@@ -188,7 +188,7 @@ int default_start_failure(struct child_process *cp,
  */
 typedef int (*task_finished_fn)(int result,
 				struct child_process *cp,
-				struct strbuf *err,
+				struct strbuf *out,
 				void *pp_cb,
 				void *pp_task_cb);
 
@@ -198,7 +198,7 @@ typedef int (*task_finished_fn)(int result,
  */
 int default_task_finished(int result,
 			  struct child_process *cp,
-			  struct strbuf *err,
+			  struct strbuf *out,
 			  void *pp_cb,
 			  void *pp_task_cb);
 
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 08/11] run_processes_parallel: correctly terminate callbacks with an LF
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (6 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
                                 ` (4 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

As the strbufs passed around collect all output to the user, and there
is no post processing involved we need to care about the line ending
ourselves.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 run-command.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/run-command.c b/run-command.c
index d2964e1..6fad42f 100644
--- a/run-command.c
+++ b/run-command.c
@@ -912,6 +912,7 @@ int default_start_failure(struct child_process *cp,
 	strbuf_addstr(out, "Starting a child failed:");
 	for (i = 0; cp->argv[i]; i++)
 		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
@@ -930,6 +931,7 @@ int default_task_finished(int result,
 	strbuf_addf(out, "A child failed with return code %d:", result);
 	for (i = 0; cp->argv[i]; i++)
 		strbuf_addf(out, " %s", cp->argv[i]);
+	strbuf_addch(out, '\n');
 
 	return 0;
 }
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (7 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-27  8:40                 ` Duy Nguyen
  2016-02-25 23:48               ` [PATCHv19 10/11] submodule update: expose parallelism to the user Stefan Beller
                                 ` (3 subsequent siblings)
  12 siblings, 1 reply; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

This introduces a new helper function in git submodule--helper
which takes care of cloning all submodules, which we want to
parallelize eventually.

Some tests (such as empty URL, update_mode=none) are required in the
helper to make the decision for cloning. These checks have been
moved into the C function as well (no need to repeat them in the
shell script).

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 249 ++++++++++++++++++++++++++++++++++++++++++++
 git-submodule.sh            |  47 +++------
 2 files changed, 262 insertions(+), 34 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f4c3eff..d119a1d 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -255,6 +255,254 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
+struct submodule_update_clone {
+	/* index into 'list', the list of submodules to look into for cloning */
+	int current;
+	struct module_list list;
+	unsigned warn_if_uninitialized : 1;
+
+	/* update parameter passed via commandline */
+	struct submodule_update_strategy update;
+
+	/* configuration parameters which are passed on to the children */
+	int quiet;
+	const char *reference;
+	const char *depth;
+	const char *recursive_prefix;
+	const char *prefix;
+
+	/* Machine-readable status lines to be consumed by git-submodule.sh */
+	struct string_list projectlines;
+
+	/* If we want to stop as fast as possible and return an error */
+	unsigned quickstop : 1;
+};
+#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
+	SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
+	STRING_LIST_INIT_DUP, 0}
+
+/**
+ * Determine whether 'ce' needs to be cloned. If so, prepare the 'child' to
+ * run the clone. Returns 1 if 'ce' needs to be cloned, 0 otherwise.
+ */
+static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
+					   struct child_process *child,
+					   struct submodule_update_clone *suc,
+					   struct strbuf *out)
+{
+	const struct submodule *sub = NULL;
+	struct strbuf displaypath_sb = STRBUF_INIT;
+	struct strbuf sb = STRBUF_INIT;
+	const char *displaypath = NULL;
+	char *url = NULL;
+	int needs_cloning = 0;
+
+	if (ce_stage(ce)) {
+		if (suc->recursive_prefix) {
+			strbuf_addf(out, "Skipping unmerged submodule %s/%s\n",
+				    suc->recursive_prefix, ce->name);
+		} else {
+			strbuf_addf(out, "Skipping unmerged submodule %s\n",
+				    ce->name);
+		}
+		goto cleanup;
+	}
+
+	sub = submodule_from_path(null_sha1, ce->name);
+
+	if (suc->recursive_prefix)
+		displaypath = relative_path(suc->recursive_prefix,
+					    ce->name, &displaypath_sb);
+	else
+		displaypath = ce->name;
+
+	if (suc->update.type == SM_UPDATE_NONE
+	    || (suc->update.type == SM_UPDATE_UNSPECIFIED
+		&& sub->update_strategy.type == SM_UPDATE_NONE)) {
+		strbuf_addf(out, "Skipping submodule '%s'\n",
+			    displaypath);
+		goto cleanup;
+	}
+
+	/*
+	 * Looking up the url in .git/config.
+	 * We must not fall back to .gitmodules as we only want
+	 * to process configured submodules.
+	 */
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "submodule.%s.url", sub->name);
+	git_config_get_string(sb.buf, &url);
+	if (!url) {
+		/*
+		 * Only mention uninitialized submodules when their
+		 * path have been specified
+		 */
+		if (suc->warn_if_uninitialized)
+			strbuf_addf(out, _("Submodule path '%s' not initialized\n"
+				    "Maybe you want to use 'update --init'?\n"),
+				    displaypath);
+		goto cleanup;
+	}
+
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "%s/.git", ce->name);
+	needs_cloning = !file_exists(sb.buf);
+
+	strbuf_reset(&sb);
+	strbuf_addf(&sb, "%06o %s %d %d\t%s\n", ce->ce_mode,
+			sha1_to_hex(ce->sha1), ce_stage(ce),
+			needs_cloning, ce->name);
+	string_list_append(&suc->projectlines, sb.buf);
+
+	if (!needs_cloning)
+		goto cleanup;
+
+	child->git_cmd = 1;
+	child->no_stdin = 1;
+	child->stdout_to_stderr = 1;
+	child->err = -1;
+	argv_array_push(&child->args, "submodule--helper");
+	argv_array_push(&child->args, "clone");
+	if (suc->quiet)
+		argv_array_push(&child->args, "--quiet");
+	if (suc->prefix)
+		argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
+	argv_array_pushl(&child->args, "--path", sub->path, NULL);
+	argv_array_pushl(&child->args, "--name", sub->name, NULL);
+	argv_array_pushl(&child->args, "--url", url, NULL);
+	if (suc->reference)
+		argv_array_push(&child->args, suc->reference);
+	if (suc->depth)
+		argv_array_push(&child->args, suc->depth);
+
+cleanup:
+	free(url);
+	strbuf_reset(&displaypath_sb);
+	strbuf_reset(&sb);
+
+	return needs_cloning;
+}
+
+static int update_clone_get_next_task(struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void **void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	for (; suc->current < suc->list.nr; suc->current++) {
+		const struct cache_entry *ce = suc->list.entries[suc->current];
+		if (prepare_to_clone_next_submodule(ce, child, suc, err)) {
+			suc->current++;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+static int update_clone_start_failure(struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void *void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	default_start_failure(child, err, suc_cb, void_task_cb);
+	suc->quickstop = 1;
+
+	return 1;
+}
+
+static int update_clone_task_finished(int result,
+				      struct child_process *child,
+				      struct strbuf *err,
+				      void *suc_cb,
+				      void *void_task_cb)
+{
+	struct submodule_update_clone *suc = suc_cb;
+
+	if (!result)
+		return 0;
+
+	default_task_finished(result, child, err, suc_cb, void_task_cb);
+	suc->quickstop = 1;
+
+	return 1;
+}
+
+static int update_clone(int argc, const char **argv, const char *prefix)
+{
+	const char *update = NULL;
+	struct string_list_item *item;
+	struct pathspec pathspec;
+	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
+
+	struct option module_update_clone_options[] = {
+		OPT_STRING(0, "prefix", &prefix,
+			   N_("path"),
+			   N_("path into the working tree")),
+		OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix,
+			   N_("path"),
+			   N_("path into the working tree, across nested "
+			      "submodule boundaries")),
+		OPT_STRING(0, "update", &update,
+			   N_("string"),
+			   N_("rebase, merge, checkout or none")),
+		OPT_STRING(0, "reference", &suc.reference, N_("repo"),
+			   N_("reference repository")),
+		OPT_STRING(0, "depth", &suc.depth, "<depth>",
+			   N_("Create a shallow clone truncated to the "
+			      "specified number of revisions")),
+		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
+		OPT_END()
+	};
+
+	const char *const git_submodule_helper_usage[] = {
+		N_("git submodule--helper update_clone [--prefix=<path>] [<path>...]"),
+		NULL
+	};
+	suc.prefix = prefix;
+
+	argc = parse_options(argc, argv, prefix, module_update_clone_options,
+			     git_submodule_helper_usage, 0);
+
+	if (update)
+		if (parse_submodule_update_strategy(update, &suc.update) < 0)
+			die(_("bad value for update parameter"));
+
+	if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0)
+		return 1;
+
+	if (pathspec.nr)
+		suc.warn_if_uninitialized = 1;
+
+	/* Overlay the parsed .gitmodules file with .git/config */
+	gitmodules_config();
+	git_config(submodule_config, NULL);
+
+	run_processes_parallel(1,
+			       update_clone_get_next_task,
+			       update_clone_start_failure,
+			       update_clone_task_finished,
+			       &suc);
+
+	/*
+	 * We saved the output and put it out all at once now.
+	 * That means:
+	 * - the listener does not have to interleave their (checkout)
+	 *   work with our fetching.  The writes involved in a
+	 *   checkout involve more straightforward sequential I/O.
+	 * - the listener can avoid doing any work if fetching failed.
+	 */
+	if (suc.quickstop)
+		return 1;
+
+	for_each_string_list_item(item, &suc.projectlines)
+		utf8_fprintf(stdout, "%s", item->string);
+
+	return 0;
+}
+
 struct cmd_struct {
 	const char *cmd;
 	int (*fn)(int, const char **, const char *);
@@ -264,6 +512,7 @@ static struct cmd_struct commands[] = {
 	{"list", module_list},
 	{"name", module_name},
 	{"clone", module_clone},
+	{"update-clone", update_clone}
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
diff --git a/git-submodule.sh b/git-submodule.sh
index 9ee86d4..a6a82d2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -664,17 +664,20 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
-	cloned_modules=
-	git submodule--helper list --prefix "$wt_prefix" "$@" | {
+	{
+	git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
+		${wt_prefix:+--prefix "$wt_prefix"} \
+		${prefix:+--recursive-prefix "$prefix"} \
+		${update:+--update "$update"} \
+		${reference:+--reference "$reference"} \
+		${depth:+--depth "$depth"} \
+		"$@" || echo "#unmatched"
+	} | {
 	err=
-	while read mode sha1 stage sm_path
+	while read mode sha1 stage just_cloned sm_path
 	do
 		die_if_unmatched "$mode"
-		if test "$stage" = U
-		then
-			echo >&2 "Skipping unmerged submodule $prefix$sm_path"
-			continue
-		fi
+
 		name=$(git submodule--helper name "$sm_path") || exit
 		url=$(git config submodule."$name".url)
 		branch=$(get_submodule_config "$name" branch master)
@@ -691,27 +694,10 @@ cmd_update()
 
 		displaypath=$(relative_path "$prefix$sm_path")
 
-		if test "$update_module" = "none"
-		then
-			echo >&2 "Skipping submodule '$displaypath'"
-			continue
-		fi
-
-		if test -z "$url"
-		then
-			# Only mention uninitialized submodules when its
-			# path have been specified
-			test "$#" != "0" &&
-			say >&2 "$(eval_gettext "Submodule path '\$displaypath' not initialized
-Maybe you want to use 'update --init'?")"
-			continue
-		fi
-
-		if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
+		if test $just_cloned -eq 1
 		then
-			git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$prefix" --path "$sm_path" --name "$name" --url "$url" "$reference" "$depth" || exit
-			cloned_modules="$cloned_modules;$name"
 			subsha1=
+			update_module=checkout
 		else
 			subsha1=$(clear_local_git_env; cd "$sm_path" &&
 				git rev-parse --verify HEAD) ||
@@ -751,13 +737,6 @@ Maybe you want to use 'update --init'?")"
 				die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
 			fi
 
-			# Is this something we just cloned?
-			case ";$cloned_modules;" in
-			*";$name;"*)
-				# then there is no local change to integrate
-				update_module=checkout ;;
-			esac
-
 			must_die_on_failure=
 			case "$update_module" in
 			checkout)
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 10/11] submodule update: expose parallelism to the user
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (8 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:48               ` [PATCHv19 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
                                 ` (2 subsequent siblings)
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Expose possible parallelism either via the "--jobs" CLI parameter or
the "submodule.fetchJobs" setting.

By having the variable initialized to -1, we make sure 0 can be passed
into the parallel processing machine, which will then pick as many parallel
workers as there are CPUs.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/git-submodule.txt |  7 ++++++-
 builtin/submodule--helper.c     |  8 +++++++-
 git-submodule.sh                |  9 +++++++++
 t/t7406-submodule-update.sh     | 12 ++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 1572f05..13adebf 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -16,7 +16,7 @@ SYNOPSIS
 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
 	      [-f|--force] [--rebase|--merge] [--reference <repository>]
-	      [--depth <depth>] [--recursive] [--] [<path>...]
+	      [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
 	      [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach [--recursive] <command>
@@ -377,6 +377,11 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
 	clone with a history truncated to the specified number of revisions.
 	See linkgit:git-clone[1]
 
+-j <n>::
+--jobs <n>::
+	This option is only valid for the update command.
+	Clone new submodules in parallel with as many jobs.
+	Defaults to the `submodule.fetchJobs` option.
 
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index d119a1d..0272c98 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -433,6 +433,7 @@ static int update_clone_task_finished(int result,
 static int update_clone(int argc, const char **argv, const char *prefix)
 {
 	const char *update = NULL;
+	int max_jobs = -1;
 	struct string_list_item *item;
 	struct pathspec pathspec;
 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
@@ -453,6 +454,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "depth", &suc.depth, "<depth>",
 			   N_("Create a shallow clone truncated to the "
 			      "specified number of revisions")),
+		OPT_INTEGER('j', "jobs", &max_jobs,
+			    N_("parallel jobs")),
 		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
 		OPT_END()
 	};
@@ -480,7 +483,10 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 	gitmodules_config();
 	git_config(submodule_config, NULL);
 
-	run_processes_parallel(1,
+	if (max_jobs < 0)
+		max_jobs = parallel_submodules();
+
+	run_processes_parallel(max_jobs,
 			       update_clone_get_next_task,
 			       update_clone_start_failure,
 			       update_clone_task_finished,
diff --git a/git-submodule.sh b/git-submodule.sh
index a6a82d2..86018ee 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -645,6 +645,14 @@ cmd_update()
 		--depth=*)
 			depth=$1
 			;;
+		-j|--jobs)
+			case "$2" in '') usage ;; esac
+			jobs="--jobs=$2"
+			shift
+			;;
+		--jobs=*)
+			jobs=$1
+			;;
 		--)
 			shift
 			break
@@ -671,6 +679,7 @@ cmd_update()
 		${update:+--update "$update"} \
 		${reference:+--reference "$reference"} \
 		${depth:+--depth "$depth"} \
+		${jobs:+$jobs} \
 		"$@" || echo "#unmatched"
 	} | {
 	err=
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index dda3929..7fd5142 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -774,4 +774,16 @@ test_expect_success 'submodule update --recursive drops module name before recur
 	 test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual
 	)
 '
+
+test_expect_success 'submodule update can be run in parallel' '
+	(cd super2 &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 7 &&
+	 grep "7 tasks" trace.out &&
+	 git config submodule.fetchJobs 8 &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update &&
+	 grep "8 tasks" trace.out &&
+	 GIT_TRACE=$(pwd)/trace.out git submodule update --jobs 9 &&
+	 grep "9 tasks" trace.out
+	)
+'
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* [PATCHv19 11/11] clone: allow an explicit argument for parallel submodule clones
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (9 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 10/11] submodule update: expose parallelism to the user Stefan Beller
@ 2016-02-25 23:48               ` Stefan Beller
  2016-02-25 23:50               ` [PATCHv19 00/11] Expose submodule parallelism to the user Jonathan Nieder
  2016-02-29 20:48               ` Johannes Sixt
  12 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-25 23:48 UTC (permalink / raw)
  To: sbeller, git, Jens.Lehmann, gitster; +Cc: peff, sunshine, jrnieder

Just pass it along to "git submodule update", which may pick reasonable
defaults if you don't specify an explicit number.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 Documentation/git-clone.txt |  6 +++++-
 builtin/clone.c             | 19 +++++++++++++------
 t/t7406-submodule-update.sh | 15 +++++++++++++++
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 6bf000d..6db7b6d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 	  [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
 	  [--dissociate] [--separate-git-dir <git dir>]
 	  [--depth <depth>] [--[no-]single-branch]
-	  [--recursive | --recurse-submodules] [--] <repository>
+	  [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository>
 	  [<directory>]
 
 DESCRIPTION
@@ -221,6 +221,10 @@ objects from the source repository into a pack in the cloned repository.
 	The result is Git repository can be separated from working
 	tree.
 
+-j <n>::
+--jobs <n>::
+	The number of submodules fetched at the same time.
+	Defaults to the `submodule.fetchJobs` option.
 
 <repository>::
 	The (possibly remote) repository to clone from.  See the
diff --git a/builtin/clone.c b/builtin/clone.c
index a0b3cd9..b004fb4 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -50,6 +50,7 @@ static int option_progress = -1;
 static struct string_list option_config;
 static struct string_list option_reference;
 static int option_dissociate;
+static int max_jobs = -1;
 
 static struct option builtin_clone_options[] = {
 	OPT__VERBOSITY(&option_verbosity),
@@ -72,6 +73,8 @@ static struct option builtin_clone_options[] = {
 		    N_("initialize submodules in the clone")),
 	OPT_BOOL(0, "recurse-submodules", &option_recursive,
 		    N_("initialize submodules in the clone")),
+	OPT_INTEGER('j', "jobs", &max_jobs,
+		    N_("number of submodules cloned in parallel")),
 	OPT_STRING(0, "template", &option_template, N_("template-directory"),
 		   N_("directory from which templates will be used")),
 	OPT_STRING_LIST(0, "reference", &option_reference, N_("repo"),
@@ -95,10 +98,6 @@ static struct option builtin_clone_options[] = {
 	OPT_END()
 };
 
-static const char *argv_submodule[] = {
-	"submodule", "update", "--init", "--recursive", NULL
-};
-
 static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)
 {
 	static char *suffix[] = { "/.git", "", ".git/.git", ".git" };
@@ -724,8 +723,16 @@ static int checkout(void)
 	err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
 			   sha1_to_hex(sha1), "1", NULL);
 
-	if (!err && option_recursive)
-		err = run_command_v_opt(argv_submodule, RUN_GIT_CMD);
+	if (!err && option_recursive) {
+		struct argv_array args = ARGV_ARRAY_INIT;
+		argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
+
+		if (max_jobs != -1)
+			argv_array_pushf(&args, "--jobs=%d", max_jobs);
+
+		err = run_command_v_opt(args.argv, RUN_GIT_CMD);
+		argv_array_clear(&args);
+	}
 
 	return err;
 }
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 7fd5142..090891e 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -786,4 +786,19 @@ test_expect_success 'submodule update can be run in parallel' '
 	 grep "9 tasks" trace.out
 	)
 '
+
+test_expect_success 'git clone passes the parallel jobs config on to submodules' '
+	test_when_finished "rm -rf super4" &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 7 . super4 &&
+	grep "7 tasks" trace.out &&
+	rm -rf super4 &&
+	git config --global submodule.fetchJobs 8 &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules . super4 &&
+	grep "8 tasks" trace.out &&
+	rm -rf super4 &&
+	GIT_TRACE=$(pwd)/trace.out git clone --recurse-submodules --jobs 9 . super4 &&
+	grep "9 tasks" trace.out &&
+	rm -rf super4
+'
+
 test_done
-- 
2.7.0.rc0.36.g75877e4.dirty

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (10 preceding siblings ...)
  2016-02-25 23:48               ` [PATCHv19 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
@ 2016-02-25 23:50               ` Jonathan Nieder
  2016-02-29 20:48               ` Johannes Sixt
  12 siblings, 0 replies; 59+ messages in thread
From: Jonathan Nieder @ 2016-02-25 23:50 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git, Jens.Lehmann, gitster, peff, sunshine

Stefan Beller wrote:

> Thanks Jonathan (and all the other cc'd reviewers) for bearing
> yet another revision!

Thanks.  This one looks good.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning
  2016-02-25 23:48               ` [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
@ 2016-02-27  8:40                 ` Duy Nguyen
  2016-02-29 19:03                   ` Stefan Beller
  0 siblings, 1 reply; 59+ messages in thread
From: Duy Nguyen @ 2016-02-27  8:40 UTC (permalink / raw)
  To: Stefan Beller
  Cc: Git Mailing List, Jens Lehmann, Junio C Hamano, Jeff King,
	Eric Sunshine, Jonathan Nieder

On Fri, Feb 26, 2016 at 6:48 AM, Stefan Beller <sbeller@google.com> wrote:
> +static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
> +                                          struct child_process *child,
> +                                          struct submodule_update_clone *suc,
> +                                          struct strbuf *out)
> +{
> +       const struct submodule *sub = NULL;
> +       struct strbuf displaypath_sb = STRBUF_INIT;
> +       struct strbuf sb = STRBUF_INIT;
> +       const char *displaypath = NULL;
> +       char *url = NULL;
> +       int needs_cloning = 0;
> +
> +       if (ce_stage(ce)) {
> +               if (suc->recursive_prefix) {
> +                       strbuf_addf(out, "Skipping unmerged submodule %s/%s\n",
> +                                   suc->recursive_prefix, ce->name);

I'm pretty sure this string is for human consumption (because it's
_()'d elsehwere in this function), please _() this string.

> +               } else {
> +                       strbuf_addf(out, "Skipping unmerged submodule %s\n",
> +                                   ce->name);

and this one

> +               }
> +               goto cleanup;
> +       }
> +
> +       sub = submodule_from_path(null_sha1, ce->name);
> +
> +       if (suc->recursive_prefix)
> +               displaypath = relative_path(suc->recursive_prefix,
> +                                           ce->name, &displaypath_sb);
> +       else
> +               displaypath = ce->name;
> +
> +       if (suc->update.type == SM_UPDATE_NONE
> +           || (suc->update.type == SM_UPDATE_UNSPECIFIED
> +               && sub->update_strategy.type == SM_UPDATE_NONE)) {
> +               strbuf_addf(out, "Skipping submodule '%s'\n",
> +                           displaypath);

and this one

> +               goto cleanup;
> +       }
> +
> +       /*
> +        * Looking up the url in .git/config.
> +        * We must not fall back to .gitmodules as we only want
> +        * to process configured submodules.
> +        */
> +       strbuf_reset(&sb);
> +       strbuf_addf(&sb, "submodule.%s.url", sub->name);
> +       git_config_get_string(sb.buf, &url);
> +       if (!url) {
> +               /*
> +                * Only mention uninitialized submodules when their
> +                * path have been specified
> +                */
> +               if (suc->warn_if_uninitialized)
> +                       strbuf_addf(out, _("Submodule path '%s' not initialized\n"
> +                                   "Maybe you want to use 'update --init'?\n"),
> +                                   displaypath);

oh it's already marked :)

BTW, while you're editing this file, perhaps do this too (maybe in a
separate patch)? Because die() already prepends "fatal:"

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a6e54fa..6cf47de 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -731,13 +731,13 @@ int cmd_submodule__helper(int argc, const char
**argv, const char *prefix)
 {
        int i;
        if (argc < 2)
-               die(_("fatal: submodule--helper subcommand must be "
+               die(_("submodule--helper subcommand must be "
                      "called with a subcommand"));

        for (i = 0; i < ARRAY_SIZE(commands); i++)
                if (!strcmp(argv[1], commands[i].cmd))
                        return commands[i].fn(argc - 1, argv + 1, prefix);

-       die(_("fatal: '%s' is not a valid submodule--helper "
+       die(_("'%s' is not a valid submodule--helper "
              "subcommand"), argv[1]);
 }
-- 
Duy

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning
  2016-02-27  8:40                 ` Duy Nguyen
@ 2016-02-29 19:03                   ` Stefan Beller
  0 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-29 19:03 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: Git Mailing List, Jens Lehmann, Junio C Hamano, Jeff King,
	Eric Sunshine, Jonathan Nieder

On Sat, Feb 27, 2016 at 12:40 AM, Duy Nguyen <pclouds@gmail.com> wrote:
> On Fri, Feb 26, 2016 at 6:48 AM, Stefan Beller <sbeller@google.com> wrote:
>> +static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
>> +                                          struct child_process *child,
>> +                                          struct submodule_update_clone *suc,
>> +                                          struct strbuf *out)
>> +{
>> +       const struct submodule *sub = NULL;
>> +       struct strbuf displaypath_sb = STRBUF_INIT;
>> +       struct strbuf sb = STRBUF_INIT;
>> +       const char *displaypath = NULL;
>> +       char *url = NULL;
>> +       int needs_cloning = 0;
>> +
>> +       if (ce_stage(ce)) {
>> +               if (suc->recursive_prefix) {
>> +                       strbuf_addf(out, "Skipping unmerged submodule %s/%s\n",
>> +                                   suc->recursive_prefix, ce->name);
>
> I'm pretty sure this string is for human consumption (because it's
> _()'d elsehwere in this function), please _() this string.
>
>> +               } else {
>> +                       strbuf_addf(out, "Skipping unmerged submodule %s\n",
>> +                                   ce->name);
>
> and this one
>
>> +               }
>> +               goto cleanup;
>> +       }
>> +
>> +       sub = submodule_from_path(null_sha1, ce->name);
>> +
>> +       if (suc->recursive_prefix)
>> +               displaypath = relative_path(suc->recursive_prefix,
>> +                                           ce->name, &displaypath_sb);
>> +       else
>> +               displaypath = ce->name;
>> +
>> +       if (suc->update.type == SM_UPDATE_NONE
>> +           || (suc->update.type == SM_UPDATE_UNSPECIFIED
>> +               && sub->update_strategy.type == SM_UPDATE_NONE)) {
>> +               strbuf_addf(out, "Skipping submodule '%s'\n",
>> +                           displaypath);
>
> and this one
>
>> +               goto cleanup;
>> +       }
>> +
>> +       /*
>> +        * Looking up the url in .git/config.
>> +        * We must not fall back to .gitmodules as we only want
>> +        * to process configured submodules.
>> +        */
>> +       strbuf_reset(&sb);
>> +       strbuf_addf(&sb, "submodule.%s.url", sub->name);
>> +       git_config_get_string(sb.buf, &url);
>> +       if (!url) {
>> +               /*
>> +                * Only mention uninitialized submodules when their
>> +                * path have been specified
>> +                */
>> +               if (suc->warn_if_uninitialized)
>> +                       strbuf_addf(out, _("Submodule path '%s' not initialized\n"
>> +                                   "Maybe you want to use 'update --init'?\n"),
>> +                                   displaypath);
>
> oh it's already marked :)
>
> BTW, while you're editing this file, perhaps do this too (maybe in a
> separate patch)? Because die() already prepends "fatal:"

Makes sense. As builtin/submodule--helper.c was introduced in 2.7.0
and translation has already started fr 2.8.0, I'll just pick it up as
part of this series
instead of sending a bugfix patch alone.

Thanks for review!

>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index a6e54fa..6cf47de 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -731,13 +731,13 @@ int cmd_submodule__helper(int argc, const char
> **argv, const char *prefix)
>  {
>         int i;
>         if (argc < 2)
> -               die(_("fatal: submodule--helper subcommand must be "
> +               die(_("submodule--helper subcommand must be "
>                       "called with a subcommand"));
>
>         for (i = 0; i < ARRAY_SIZE(commands); i++)
>                 if (!strcmp(argv[1], commands[i].cmd))
>                         return commands[i].fn(argc - 1, argv + 1, prefix);
>
> -       die(_("fatal: '%s' is not a valid submodule--helper "
> +       die(_("'%s' is not a valid submodule--helper "
>               "subcommand"), argv[1]);
>  }
> --
> Duy

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
                                 ` (11 preceding siblings ...)
  2016-02-25 23:50               ` [PATCHv19 00/11] Expose submodule parallelism to the user Jonathan Nieder
@ 2016-02-29 20:48               ` Johannes Sixt
  2016-02-29 20:59                 ` Stefan Beller
  2016-02-29 21:01                 ` Junio C Hamano
  12 siblings, 2 replies; 59+ messages in thread
From: Johannes Sixt @ 2016-02-29 20:48 UTC (permalink / raw)
  To: Stefan Beller, gitster; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder

Hi folks,

we have a major breakage in the parallel tasks infrastructure, and I'm
afraid it is already in master.

Instrument the code in sb/submodule-parallel-update like this and enjoy
the fireworks of './t7400-submodule-basic.sh -v -i -x --debug':

diff --git a/git-submodule.sh b/git-submodule.sh
index 0322282..482c7f6 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -690,8 +690,9 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
+	set -x
 	{
-	git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
+	valgrind git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
 		${wt_prefix:+--prefix "$wt_prefix"} \
 		${prefix:+--recursive-prefix "$prefix"} \
 		${update:+--update "$update"} \
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 5572327..717e491 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -337,6 +337,7 @@ test_expect_success 'update should fail when path is used by a file' '
 
 	echo "hello" >init &&
 	test_must_fail git submodule update &&
+	false &&
 
 	test_cmp expect init
 '

The culprit seems to be default_task_finished(), which accesses argv[]
of the struct child_process after finish_command has released it,
provided the child exited with an error, for example:

==3395== Invalid read of size 8
==3395==    at 0x54F991: default_task_finished (run-command.c:932)
==3395==    by 0x49158F: update_clone_task_finished (submodule--helper.c:421)
==3395==    by 0x5504A2: pp_collect_finished (run-command.c:1122)
==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
==3395==    by 0x405CBE: run_builtin (git.c:353)
==3395==    by 0x405EAA: handle_builtin (git.c:540)
==3395==    by 0x405FCC: run_argv (git.c:594)
==3395==    by 0x4061BF: main (git.c:701)
==3395==  Address 0x5e49370 is 0 bytes inside a block of size 192 free'd
==3395==    at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==3395==    by 0x4A26EE: argv_array_clear (argv-array.c:73)
==3395==    by 0x54DFC4: child_process_clear (run-command.c:18)
==3395==    by 0x54EFA7: finish_command (run-command.c:539)
==3395==    by 0x550413: pp_collect_finished (run-command.c:1120)
==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
==3395==    by 0x405CBE: run_builtin (git.c:353)
==3395==    by 0x405EAA: handle_builtin (git.c:540)
==3395==    by 0x405FCC: run_argv (git.c:594)
==3395==    by 0x4061BF: main (git.c:701)

I haven't thought about a solution, yet. Perhaps you have ideas.

-- Hannes

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 20:48               ` Johannes Sixt
@ 2016-02-29 20:59                 ` Stefan Beller
  2016-02-29 21:01                 ` Junio C Hamano
  1 sibling, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-29 20:59 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Junio C Hamano, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine, Jonathan Nieder

On Mon, Feb 29, 2016 at 12:48 PM, Johannes Sixt <j6t@kdbg.org> wrote:
> Hi folks,
>
> we have a major breakage in the parallel tasks infrastructure, and I'm
> afraid it is already in master.
>
> Instrument the code in sb/submodule-parallel-update like this and enjoy
> the fireworks of './t7400-submodule-basic.sh -v -i -x --debug':
>
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 0322282..482c7f6 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -690,8 +690,9 @@ cmd_update()
>                 cmd_init "--" "$@" || return
>         fi
>
> +       set -x
>         {
> -       git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
> +       valgrind git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
>                 ${wt_prefix:+--prefix "$wt_prefix"} \
>                 ${prefix:+--recursive-prefix "$prefix"} \
>                 ${update:+--update "$update"} \
> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index 5572327..717e491 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -337,6 +337,7 @@ test_expect_success 'update should fail when path is used by a file' '
>
>         echo "hello" >init &&
>         test_must_fail git submodule update &&
> +       false &&
>
>         test_cmp expect init
>  '
>
> The culprit seems to be default_task_finished(), which accesses argv[]
> of the struct child_process after finish_command has released it,
> provided the child exited with an error, for example:
>
> ==3395== Invalid read of size 8
> ==3395==    at 0x54F991: default_task_finished (run-command.c:932)
> ==3395==    by 0x49158F: update_clone_task_finished (submodule--helper.c:421)
> ==3395==    by 0x5504A2: pp_collect_finished (run-command.c:1122)
> ==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
> ==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
> ==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
> ==3395==    by 0x405CBE: run_builtin (git.c:353)
> ==3395==    by 0x405EAA: handle_builtin (git.c:540)
> ==3395==    by 0x405FCC: run_argv (git.c:594)
> ==3395==    by 0x4061BF: main (git.c:701)
> ==3395==  Address 0x5e49370 is 0 bytes inside a block of size 192 free'd
> ==3395==    at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==3395==    by 0x4A26EE: argv_array_clear (argv-array.c:73)
> ==3395==    by 0x54DFC4: child_process_clear (run-command.c:18)
> ==3395==    by 0x54EFA7: finish_command (run-command.c:539)
> ==3395==    by 0x550413: pp_collect_finished (run-command.c:1120)
> ==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
> ==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
> ==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
> ==3395==    by 0x405CBE: run_builtin (git.c:353)
> ==3395==    by 0x405EAA: handle_builtin (git.c:540)
> ==3395==    by 0x405FCC: run_argv (git.c:594)
> ==3395==    by 0x4061BF: main (git.c:701)
>
> I haven't thought about a solution, yet. Perhaps you have ideas.
>
> -- Hannes
>

What about unfolding finish_command like so:

diff --git a/run-command.c b/run-command.c
index 863dad5..659abd9 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1115,11 +1115,13 @@ static int pp_collect_finished(struct
parallel_processes *pp)
                if (i == pp->max_processes)
                        break;

-               code = finish_command(&pp->children[i].process);
+               code = wait_or_whine(pp->children[i].process.pid,
+                                    pp->children[i].process.argv[0], 0);

                code = pp->task_finished(code, &pp->children[i].process,
                                         &pp->children[i].err, pp->data,
                                         &pp->children[i].data);
+               child_process_clear(&pp->children[i].process);

                if (code)
                        result = code;

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 20:48               ` Johannes Sixt
  2016-02-29 20:59                 ` Stefan Beller
@ 2016-02-29 21:01                 ` Junio C Hamano
  2016-02-29 21:06                   ` Stefan Beller
  1 sibling, 1 reply; 59+ messages in thread
From: Junio C Hamano @ 2016-02-29 21:01 UTC (permalink / raw)
  To: Stefan Beller, Johannes Sixt; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder

Johannes Sixt <j6t@kdbg.org> writes:

> The culprit seems to be default_task_finished(), which accesses argv[]
> of the struct child_process after finish_command has released it,
> provided the child exited with an error, for example:

Thanks for a report.

> ==3395== Invalid read of size 8
> ==3395==    at 0x54F991: default_task_finished (run-command.c:932)

That one and also start_failure() do run after child_process_clear()
has cleaned things up, so they shouldn't be looking at argv[] (or
anything in that structure for that matter).



> ==3395==    by 0x49158F: update_clone_task_finished (submodule--helper.c:421)
> ==3395==    by 0x5504A2: pp_collect_finished (run-command.c:1122)
> ==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
> ==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
> ==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
> ==3395==    by 0x405CBE: run_builtin (git.c:353)
> ==3395==    by 0x405EAA: handle_builtin (git.c:540)
> ==3395==    by 0x405FCC: run_argv (git.c:594)
> ==3395==    by 0x4061BF: main (git.c:701)
> ==3395==  Address 0x5e49370 is 0 bytes inside a block of size 192 free'd
> ==3395==    at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==3395==    by 0x4A26EE: argv_array_clear (argv-array.c:73)
> ==3395==    by 0x54DFC4: child_process_clear (run-command.c:18)
> ==3395==    by 0x54EFA7: finish_command (run-command.c:539)
> ==3395==    by 0x550413: pp_collect_finished (run-command.c:1120)
> ==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
> ==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
> ==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
> ==3395==    by 0x405CBE: run_builtin (git.c:353)
> ==3395==    by 0x405EAA: handle_builtin (git.c:540)
> ==3395==    by 0x405FCC: run_argv (git.c:594)
> ==3395==    by 0x4061BF: main (git.c:701)
>
> I haven't thought about a solution, yet. Perhaps you have ideas.
>
> -- Hannes

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 21:01                 ` Junio C Hamano
@ 2016-02-29 21:06                   ` Stefan Beller
  2016-02-29 21:19                     ` Junio C Hamano
  0 siblings, 1 reply; 59+ messages in thread
From: Stefan Beller @ 2016-02-29 21:06 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Sixt, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine, Jonathan Nieder

On Mon, Feb 29, 2016 at 1:01 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Johannes Sixt <j6t@kdbg.org> writes:
>
>> The culprit seems to be default_task_finished(), which accesses argv[]
>> of the struct child_process after finish_command has released it,
>> provided the child exited with an error, for example:
>
> Thanks for a report.
>
>> ==3395== Invalid read of size 8
>> ==3395==    at 0x54F991: default_task_finished (run-command.c:932)
>
> That one and also start_failure() do run after child_process_clear()
> has cleaned things up, so they shouldn't be looking at argv[] (or
> anything in that structure for that matter).

I am undecided if easy access to the child process struct
is a benefit or not for the callback. It makes error reporting
easy, but maybe hacky as you poke around with the argv.

Maybe we want to remove the struct child_process from the
function signature of the callbacks and callbacks need to rely on
the data provided solely thru the pointer as passed around for
callback purposes, which the user is free to use for any kind
of data.

As a rather quickfix for 2.8 (and 2.7) we could however just
breakup the finish_command function and call child_process_clear
after the callbacks have run.

>
>
>
>> ==3395==    by 0x49158F: update_clone_task_finished (submodule--helper.c:421)
>> ==3395==    by 0x5504A2: pp_collect_finished (run-command.c:1122)
>> ==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
>> ==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
>> ==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
>> ==3395==    by 0x405CBE: run_builtin (git.c:353)
>> ==3395==    by 0x405EAA: handle_builtin (git.c:540)
>> ==3395==    by 0x405FCC: run_argv (git.c:594)
>> ==3395==    by 0x4061BF: main (git.c:701)
>> ==3395==  Address 0x5e49370 is 0 bytes inside a block of size 192 free'd
>> ==3395==    at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
>> ==3395==    by 0x4A26EE: argv_array_clear (argv-array.c:73)
>> ==3395==    by 0x54DFC4: child_process_clear (run-command.c:18)
>> ==3395==    by 0x54EFA7: finish_command (run-command.c:539)
>> ==3395==    by 0x550413: pp_collect_finished (run-command.c:1120)
>> ==3395==    by 0x5507C7: run_processes_parallel (run-command.c:1194)
>> ==3395==    by 0x4918EB: update_clone (submodule--helper.c:483)
>> ==3395==    by 0x4919D8: cmd_submodule__helper (submodule--helper.c:527)
>> ==3395==    by 0x405CBE: run_builtin (git.c:353)
>> ==3395==    by 0x405EAA: handle_builtin (git.c:540)
>> ==3395==    by 0x405FCC: run_argv (git.c:594)
>> ==3395==    by 0x4061BF: main (git.c:701)
>>
>> I haven't thought about a solution, yet. Perhaps you have ideas.
>>
>> -- Hannes

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 21:06                   ` Stefan Beller
@ 2016-02-29 21:19                     ` Junio C Hamano
  2016-02-29 21:22                       ` Stefan Beller
  2016-02-29 21:28                       ` Johannes Sixt
  0 siblings, 2 replies; 59+ messages in thread
From: Junio C Hamano @ 2016-02-29 21:19 UTC (permalink / raw)
  To: Stefan Beller
  Cc: Johannes Sixt, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine, Jonathan Nieder

Stefan Beller <sbeller@google.com> writes:

> Maybe we want to remove the struct child_process from the
> function signature of the callbacks and callbacks need to rely on
> the data provided solely thru the pointer as passed around for
> callback purposes, which the user is free to use for any kind
> of data.

I think that is the most sensible.

> As a rather quickfix for 2.8 (and 2.7) we could however just
> breakup the finish_command function and call child_process_clear
> after the callbacks have run.

That would not fix the case where run_command() fails, clears child
and then start failure callback, no?

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 21:19                     ` Junio C Hamano
@ 2016-02-29 21:22                       ` Stefan Beller
  2016-02-29 21:28                       ` Johannes Sixt
  1 sibling, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-29 21:22 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Sixt, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine, Jonathan Nieder

On Mon, Feb 29, 2016 at 1:19 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> Maybe we want to remove the struct child_process from the
>> function signature of the callbacks and callbacks need to rely on
>> the data provided solely thru the pointer as passed around for
>> callback purposes, which the user is free to use for any kind
>> of data.
>
> I think that is the most sensible.

Ok I'll send the diff above as a patch.
>
>> As a rather quickfix for 2.8 (and 2.7) we could however just
>> breakup the finish_command function and call child_process_clear
>> after the callbacks have run.
>
> That would not fix the case where run_command() fails, clears child
> and then start failure callback, no?

For that I was about to propose (broken whitespace below):

commit a0dcfbf86b6b720529958a4043d3679ed6f340d0
Author: Stefan Beller <sbeller@google.com>
Date:   Mon Feb 29 13:20:38 2016 -0800

    run-command: factor cleanup out of start_command

    The default callback of the parallel processing infrastructure assumes
    start_command will not clear the child process upon failing to start a
    child process. However having access to the child's argument vector
    enables easy error reporting, so move cleaning the child into a wrapper
    for general use and the parallel processing infrastructure needs to take
    care of cleaning up the child itself

    Signed-off-by: Stefan Beller <sbeller@google.com>

diff --git a/run-command.c b/run-command.c
index 863dad5..b1d97d0 100644
--- a/run-command.c
+++ b/run-command.c
@@ -265,7 +265,7 @@ static int wait_or_whine(pid_t pid, const char
*argv0, int in_signal)
         return code;
 }

-int start_command(struct child_process *cmd)
+static int start_command_uncleaned(struct child_process *cmd)
 {
         int need_in, need_out, need_err;
         int fdin[2], fdout[2], fderr[2];
@@ -326,7 +326,6 @@ int start_command(struct child_process *cmd)
 fail_pipe:
                         error("cannot create %s pipe for %s: %s",
                                 str, cmd->argv[0], strerror(failed_errno));
-                        child_process_clear(cmd);
                         errno = failed_errno;
                         return -1;
                 }
@@ -510,7 +509,7 @@ fail_pipe:
                         close_pair(fderr);
                 else if (cmd->err)
                         close(cmd->err);
-                child_process_clear(cmd);
+
                 errno = failed_errno;
                 return -1;
         }
@@ -533,6 +532,14 @@ fail_pipe:
         return 0;
 }

+int start_command(struct child_process *cmd)
+{
+        int code = start_command_uncleaned(cmd);
+        if (code == -1)
+                child_process_clear(cmd);
+        return code;
+}
+
 int finish_command(struct child_process *cmd)
 {
         int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
@@ -1047,11 +1054,12 @@ static int pp_start_one(struct parallel_processes *pp)
         pp->children[i].process.stdout_to_stderr = 1;
         pp->children[i].process.no_stdin = 1;

-        if (start_command(&pp->children[i].process)) {
+        if (start_command_uncleaned(&pp->children[i].process)) {
                 code = pp->start_failure(&pp->children[i].process,
                                          &pp->children[i].err,
                                          pp->data,
                                          &pp->children[i].data);
+                child_process_clear(&pp->children[i].process);
                 strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
                 strbuf_reset(&pp->children[i].err);
                 if (code)

^ permalink raw reply related	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 21:19                     ` Junio C Hamano
  2016-02-29 21:22                       ` Stefan Beller
@ 2016-02-29 21:28                       ` Johannes Sixt
  2016-02-29 21:51                         ` Junio C Hamano
  1 sibling, 1 reply; 59+ messages in thread
From: Johannes Sixt @ 2016-02-29 21:28 UTC (permalink / raw)
  To: Junio C Hamano, Stefan Beller
  Cc: git@vger.kernel.org, Jens Lehmann, Jeff King, Eric Sunshine,
	Jonathan Nieder

Am 29.02.2016 um 22:19 schrieb Junio C Hamano:
> Stefan Beller <sbeller@google.com> writes:
>
>> Maybe we want to remove the struct child_process from the
>> function signature of the callbacks and callbacks need to rely on
>> the data provided solely thru the pointer as passed around for
>> callback purposes, which the user is free to use for any kind
>> of data.
>
> I think that is the most sensible.

I also think that is the better approach. Dumping out the argv array is 
not the best end-user experience. It is just a debugging aid, and for 
that we have (or should extend if necessary) GIT_TRACE infrastructure. 
Moreover, a command that failed should have printed error messages, and 
it is not necessary to follow it up with another "A child process exited 
with code N" message.

-- Hannes

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 21:28                       ` Johannes Sixt
@ 2016-02-29 21:51                         ` Junio C Hamano
  2016-02-29 21:55                           ` Stefan Beller
  0 siblings, 1 reply; 59+ messages in thread
From: Junio C Hamano @ 2016-02-29 21:51 UTC (permalink / raw)
  To: Johannes Sixt
  Cc: Stefan Beller, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine, Jonathan Nieder

Johannes Sixt <j6t@kdbg.org> writes:

> Am 29.02.2016 um 22:19 schrieb Junio C Hamano:
>> Stefan Beller <sbeller@google.com> writes:
>>
>>> Maybe we want to remove the struct child_process from the
>>> function signature of the callbacks and callbacks need to rely on
>>> the data provided solely thru the pointer as passed around for
>>> callback purposes, which the user is free to use for any kind
>>> of data.
>>
>> I think that is the most sensible.
>
> I also think that is the better approach. Dumping out the argv array
> is not the best end-user experience. It is just a debugging aid, and
> for that we have (or should extend if necessary) GIT_TRACE
> infrastructure. Moreover, a command that failed should have printed
> error messages, and it is not necessary to follow it up with another
> "A child process exited with code N" message.

Exactly.  Stefan, please do not go in the route of butchering the
start_command(), finish_command(), etc. API set with the "uncleaned"
variants.

Thanks.

^ permalink raw reply	[flat|nested] 59+ messages in thread

* Re: [PATCHv19 00/11] Expose submodule parallelism to the user
  2016-02-29 21:51                         ` Junio C Hamano
@ 2016-02-29 21:55                           ` Stefan Beller
  0 siblings, 0 replies; 59+ messages in thread
From: Stefan Beller @ 2016-02-29 21:55 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Johannes Sixt, git@vger.kernel.org, Jens Lehmann, Jeff King,
	Eric Sunshine, Jonathan Nieder

On Mon, Feb 29, 2016 at 1:51 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Johannes Sixt <j6t@kdbg.org> writes:
>
>> Am 29.02.2016 um 22:19 schrieb Junio C Hamano:
>>> Stefan Beller <sbeller@google.com> writes:
>>>
>>>> Maybe we want to remove the struct child_process from the
>>>> function signature of the callbacks and callbacks need to rely on
>>>> the data provided solely thru the pointer as passed around for
>>>> callback purposes, which the user is free to use for any kind
>>>> of data.
>>>
>>> I think that is the most sensible.
>>
>> I also think that is the better approach. Dumping out the argv array
>> is not the best end-user experience. It is just a debugging aid, and
>> for that we have (or should extend if necessary) GIT_TRACE
>> infrastructure. Moreover, a command that failed should have printed
>> error messages, and it is not necessary to follow it up with another
>> "A child process exited with code N" message.
>
> Exactly.  Stefan, please do not go in the route of butchering the
> start_command(), finish_command(), etc. API set with the "uncleaned"
> variants.
>
> Thanks.

After rereading your emails just after I had the patches ready to send,
I realized it's a bad way to go. Thanks for confirming that. :)

^ permalink raw reply	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2016-02-29 21:55 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-25  3:06 [PATCHv17 00/11] Expose submodule parallelism to the user Stefan Beller
2016-02-25  3:06 ` [PATCHv17 01/11] submodule-config: keep update strategy around Stefan Beller
2016-02-25 18:06   ` Junio C Hamano
2016-02-25 18:21     ` Stefan Beller
2016-02-25  3:06 ` [PATCHv17 02/11] submodule-config: drop check against NULL Stefan Beller
2016-02-25  3:06 ` [PATCHv17 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
2016-02-25  3:06 ` [PATCHv17 04/11] submodule update: direct error message to stderr Stefan Beller
2016-02-25  3:06 ` [PATCHv17 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
2016-02-25 18:16   ` Junio C Hamano
2016-02-25 20:35     ` Stefan Beller
2016-02-25  3:06 ` [PATCHv17 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
2016-02-25  3:06 ` [PATCHv17 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
2016-02-25  3:06 ` [PATCHv17 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
2016-02-25  3:06 ` [PATCHv17 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
2016-02-25  3:06 ` [PATCHv17 10/11] submodule update: expose parallelism to the user Stefan Beller
2016-02-25  3:06 ` [PATCHv17 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
2016-02-25 22:26 ` [PATCHv17 00/11] Expose submodule parallelism to the user Junio C Hamano
2016-02-25 23:08   ` [PATCHv18 00/11] Expose Stefan Beller
2016-02-25 23:08     ` [PATCHv18 01/11] submodule-config: keep update strategy around Stefan Beller
2016-02-25 23:08     ` [PATCHv18 02/11] submodule-config: drop check against NULL Stefan Beller
2016-02-25 23:08     ` [PATCHv18 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
2016-02-25 23:08     ` [PATCHv18 04/11] submodule update: direct error message to stderr Stefan Beller
2016-02-25 23:08     ` [PATCHv18 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
2016-02-25 23:08     ` [PATCHv18 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
2016-02-25 23:08     ` [PATCHv18 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
2016-02-25 23:08     ` [PATCHv18 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
2016-02-25 23:08     ` [PATCHv18 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
2016-02-25 23:08     ` [PATCHv18 10/11] submodule update: expose parallelism to the user Stefan Beller
2016-02-25 23:08     ` [PATCHv18 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
2016-02-25 23:11     ` [PATCHv18 00/11] Expose Stefan Beller
2016-02-25 23:19     ` Jonathan Nieder
2016-02-25 23:25       ` Stefan Beller
2016-02-25 23:35         ` Jonathan Nieder
2016-02-25 23:39           ` Junio C Hamano
2016-02-25 23:48             ` [PATCHv19 00/11] Expose submodule parallelism to the user Stefan Beller
2016-02-25 23:48               ` [PATCHv19 01/11] submodule-config: keep update strategy around Stefan Beller
2016-02-25 23:48               ` [PATCHv19 02/11] submodule-config: drop check against NULL Stefan Beller
2016-02-25 23:48               ` [PATCHv19 03/11] fetching submodules: respect `submodule.fetchJobs` config option Stefan Beller
2016-02-25 23:48               ` [PATCHv19 04/11] submodule update: direct error message to stderr Stefan Beller
2016-02-25 23:48               ` [PATCHv19 05/11] run_processes_parallel: treat output of children as byte array Stefan Beller
2016-02-25 23:48               ` [PATCHv19 06/11] run-command: expose default_{start_failure, task_finished} Stefan Beller
2016-02-25 23:48               ` [PATCHv19 07/11] run_processes_parallel: rename parameters for the callbacks Stefan Beller
2016-02-25 23:48               ` [PATCHv19 08/11] run_processes_parallel: correctly terminate callbacks with an LF Stefan Beller
2016-02-25 23:48               ` [PATCHv19 09/11] git submodule update: have a dedicated helper for cloning Stefan Beller
2016-02-27  8:40                 ` Duy Nguyen
2016-02-29 19:03                   ` Stefan Beller
2016-02-25 23:48               ` [PATCHv19 10/11] submodule update: expose parallelism to the user Stefan Beller
2016-02-25 23:48               ` [PATCHv19 11/11] clone: allow an explicit argument for parallel submodule clones Stefan Beller
2016-02-25 23:50               ` [PATCHv19 00/11] Expose submodule parallelism to the user Jonathan Nieder
2016-02-29 20:48               ` Johannes Sixt
2016-02-29 20:59                 ` Stefan Beller
2016-02-29 21:01                 ` Junio C Hamano
2016-02-29 21:06                   ` Stefan Beller
2016-02-29 21:19                     ` Junio C Hamano
2016-02-29 21:22                       ` Stefan Beller
2016-02-29 21:28                       ` Johannes Sixt
2016-02-29 21:51                         ` Junio C Hamano
2016-02-29 21:55                           ` Stefan Beller
2016-02-25 23:25     ` [PATCHv18 00/11] Expose Jonathan Nieder

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).