Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2057)

Side by Side Diff: git-crup

Issue 12865010: Refactor with fixes for msys-git. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: fix reinvoke logic Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « crup-runner.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Auto-update depot_tools 10 orig_args="$@"
11 if [ -z "$GIT_CRUP_REINVOKE" ]; then
12 update_depot_tools || exit 1
13 GIT_CRUP_REINVOKE=1 exec bash "$0" "$@"
14 fi
15
16 export GIT_MERGE_AUTOEDIT=0
17
18 ECHO= 11 ECHO=
19 pull=pull 12 pull=pull
20 pull_args= 13 pull_args=
21 hooks=yes 14 hooks=yes
22 j=10 15 j=10
23 crup_runner="crup-runner.sh" 16 crup_runner="crup-runner.sh"
24 runhooks="git-runhooks"
25
26 kernel_name=$(uname -s)
27 if [ "${kernel_name:0:5}" = "MINGW" -o "${kernel_name:0:6}" = "CYGWIN" ]; then
28 GIT_EXE=git.exe
29 else
30 GIT_EXE=git
31 fi
32 export GIT_EXE
33
34 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then
35 max_lines="--max-lines=1"
36 else
37 max_lines="-L 1"
38 fi
39
40 if ( echo test | xargs -I bar true 2>/dev/null ); then
41 replace_arg="-I replace_arg"
42 else
43 replace_arg="-ireplace_arg"
44 fi
45 17
46 usage() { 18 usage() {
47 cat <<EOF 19 cat <<EOF
48 Usage: git-crup [-n|--dry-run] [--fetch|--sync] [-j|--jobs [jobs]] 20 Usage: git-crup [-n|--dry-run] [--fetch|--sync] [-j|--jobs [jobs]]
49 [--no-hooks] [<args to git-pull or git-fetch>] 21 [--no-hooks] [<args to git-pull or git-fetch>]
22
23 -n, --dry-run Don't do anything; just show what would have been done.
24 --fetch Run 'git fetch' on top-level sources, but don't merge.
25 --sync Don't do anything at all to the top-level sources.
26 -j, --jobs Run this many jobs in parallel.
27 --no-hooks Don't run hooks (e.g., to generate build files) after
28 updating.
50 EOF 29 EOF
51 } 30 }
52 31
53 serial_update() { 32 serial_update() {
54 ( cd "$1" 33 ( cd "$1"
55 if test -n "$toplevel_cmd"; then 34 if test -n "$toplevel_cmd"; then
56 $toplevel_cmd | sed "s/^/[$1] /g" 35 $ECHO $toplevel_cmd | sed "s/^/[$1] /g"
57 if [ $? -ne 0 ]; then 36 if [ $? -ne 0 ]; then
58 return $? 37 return $?
59 fi 38 fi
60 fi 39 fi
61 $GIT_EXE submodule --quiet sync 40 $ECHO git submodule --quiet sync
62 $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | 41 $ECHO git ls-files -s | grep ^160000 | awk '{print $4}' |
63 while read submod; do 42 while read submod; do
64 "$crup_runner" "$1/$submod" 43 $ECHO "$crup_runner" "$1/$submod"
65 done 44 done
66 ) 45 )
67 } 46 }
68 47
69 while test $# -ne 0; do 48 while test $# -ne 0; do
70 case "$1" in 49 case "$1" in
71 -j[0-9]*) 50 -j[0-9]*)
72 j=$(echo "$1" | cut -c3-) 51 j=$(echo "$1" | cut -c3-)
73 ;; 52 ;;
74 --jobs=[0-9]*) 53 --jobs=[0-9]*)
(...skipping 27 matching lines...) Expand all
102 hooks=no 81 hooks=no
103 ;; 82 ;;
104 *) 83 *)
105 pull_args="$pull_args $1" 84 pull_args="$pull_args $1"
106 break 85 break
107 ;; 86 ;;
108 esac 87 esac
109 shift 88 shift
110 done 89 done
111 90
91 # Auto-update depot_tools. Windows behaves badly if you rewrite a file while
92 # it's being executed, which might happen to this file when update_depot_tools
93 # runs. So, we re-exec from a temporary script.
iannucci 2013/03/20 23:41:19 Are we absolutely sure that this happens? Doesn't
szager1 2013/03/21 00:06:08 By golly, you're right! I'll nuke this code.
94 if [ -z "$GIT_CRUP_REINVOKE" ]; then
95 if [ -z "$TEMP" ]; then
96 TEMP="/tmp"
97 fi
98 tmp_script="${TEMP}/git_crup_reinvoke.sh"
99 cat <<EOF > "$tmp_script"
100 #!/bin/bash
101
102 kernel_name="\$(uname -s)"
103 if [ "\${kernel_name:0:5}" = "MINGW" ]; then
104 cmd '/C update_depot_tools.bat'
105 else
106 update_depot_tools
107 fi
108 GIT_CRUP_REINVOKE=1 exec bash "$0" $orig_args
109 EOF
110 exec bash "$tmp_script" "$kernel_name"
111 fi
112
112 while test "$PWD" != "/"; do 113 while test "$PWD" != "/"; do
113 if test -f "$PWD/src/.gitmodules"; then 114 if test -f "$PWD/src/.gitmodules"; then
114 break 115 break
115 fi 116 fi
116 cd .. 117 cd ..
117 done 118 done
118 if test "$PWD" = "/"; then 119 if test "$PWD" = "/"; then
119 echo "Could not find the root of your checkout; aborting." 1>&2 120 echo "Could not find the root of your checkout; aborting." 1>&2
120 exit 1 121 exit 1
121 fi 122 fi
122 123
124 export GIT_MERGE_AUTOEDIT=no
125
126 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then
127 max_lines="--max-lines=1"
128 else
129 max_lines="-L 1"
130 fi
131
132 if ( echo test | xargs -I bar true 2>/dev/null ); then
133 replace_arg="-I replace_arg"
134 else
135 replace_arg="-ireplace_arg"
136 fi
137
123 if ( echo test test | xargs -P 2 true 2>/dev/null ); then 138 if ( echo test test | xargs -P 2 true 2>/dev/null ); then
124 xargs_parallel=yes 139 xargs_parallel=yes
125 else 140 else
126 if test "$j" != "1"; then 141 if test "$j" != "1"; then
127 echo "Warning: parallel execution is not supported on this platform." 1>&2 142 echo "Warning: parallel execution is not supported on this platform." 1>&2
128 fi 143 fi
129 xargs_parallel=no 144 xargs_parallel=no
130 fi 145 fi
131 146
132 if test -n "$pull"; then 147 if test -n "$pull"; then
133 toplevel_cmd="$GIT_EXE $pull $pull_args -q origin" 148 toplevel_cmd="git $pull $pull_args -q origin"
134 else 149 else
135 toplevel_cmd= 150 toplevel_cmd=
136 fi 151 fi
137 152
138 set -o pipefail 153 set -o pipefail
139 if test "$xargs_parallel" = "yes"; then 154 if test "$xargs_parallel" = "yes"; then
140 ( ls -d */.git | sed 's/\/\.git$//' | 155 ( ls -d */.git | sed 's/\/\.git$//' |
141 xargs $max_lines $replace_arg -P "$j" \ 156 xargs $max_lines $replace_arg -P "$j" \
142 "$crup_runner" replace_arg $toplevel_cmd | 157 "$crup_runner" replace_arg $ECHO $toplevel_cmd |
143 xargs $max_lines -P "$j" "$crup_runner" ) 158 xargs $max_lines -P "$j" $ECHO "$crup_runner" )
144 else 159 else
145 ls -d */.git | 160 ls -d */.git |
146 while read gitdir; do 161 while read gitdir; do
147 serial_update "${gitdir%%/.git}" 162 serial_update "${gitdir%%/.git}"
148 done 163 done
149 fi 164 fi
150 165
151 status=$? 166 status=$?
152 167
153 if [ "$status" -ne 0 ]; then 168 if [ "$status" -ne 0 ]; then
154 cat 1>&2 <<EOF 169 cat 1>&2 <<EOF
155 Please check the preceding terminal output for error messages. 170 Please check the preceding terminal output for error messages.
156 Run 'git submodule status' to see the current state of submodule checkouts. 171 Run 'git submodule status' to see the current state of submodule checkouts.
157 EOF 172 EOF
158 exit $status 173 exit $status
159 fi 174 fi
160 175
161 if [ "$hooks" = "yes" ]; then 176 if [ "$hooks" = "yes" ]; then
162 "$runhooks" 177 $ECHO git runhooks
163 status=$? 178 status=$?
164 fi 179 fi
165 180
166 echo 181 echo
167 exit $status 182 exit $status
OLDNEW
« no previous file with comments | « crup-runner.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698