OLD | NEW |
1 #!/bin/bash | 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 export GIT_MERGE_AUTOEDIT=0 |
| 11 |
11 ECHO= | 12 ECHO= |
12 pull=pull | 13 pull=pull |
13 pull_args= | 14 pull_args= |
14 hooks=yes | 15 hooks=yes |
| 16 j=10 |
| 17 crup_runner="crup-runner.sh" |
| 18 |
| 19 kernel_name=$(uname -s) |
| 20 if [ "${kernel_name:0:5}" = "MINGW" -o "${kernel_name:0:6}" = "CYGWIN" ]; then |
| 21 GIT_EXE=git.exe |
| 22 else |
| 23 GIT_EXE=git |
| 24 fi |
| 25 export GIT_EXE |
15 | 26 |
16 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then | 27 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then |
17 max_lines="--max-lines=1" | 28 max_lines="--max-lines=1" |
18 else | 29 else |
19 max_lines="-L 1" | 30 max_lines="-L 1" |
20 fi | 31 fi |
21 | 32 |
| 33 if ( echo test | xargs -I bar true 2>/dev/null ); then |
| 34 replace_arg="-I replace_arg" |
| 35 else |
| 36 replace_arg="-ireplace_arg" |
| 37 fi |
| 38 |
22 usage() { | 39 usage() { |
23 cat <<EOF 1>&2 | 40 cat <<EOF |
24 Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]] | 41 Usage: git-crup [-n|--dry-run] [--fetch] [-j|--jobs [jobs]] |
25 [--no-hooks] [<args to git-pull or git-fetch>] | 42 [--no-hooks] [<args to git-pull or git-fetch>] |
26 EOF | 43 EOF |
27 } | 44 } |
28 | 45 |
29 parallel_update() { | 46 serial_update() { |
30 ( echo Entering "$1" | 47 ( cd "$1" |
31 cd "$1" | 48 $GIT_EXE $pull $pull_args -q origin | sed "s/^/[$1] /g" |
32 $ECHO git $pull $pull_args origin | 49 if [ $? -ne 0 ]; then |
33 $ECHO git submodule sync | 50 return $? |
34 if test "$xargs_parallel" = "yes"; then | 51 fi |
35 git ls-files -s | grep ^160000 | awk '{print $4}' | | 52 $GIT_EXE submodule --quiet sync |
36 xargs $max_lines -P "$j" $ECHO git submodule update --init | 53 $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | |
37 else | 54 while read submod; do |
38 $ECHO git submodule update --init | 55 $GIT_EXE submodule update --init "$submod" | sed "s|^|[$1/$submod] |g" |
39 fi ) | 56 done |
| 57 ) |
40 } | 58 } |
41 | 59 |
42 while test $# -ne 0; do | 60 while test $# -ne 0; do |
43 case "$1" in | 61 case "$1" in |
44 -j[0-9]*) | 62 -j[0-9]*) |
45 j=$(echo "$1" | cut -c3-) | 63 j=$(echo "$1" | cut -c3-) |
46 ;; | 64 ;; |
47 --jobs=[0-9]*) | 65 --jobs=[0-9]*) |
48 j=$(echo "$1" | cut -c8-) | 66 j=$(echo "$1" | cut -c8-) |
49 ;; | 67 ;; |
(...skipping 11 matching lines...) Expand all Loading... |
61 -n|--dry-run) | 79 -n|--dry-run) |
62 ECHO=echo | 80 ECHO=echo |
63 ;; | 81 ;; |
64 -h|--help) | 82 -h|--help) |
65 usage | 83 usage |
66 exit 0 | 84 exit 0 |
67 ;; | 85 ;; |
68 --fetch) | 86 --fetch) |
69 pull=fetch | 87 pull=fetch |
70 ;; | 88 ;; |
71 --no-hooks) | 89 --no-hooks|--nohooks) |
72 hooks=no | 90 hooks=no |
73 ;; | 91 ;; |
74 *) | 92 *) |
75 pull_args="$pull_args $1" | 93 pull_args="$pull_args $1" |
76 break | 94 break |
77 ;; | 95 ;; |
78 esac | 96 esac |
79 shift | 97 shift |
80 done | 98 done |
81 | 99 |
(...skipping 10 matching lines...) Expand all Loading... |
92 | 110 |
93 if ( echo test test | xargs -P 2 true 2>/dev/null ); then | 111 if ( echo test test | xargs -P 2 true 2>/dev/null ); then |
94 xargs_parallel=yes | 112 xargs_parallel=yes |
95 else | 113 else |
96 if test "$j" != "1"; then | 114 if test "$j" != "1"; then |
97 echo "Warning: parallel execution is not supported on this platform." 1>&2 | 115 echo "Warning: parallel execution is not supported on this platform." 1>&2 |
98 fi | 116 fi |
99 xargs_parallel=no | 117 xargs_parallel=no |
100 fi | 118 fi |
101 | 119 |
102 ls -d */.git | | 120 set -o pipefail |
103 while read gitdir; do | |
104 parallel_update `dirname $gitdir` | |
105 done | |
106 | 121 |
107 gclient_spec="solutions=[{'name':'src','url':None,'deps_file':'.DEPS.git'}]" | 122 if test "$xargs_parallel" = "yes"; then |
108 test "$hooks" = "yes" && gclient runhooks --spec="$gclient_spec" | 123 ( ls -d */.git | sed 's/\/\.git$//' | |
| 124 xargs $max_lines $replace_arg -P "$j" \ |
| 125 "$crup_runner" replace_arg $GIT_EXE $pull $pull_args -q origin | |
| 126 xargs $max_lines -P "$j" "$crup_runner" ) |
| 127 else |
| 128 ls -d */.git | |
| 129 while read gitdir; do |
| 130 serial_update "${gitdir%%/.git}" |
| 131 done |
| 132 fi |
| 133 |
| 134 status=$? |
| 135 |
| 136 if [ "$hooks" = "yes" -a "$status" -eq 0 ]; then |
| 137 gclient_spec="solutions=[{'name':'src','url':None,'deps_file':'.DEPS.git'}]" |
| 138 gclient runhooks --spec="$gclient_spec" |
| 139 status=$? |
| 140 fi |
| 141 |
| 142 echo |
| 143 exit $status |
OLD | NEW |