From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Beller Subject: [PATCH 7/8] submodule update: expose parallelism to the user Date: Tue, 2 Feb 2016 09:51:36 -0800 Message-ID: <1454435497-26429-8-git-send-email-sbeller@google.com> References: <1454435497-26429-1-git-send-email-sbeller@google.com> Cc: Jens.Lehmann@web.de, Stefan Beller , Junio C Hamano To: git@vger.kernel.org, jrnieder@gmail.com X-From: git-owner@vger.kernel.org Tue Feb 02 18:52:17 2016 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aQf7f-0002MB-2C for gcvg-git-2@plane.gmane.org; Tue, 02 Feb 2016 18:52:15 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933197AbcBBRv6 (ORCPT ); Tue, 2 Feb 2016 12:51:58 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:32981 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933143AbcBBRvz (ORCPT ); Tue, 2 Feb 2016 12:51:55 -0500 Received: by mail-pf0-f171.google.com with SMTP id w123so16153075pfb.0 for ; Tue, 02 Feb 2016 09:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6SxtnqSMZEOLtA9gjQJQUrzMCQ5A32eozshVUVRYkVo=; b=HUKSbYy0RWm2G2QXJxNjYccVvBJMFK+BYzCZaqJsp1udgrmlqQNpAlAtZOJBN0Z/yt PjGomgELBtnjHwOccfpqE516w5J4iypZsGMq+cIK1t8UBQxH1/cv1dlZZiRAXMfK4UnO bLlFqt4VollZIsdkZzZHDulcK+O4wKSwBLIEpl6atHC2kiyxM0MPmG8bpcXxYDHgqIcp gAI7JR6o24kDiY3tNBIdH3aJ/wO1N1C6awZyE2RGYQxJrKuicK0qIWCLoqoQyPQLV0Xc OgTsxPqA/uDwO2esW839DXIVM+8CDsJ4WUoR5VLFz7B/I5K97PAPB4d57vACkhdoicwg 9i5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6SxtnqSMZEOLtA9gjQJQUrzMCQ5A32eozshVUVRYkVo=; b=Yi6wSrOpEJTAJAAxd8/Ea0Dw2mr5Dsu7YethOAc59KQ2oSVFV7F5ge9i1UcfJtF5Z5 YtPmn+cP39ahziUUB3WNrPOEJWbt/8uE6tl5ThNWgn2pgeGipt4nf7xY1Q6o4VYo3/NV 2lybJw8eK+XwpjOhsm0Iv/mIH3MpKCNcQdBJooY34DJPe2rybCVbikeAkTIwmgRUz0mP kmTH/UoOPvwEvKYtqQmFNtol3/yLI0mLNnXd0v1AprbUNKlWZoyWrm2z4WkK8qGvm8D9 ZzGPAgUkHhBfRQD/26hbHyCCtzS51G3FtwjqanlJzmw1r8wNzBiyt/z2A+NZF04JmQAr fBsw== X-Gm-Message-State: AG10YOS8AsPrEwIVLdmltW3ZGS0j7cdrRdoMsXkp1g2FcMBwQaUEEmo1f7dX/oMiklMuVZYz X-Received: by 10.98.15.82 with SMTP id x79mr49657352pfi.52.1454435515046; Tue, 02 Feb 2016 09:51:55 -0800 (PST) Received: from localhost ([2620:0:1000:5b00:11e1:ff63:6d72:465a]) by smtp.gmail.com with ESMTPSA id xr8sm4079809pab.26.2016.02.02.09.51.54 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 02 Feb 2016 09:51:54 -0800 (PST) X-Mailer: git-send-email 2.7.0.rc0.42.ge5f5e2d In-Reply-To: <1454435497-26429-1-git-send-email-sbeller@google.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- Documentation/git-submodule.txt | 7 ++++++- builtin/submodule--helper.c | 18 ++++++++++++++---- git-submodule.sh | 9 +++++++++ t/t7406-submodule-update.sh | 12 ++++++++++++ 4 files changed, 41 insertions(+), 5 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] [--] ... 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase|--merge] [--reference ] - [--depth ] [--recursive] [--] [...] + [--depth ] [--recursive] [--jobs ] [--] [...] 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) ] [commit] [--] [...] 'git submodule' [--quiet] foreach [--recursive] @@ -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 :: +--jobs :: + This option is only valid for the update command. + Clone new submodules in parallel with as many jobs. + Defaults to the `submodule.fetchJobs` option. ...:: Paths to submodule(s). When specified this will restrict the command diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9441f20..8002187 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -426,6 +426,7 @@ static int update_clone_task_finished(int result, static int update_clone(int argc, const char **argv, const char *prefix) { + int max_jobs = -1; struct string_list_item *item; struct submodule_update_clone pp = SUBMODULE_UPDATE_CLONE_INIT; @@ -446,6 +447,8 @@ static int update_clone(int argc, const char **argv, const char *prefix) OPT_STRING(0, "depth", &pp.depth, "", N_("Create a shallow clone truncated to the " "specified number of revisions")), + OPT_INTEGER('j', "jobs", &max_jobs, + N_("parallel jobs")), OPT__QUIET(&pp.quiet, N_("do't print cloning progress")), OPT_END() }; @@ -467,10 +470,17 @@ static int update_clone(int argc, const char **argv, const char *prefix) gitmodules_config(); /* Overlay the parsed .gitmodules file with .git/config */ git_config(git_submodule_config, NULL); - run_processes_parallel(1, update_clone_get_next_task, - update_clone_start_failure, - update_clone_task_finished, - &pp); + + if (max_jobs < 0) + max_jobs = config_parallel_submodules(); + if (max_jobs < 0) + max_jobs = 1; + + run_processes_parallel(max_jobs, + update_clone_get_next_task, + update_clone_start_failure, + update_clone_task_finished, + &pp); if (pp.print_unmatched) { printf("#unmatched\n"); diff --git a/git-submodule.sh b/git-submodule.sh index 9f554fb..10c5af9 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 @@ -670,6 +678,7 @@ cmd_update() ${update:+--update "$update"} \ ${reference:+--reference "$reference"} \ ${depth:+--depth "$depth"} \ + ${jobs:+$jobs} \ "$@" | { err= while read mode sha1 stage just_cloned sm_path 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.42.ge5f5e2d