From c1200a855957a4ba4de209ca8293282535046923 Mon Sep 17 00:00:00 2001 From: "szager@google.com" Date: Thu, 25 Oct 2012 19:26:31 +0000 Subject: [PATCH] Keep the parallel execution pipes full as much as possible. Rearrange some of the pipe redirections to avoid crashing on Windows. TBR=cmp@chromium.org Review URL: https://codereview.chromium.org/11260036 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@164140 0039d316-1c4b-4281-b951-d872f2087c98 --- crup-runner.sh | 30 ++++++++++++++++++++ git-crup | 75 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 20 deletions(-) create mode 100755 crup-runner.sh diff --git a/crup-runner.sh b/crup-runner.sh new file mode 100755 index 000000000..9b17413dc --- /dev/null +++ b/crup-runner.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ -z "$*" ]; then + exit 0 +fi +set -o pipefail +dir="$1" +solution="${1%%/*}" +cd "$solution" +if [ "$solution" = "$1" ]; then + shift + $@ | sed "s/^/[$solution] /g" 1>&2 + if [ $? -ne 0 ]; then + exit $? + fi + "$GIT_EXE" submodule --quiet sync + "$GIT_EXE" ls-files -s | grep ^160000 | awk '{print $4}' | + sed "s/^/$solution\//g" + status=$? +else + submodule="${1#*/}" + echo "[$solution] updating $submodule ..." + "$GIT_EXE" submodule update --quiet --init "$submodule" | + ( grep -v '^Skipping submodule' || true ) | sed "s|^|[$1] |g" + status=$? + if [ "$status" -ne "0" ]; then + echo "[$solution] FAILED to update $submodule" + fi +fi +exit $status diff --git a/git-crup b/git-crup index f57d3a7b5..be56d30e3 100755 --- a/git-crup +++ b/git-crup @@ -7,11 +7,22 @@ # submodule-based checkout. Fetches latest commits for top-level solutions; # updates submodules; and runs post-sync hooks. -j=10 +export GIT_MERGE_AUTOEDIT=0 + ECHO= pull=pull pull_args= hooks=yes +j=10 +crup_runner="crup-runner.sh" + +kernel_name=$(uname -s) +if [ "${kernel_name:0:5}" = "MINGW" -o "${kernel_name:0:6}" = "CYGWIN" ]; then + GIT_EXE=git.exe +else + GIT_EXE=git +fi +export GIT_EXE if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then max_lines="--max-lines=1" @@ -19,24 +30,31 @@ else max_lines="-L 1" fi +if ( echo test | xargs -I bar true 2>/dev/null ); then + replace_arg="-I replace_arg" +else + replace_arg="-ireplace_arg" +fi + usage() { - cat <&2 + cat <] EOF } -parallel_update() { - ( echo Entering "$1" - cd "$1" - $ECHO git $pull $pull_args origin - $ECHO git submodule sync - if test "$xargs_parallel" = "yes"; then - git ls-files -s | grep ^160000 | awk '{print $4}' | - xargs $max_lines -P "$j" $ECHO git submodule update --init - else - $ECHO git submodule update --init - fi ) +serial_update() { + ( cd "$1" + $GIT_EXE $pull $pull_args -q origin | sed "s/^/[$1] /g" + if [ $? -ne 0 ]; then + return $? + fi + $GIT_EXE submodule --quiet sync + $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | + while read submod; do + $GIT_EXE submodule update --init "$submod" | sed "s|^|[$1/$submod] |g" + done + ) } while test $# -ne 0; do @@ -68,7 +86,7 @@ while test $# -ne 0; do --fetch) pull=fetch ;; - --no-hooks) + --no-hooks|--nohooks) hooks=no ;; *) @@ -99,10 +117,27 @@ else xargs_parallel=no fi -ls -d */.git | -while read gitdir; do - parallel_update `dirname $gitdir` -done +set -o pipefail + +if test "$xargs_parallel" = "yes"; then + ( ls -d */.git | sed 's/\/\.git$//' | + xargs $max_lines $replace_arg -P "$j" \ + "$crup_runner" replace_arg $GIT_EXE $pull $pull_args -q origin | + xargs $max_lines -P "$j" "$crup_runner" ) +else + ls -d */.git | + while read gitdir; do + serial_update "${gitdir%%/.git}" + done +fi + +status=$? + +if [ "$hooks" = "yes" -a "$status" -eq 0 ]; then + gclient_spec="solutions=[{'name':'src','url':None,'deps_file':'.DEPS.git'}]" + gclient runhooks --spec="$gclient_spec" + status=$? +fi -gclient_spec="solutions=[{'name':'src','url':None,'deps_file':'.DEPS.git'}]" -test "$hooks" = "yes" && gclient runhooks --spec="$gclient_spec" +echo +exit $status