| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/bash |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # A convenience script to largely replicate the behavior of `gclient sync` in a | 6 # A convenience script to largely replicate the behavior of `gclient sync` in a |
| 7 # submodule-based checkout. Fetches latest commits for top-level solutions; | 7 # submodule-based checkout. Fetches latest commits for top-level solutions; |
| 8 # updates submodules; and runs post-sync hooks. | 8 # updates submodules; and runs post-sync hooks. |
| 9 | 9 |
| 10 j=10 | 10 j=10 |
| 11 ECHO= | 11 ECHO= |
| 12 pull=pull | 12 pull=pull |
| 13 pull_args= | 13 pull_args= |
| 14 hooks=yes | 14 hooks=yes |
| 15 | 15 |
| 16 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then |
| 17 max_lines="--max-lines=1" |
| 18 else |
| 19 max_lines="-L 1" |
| 20 fi |
| 21 |
| 16 usage() { | 22 usage() { |
| 17 cat <<EOF 1>&2 | 23 cat <<EOF 1>&2 |
| 18 Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]] | 24 Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]] |
| 19 [--no-hooks] [<args to git-pull or git-fetch>] | 25 [--no-hooks] [<args to git-pull or git-fetch>] |
| 20 EOF | 26 EOF |
| 21 } | 27 } |
| 22 | 28 |
| 23 parallel_update() { | 29 parallel_update() { |
| 24 ( echo Entering "$1" | 30 ( echo Entering "$1" |
| 25 cd "$1" | 31 cd "$1" |
| 26 $ECHO git $pull $pull_args origin | 32 $ECHO git $pull $pull_args origin |
| 27 $ECHO git submodule sync | 33 $ECHO git submodule sync |
| 28 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then | 34 if test "$xargs_parallel" = "yes"; then |
| 29 max_lines="--max-lines=1" | |
| 30 else | |
| 31 max_lines="-L 1" | |
| 32 fi | |
| 33 if ( echo test | xargs -P "$j" true 2>/dev/null ) | |
| 34 then | |
| 35 git ls-files -s | grep ^160000 | awk '{print $4}' | | 35 git ls-files -s | grep ^160000 | awk '{print $4}' | |
| 36 xargs $max_lines -P "$j" $ECHO git submodule update --init | 36 xargs $max_lines -P "$j" $ECHO git submodule update --init |
| 37 else | 37 else |
| 38 echo "Warn: parallel execution is not supported on this platform." | |
| 39 $ECHO git submodule update --init | 38 $ECHO git submodule update --init |
| 40 fi ) | 39 fi ) |
| 41 } | 40 } |
| 42 | 41 |
| 43 while test $# -ne 0; do | 42 while test $# -ne 0; do |
| 44 case "$1" in | 43 case "$1" in |
| 44 -j[0-9]*) |
| 45 j=$(echo "$1" | cut -c3-) |
| 46 ;; |
| 47 --jobs=[0-9]*) |
| 48 j=$(echo "$1" | cut -c8-) |
| 49 ;; |
| 45 -j|--jobs) | 50 -j|--jobs) |
| 46 if test -n "$2"; then | 51 case "$2" in |
| 47 j="$2" | 52 ''|-*) |
| 48 shift | 53 j=0 |
| 49 else | 54 ;; |
| 50 j=0 | 55 *) |
| 51 fi | 56 j="$2" |
| 57 shift |
| 58 ;; |
| 59 esac |
| 52 ;; | 60 ;; |
| 53 -n|--dry-run) | 61 -n|--dry-run) |
| 54 ECHO=echo | 62 ECHO=echo |
| 55 ;; | 63 ;; |
| 56 -h|--help) | 64 -h|--help) |
| 57 usage | 65 usage |
| 58 exit 0 | 66 exit 0 |
| 59 ;; | 67 ;; |
| 60 --fetch) | 68 --fetch) |
| 61 pull=fetch | 69 pull=fetch |
| (...skipping 13 matching lines...) Expand all Loading... |
| 75 if test -f "$PWD/src/.gitmodules"; then | 83 if test -f "$PWD/src/.gitmodules"; then |
| 76 break | 84 break |
| 77 fi | 85 fi |
| 78 cd .. | 86 cd .. |
| 79 done | 87 done |
| 80 if test "$PWD" = "/"; then | 88 if test "$PWD" = "/"; then |
| 81 echo "Could not find the root of your checkout; aborting." 1>&2 | 89 echo "Could not find the root of your checkout; aborting." 1>&2 |
| 82 exit 1 | 90 exit 1 |
| 83 fi | 91 fi |
| 84 | 92 |
| 93 if ( echo test test | xargs -P 2 true 2>/dev/null ); then |
| 94 xargs_parallel=yes |
| 95 else |
| 96 if test "$j" != "1"; then |
| 97 echo "Warning: parallel execution is not supported on this platform." 1>&2 |
| 98 fi |
| 99 xargs_parallel=no |
| 100 fi |
| 101 |
| 85 ls -d */.git | | 102 ls -d */.git | |
| 86 while read gitdir; do | 103 while read gitdir; do |
| 87 parallel_update `dirname $gitdir` | 104 parallel_update `dirname $gitdir` |
| 88 done | 105 done |
| 89 | 106 |
| 90 gclient_spec="solutions=[{'name':'src','url':None,'deps_file':'.DEPS.git'}]" | 107 gclient_spec="solutions=[{'name':'src','url':None,'deps_file':'.DEPS.git'}]" |
| 91 test "$hooks" = "yes" && gclient runhooks --spec="$gclient_spec" | 108 test "$hooks" = "yes" && gclient runhooks --spec="$gclient_spec" |
| OLD | NEW |