submodule update: expose parallelism to the user
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									cdc04b65b4
								
							
						
					
					
						commit
						2335b870fa
					
				|  | @ -16,7 +16,7 @@ SYNOPSIS | ||||||
| 'git submodule' [--quiet] deinit [-f|--force] [--] <path>... | 'git submodule' [--quiet] deinit [-f|--force] [--] <path>... | ||||||
| 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] | 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] | ||||||
| 	      [-f|--force] [--rebase|--merge] [--reference <repository>] | 	      [-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>] | 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>] | ||||||
| 	      [commit] [--] [<path>...] | 	      [commit] [--] [<path>...] | ||||||
| 'git submodule' [--quiet] foreach [--recursive] <command> | '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. | 	clone with a history truncated to the specified number of revisions. | ||||||
| 	See linkgit:git-clone[1] | 	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>...:: | <path>...:: | ||||||
| 	Paths to submodule(s). When specified this will restrict the command | 	Paths to submodule(s). When specified this will restrict the command | ||||||
|  |  | ||||||
|  | @ -430,6 +430,7 @@ static int update_clone_task_finished(int result, | ||||||
| static int update_clone(int argc, const char **argv, const char *prefix) | static int update_clone(int argc, const char **argv, const char *prefix) | ||||||
| { | { | ||||||
| 	const char *update = NULL; | 	const char *update = NULL; | ||||||
|  | 	int max_jobs = -1; | ||||||
| 	struct string_list_item *item; | 	struct string_list_item *item; | ||||||
| 	struct pathspec pathspec; | 	struct pathspec pathspec; | ||||||
| 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; | 	struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; | ||||||
|  | @ -450,6 +451,8 @@ static int update_clone(int argc, const char **argv, const char *prefix) | ||||||
| 		OPT_STRING(0, "depth", &suc.depth, "<depth>", | 		OPT_STRING(0, "depth", &suc.depth, "<depth>", | ||||||
| 			   N_("Create a shallow clone truncated to the " | 			   N_("Create a shallow clone truncated to the " | ||||||
| 			      "specified number of revisions")), | 			      "specified number of revisions")), | ||||||
|  | 		OPT_INTEGER('j', "jobs", &max_jobs, | ||||||
|  | 			    N_("parallel jobs")), | ||||||
| 		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")), | 		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")), | ||||||
| 		OPT_END() | 		OPT_END() | ||||||
| 	}; | 	}; | ||||||
|  | @ -477,7 +480,10 @@ static int update_clone(int argc, const char **argv, const char *prefix) | ||||||
| 	gitmodules_config(); | 	gitmodules_config(); | ||||||
| 	git_config(submodule_config, NULL); | 	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_get_next_task, | ||||||
| 			       update_clone_start_failure, | 			       update_clone_start_failure, | ||||||
| 			       update_clone_task_finished, | 			       update_clone_task_finished, | ||||||
|  |  | ||||||
|  | @ -645,6 +645,14 @@ cmd_update() | ||||||
| 		--depth=*) | 		--depth=*) | ||||||
| 			depth=$1 | 			depth=$1 | ||||||
| 			;; | 			;; | ||||||
|  | 		-j|--jobs) | ||||||
|  | 			case "$2" in '') usage ;; esac | ||||||
|  | 			jobs="--jobs=$2" | ||||||
|  | 			shift | ||||||
|  | 			;; | ||||||
|  | 		--jobs=*) | ||||||
|  | 			jobs=$1 | ||||||
|  | 			;; | ||||||
| 		--) | 		--) | ||||||
| 			shift | 			shift | ||||||
| 			break | 			break | ||||||
|  | @ -671,6 +679,7 @@ cmd_update() | ||||||
| 		${update:+--update "$update"} \ | 		${update:+--update "$update"} \ | ||||||
| 		${reference:+--reference "$reference"} \ | 		${reference:+--reference "$reference"} \ | ||||||
| 		${depth:+--depth "$depth"} \ | 		${depth:+--depth "$depth"} \ | ||||||
|  | 		${jobs:+$jobs} \ | ||||||
| 		"$@" || echo "#unmatched" | 		"$@" || echo "#unmatched" | ||||||
| 	} | { | 	} | { | ||||||
| 	err= | 	err= | ||||||
|  |  | ||||||
|  | @ -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_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 | test_done | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Stefan Beller
						Stefan Beller