From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Beller Subject: [PATCHv14 6/7] submodule update: expose parallelism to the user Date: Fri, 19 Feb 2016 10:17:12 -0800 Message-ID: <1455905833-7449-7-git-send-email-sbeller@google.com> References: <1455905833-7449-1-git-send-email-sbeller@google.com> Cc: git@vger.kernel.org, jrnieder@gmail.com, Jens.Lehmann@web.de, peff@peff.net, sunshine@sunshineco.com, Stefan Beller To: gitster@pobox.com X-From: git-owner@vger.kernel.org Fri Feb 19 19:17:52 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 1aWpcf-00015c-Kc for gcvg-git-2@plane.gmane.org; Fri, 19 Feb 2016 19:17:45 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992814AbcBSSRf (ORCPT ); Fri, 19 Feb 2016 13:17:35 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:33958 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2992705AbcBSSR1 (ORCPT ); Fri, 19 Feb 2016 13:17:27 -0500 Received: by mail-pf0-f173.google.com with SMTP id x65so55068779pfb.1 for ; Fri, 19 Feb 2016 10:17:26 -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=TmOzS19nB3HdKSibMnzI0+sSQ8lYW3vKf/dJm3O7h0A=; b=QbGn801F4r0cOnuSJNsIAinR832bQu45r+uiVLpHpXnx9wxSuR0RsgmEETEur407uA PY8hpEQr8O55OjRb+rwasCYwrcGXBgtqselJ6esZNJs4cEKT2nLps1yOUPhpiVE2c+1A 8ImJbHQQFRtXe5lnXcp9VGvGAn5eyMCJj5heQp6UAK6yY3PzuSCk7Oh9FCd8V6f+YW1R QBO3quaqtET8MmCf1whsI7rR+b+HmD54mM6JapXxOGQ0ykOHfFVf38EagR6/HWtRS34G JE5hJ7P99u68+l4OMm6vbxB9y/PHqdz8xSiL8LyDhnbSRvRT6POjnCqhRszBYepyGSp6 Lh1A== 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=TmOzS19nB3HdKSibMnzI0+sSQ8lYW3vKf/dJm3O7h0A=; b=k3y6bQ+i+tDVSHJiMVOyWgXO8BmQGehbZNb8OJlXhBySP7g5X5b+qydynqMsMPUMAr GleAK2L5apFzkxmYVsOb71gHU7nYbz7Hi30WX95DRMOLVJoYSbYaSO7zE34+zJCGVO+7 AXNph8ErRMIKq1uzAJWGgCeqoy2PApBfgL7/wDtVa19APCA1uyApNtc7M5DcYiDwuK7z m9mXMmuzEmO54OKGWSYzpgnXXj4MkjyA/YojT8xrnKPSGZ5PY+np4L+vsAnhRjrhEoaV m6jeMMZexA9waJSfBJ9yX64Z2kso3qLnVmqnMch41qqisISXQMWv5JNVGINaWAuNM0j4 BiIg== X-Gm-Message-State: AG10YOTUnqDFaEiJf54PaH3Bj6EGAPP6lG/vRycARu2PVDhJrGpUXvGRVsCk+/HWuQQbNR2N X-Received: by 10.98.80.150 with SMTP id g22mr20102901pfj.132.1455905846275; Fri, 19 Feb 2016 10:17:26 -0800 (PST) Received: from localhost ([2620:0:1000:5b00:d444:f36c:1851:bb54]) by smtp.gmail.com with ESMTPSA id tb10sm19462911pab.22.2016.02.19.10.17.25 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 19 Feb 2016 10:17:25 -0800 (PST) X-Mailer: git-send-email 2.7.0.rc0.34.ga06e0b3.dirty In-Reply-To: <1455905833-7449-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 | 16 ++++++++++++---- git-submodule.sh | 9 +++++++++ t/t7406-submodule-update.sh | 12 ++++++++++++ 4 files changed, 39 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 c356aaf..c435c53 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -422,6 +422,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 submodule_update_clone pp = SUBMODULE_UPDATE_CLONE_INIT; @@ -442,6 +443,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,15 @@ static int update_clone(int argc, const char **argv, const char *prefix) gitmodules_config(); /* Overlay the parsed .gitmodules file with .git/config */ git_config(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 = parallel_submodules(); + + 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.34.ga06e0b3.dirty