Commit 8cfdb58a authored by szager@chromium.org's avatar szager@chromium.org

Fix handling of optional argument to -j.

Review URL: https://chromiumcodereview.appspot.com/10830108

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@149649 0039d316-1c4b-4281-b951-d872f2087c98
parent 136ace1d
#!/bin/sh #!/bin/bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -13,6 +13,12 @@ pull=pull ...@@ -13,6 +13,12 @@ pull=pull
pull_args= pull_args=
hooks=yes hooks=yes
if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then
max_lines="--max-lines=1"
else
max_lines="-L 1"
fi
usage() { usage() {
cat <<EOF 1>&2 cat <<EOF 1>&2
Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]] Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]]
...@@ -25,30 +31,32 @@ parallel_update() { ...@@ -25,30 +31,32 @@ parallel_update() {
cd "$1" cd "$1"
$ECHO git $pull $pull_args origin $ECHO git $pull $pull_args origin
$ECHO git submodule sync $ECHO git submodule sync
if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then if test "$xargs_parallel" = "yes"; then
max_lines="--max-lines=1"
else
max_lines="-L 1"
fi
if ( echo test | xargs -P "$j" true 2>/dev/null )
then
git ls-files -s | grep ^160000 | awk '{print $4}' | git ls-files -s | grep ^160000 | awk '{print $4}' |
xargs $max_lines -P "$j" $ECHO git submodule update --init xargs $max_lines -P "$j" $ECHO git submodule update --init
else else
echo "Warn: parallel execution is not supported on this platform."
$ECHO git submodule update --init $ECHO git submodule update --init
fi ) fi )
} }
while test $# -ne 0; do while test $# -ne 0; do
case "$1" in case "$1" in
-j[0-9]*)
j=$(echo "$1" | cut -c3-)
;;
--jobs=[0-9]*)
j=$(echo "$1" | cut -c8-)
;;
-j|--jobs) -j|--jobs)
if test -n "$2"; then case "$2" in
j="$2" ''|-*)
shift j=0
else ;;
j=0 *)
fi j="$2"
shift
;;
esac
;; ;;
-n|--dry-run) -n|--dry-run)
ECHO=echo ECHO=echo
...@@ -82,6 +90,15 @@ if test "$PWD" = "/"; then ...@@ -82,6 +90,15 @@ if test "$PWD" = "/"; then
exit 1 exit 1
fi fi
if ( echo test test | xargs -P 2 true 2>/dev/null ); then
xargs_parallel=yes
else
if test "$j" != "1"; then
echo "Warning: parallel execution is not supported on this platform." 1>&2
fi
xargs_parallel=no
fi
ls -d */.git | ls -d */.git |
while read gitdir; do while read gitdir; do
parallel_update `dirname $gitdir` parallel_update `dirname $gitdir`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment