{"thread":{"id":"31981","subject":"[PATCH] Enable parallelism in git submodule update.","startedAt":"2012-10-30T18:03:33Z","lastAt":"2012-10-30T18:03:33Z","messageCount":1,"participants":["szager@google.com"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"202212","messageId":"50901675.WKMg80aNqNeozrMn%szager@google.com","threadId":"31981","inReplyTo":null,"subject":"[PATCH] Enable parallelism in git submodule update.","fromName":"","fromEmail":"szager@google.com","sentAt":"2012-10-30T18:03:33Z","receivedAt":"2012-10-30T18:03:33Z","isPatch":true,"sender":{"key":"szager@google.com","avatar":null},"body":"The --jobs parameter may be used to set the degree of per-submodule\nparallel execution.\n\nSigned-off-by: Stefan Zager <szager@google.com>\n---\n Documentation/git-submodule.txt |    8 ++++++-\n git-submodule.sh                |   40 ++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 46 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex b4683bb..cb23ba7 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -14,7 +14,8 @@ SYNOPSIS\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]\n-\t      [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n+\t      [--reference <repository>] [--merge] [--recursive]\n+\t      [-j|--jobs [jobs]] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n \t      [commit] [--] [<path>...]\n 'git submodule' [--quiet] foreach [--recursive] <command>\n@@ -146,6 +147,11 @@ If the submodule is not yet initialized, and you just want to use the\n setting as stored in .gitmodules, you can automatically initialize the\n submodule with the `--init` option.\n +\n+By default, each submodule is treated serially.  You may specify a degree of\n+parallel execution with the --jobs flag.  If a parameter is provided, it is\n+the maximum number of jobs to run in parallel; without a parameter, all jobs are\n+run in parallel.\n++\n If `--recursive` is specified, this command will recurse into the\n registered submodules, and update any nested submodules within.\n +\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ab6b110..60a5f96 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -8,7 +8,7 @@ dashless=$(basename \"$0\" | sed -e 's/-/ /')\n USAGE=\"[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]\n    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] init [--] [<path>...]\n-   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n+   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [-j|--jobs [jobs]] [--] [<path>...]\n    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]\n    or: $dashless [--quiet] foreach [--recursive] <command>\n    or: $dashless [--quiet] sync [--] [<path>...]\"\n@@ -500,6 +500,7 @@ cmd_update()\n {\n \t# parse $args after \"submodule ... update\".\n \torig_flags=\n+\tjobs=\"1\"\n \twhile test $# -ne 0\n \tdo\n \t\tcase \"$1\" in\n@@ -518,6 +519,20 @@ cmd_update()\n \t\t-r|--rebase)\n \t\t\tupdate=\"rebase\"\n \t\t\t;;\n+\t\t-j|--jobs)\n+\t\t\tcase \"$2\" in\n+\t\t\t''|-*)\n+\t\t\t\tjobs=\"0\"\n+\t\t\t\t;;\n+\t\t\t*)\n+\t\t\t\tjobs=\"$2\"\n+\t\t\t\tshift\n+\t\t\t\t;;\n+\t\t\tesac\n+\t\t\t# Don't preserve this arg.\n+\t\t\tshift\n+\t\t\tcontinue\n+\t\t\t;;\n \t\t--reference)\n \t\t\tcase \"$2\" in '') usage ;; esac\n \t\t\treference=\"--reference=$2\"\n@@ -551,11 +566,34 @@ cmd_update()\n \t\tshift\n \tdone\n \n+\t# Correctly handle the case where '-q' came before 'update' on the command line.\n+\tif test -n \"$GIT_QUIET\"\n+\tthen\n+\t\torig_flags=\"$orig_flags -q\"\n+\tfi\n+\n \tif test -n \"$init\"\n \tthen\n \t\tcmd_init \"--\" \"$@\" || return\n \tfi\n \n+\tif test \"$jobs\" != 1\n+\tthen\n+\t\tif ( echo test | xargs -P \"$jobs\" true 2>/dev/null )\n+\t\tthen\n+\t\t\tif ( echo test | xargs --max-lines=1 true 2>/dev/null ); then\n+\t\t\t\tmax_lines=\"--max-lines=1\"\n+\t\t\telse\n+\t\t\t\tmax_lines=\"-L 1\"\n+\t\t\tfi\n+\t\t\tmodule_list \"$@\" | awk '{print $4}' |\n+\t\t\txargs $max_lines -P \"$jobs\" git submodule update $orig_flags\n+\t\t\treturn\n+\t\telse\n+\t\t\techo \"Warn: parallel execution is not supported on this platform.\"\n+\t\tfi\n+\tfi\n+\n \tcloned_modules=\n \tmodule_list \"$@\" | {\n \terr=\n-- \n1.7.7.3\n"}]}