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

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: More usage 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
« crup-runner.sh ('K') | « 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_EXE submodule --quiet sync
62 $GIT_EXE ls-files -s | grep ^160000 | awk '{print $4}' | 41 $ECHO $GIT_EXE 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 kernel_name=$(uname -s)
92 if [ "${kernel_name:0:5}" = "MINGW" -o "${kernel_name:0:6}" = "CYGWIN" ]; then
iannucci 2013/03/19 22:11:52 Why not do `which git` and fall back to git.exe?
szager1 2013/03/20 21:47:01 On further examination, I don't think GIT_EXE is e
93 GIT_EXE=git.exe
94 else
95 GIT_EXE=git
96 fi
97
98 # Auto-update depot_tools
99 if [ -z "$GIT_CRUP_REINVOKE" ]; then
100 if [ "${kernel_name:0:5}" = "MINGW" ]; then
101 # Windows behaves badly if you rewrite a file while it's being executed,
102 # which might happen when update_depot_tools runs.
103 cat <<EOF > "$TEMP/git_crup_reinvoke.sh"
104 #!/bin/bash
105
106 cmd '/C update_depot_tools.bat'
107 GIT_CRUP_REINVOKE=1 exec bash "$0" $orig_args
108 EOF
109 exec bash "$TEMP/git_crup_reinvoke.sh"
110 else
111 update_depot_tools
112 GIT_CRUP_REINVOKE=1 exec bash "$0" $orig_args
iannucci 2013/03/19 22:11:52 Why not just do the windows-path on all platforms?
szager1 2013/03/20 21:47:01 I separated out copying off upate_depot_tools.bat
113 fi
114 fi
115
112 while test "$PWD" != "/"; do 116 while test "$PWD" != "/"; do
113 if test -f "$PWD/src/.gitmodules"; then 117 if test -f "$PWD/src/.gitmodules"; then
114 break 118 break
115 fi 119 fi
116 cd .. 120 cd ..
117 done 121 done
118 if test "$PWD" = "/"; then 122 if test "$PWD" = "/"; then
119 echo "Could not find the root of your checkout; aborting." 1>&2 123 echo "Could not find the root of your checkout; aborting." 1>&2
120 exit 1 124 exit 1
121 fi 125 fi
122 126
127 export GIT_EXE
128 export GIT_MERGE_AUTOEDIT=no
129
130 if ( echo test | xargs --max-lines=1 true 2>/dev/null ); then
131 max_lines="--max-lines=1"
132 else
133 max_lines="-L 1"
134 fi
135
136 if ( echo test | xargs -I bar true 2>/dev/null ); then
137 replace_arg="-I replace_arg"
138 else
139 replace_arg="-ireplace_arg"
140 fi
141
123 if ( echo test test | xargs -P 2 true 2>/dev/null ); then 142 if ( echo test test | xargs -P 2 true 2>/dev/null ); then
124 xargs_parallel=yes 143 xargs_parallel=yes
125 else 144 else
126 if test "$j" != "1"; then 145 if test "$j" != "1"; then
127 echo "Warning: parallel execution is not supported on this platform." 1>&2 146 echo "Warning: parallel execution is not supported on this platform." 1>&2
128 fi 147 fi
129 xargs_parallel=no 148 xargs_parallel=no
130 fi 149 fi
131 150
132 if test -n "$pull"; then 151 if test -n "$pull"; then
133 toplevel_cmd="$GIT_EXE $pull $pull_args -q origin" 152 toplevel_cmd="$GIT_EXE $pull $pull_args -q origin"
134 else 153 else
135 toplevel_cmd= 154 toplevel_cmd=
136 fi 155 fi
137 156
138 set -o pipefail 157 set -o pipefail
139 if test "$xargs_parallel" = "yes"; then 158 if test "$xargs_parallel" = "yes"; then
140 ( ls -d */.git | sed 's/\/\.git$//' | 159 ( ls -d */.git | sed 's/\/\.git$//' |
141 xargs $max_lines $replace_arg -P "$j" \ 160 xargs $max_lines $replace_arg -P "$j" \
142 "$crup_runner" replace_arg $toplevel_cmd | 161 "$crup_runner" replace_arg $ECHO $toplevel_cmd |
143 xargs $max_lines -P "$j" "$crup_runner" ) 162 xargs $max_lines -P "$j" $ECHO "$crup_runner" )
144 else 163 else
145 ls -d */.git | 164 ls -d */.git |
146 while read gitdir; do 165 while read gitdir; do
147 serial_update "${gitdir%%/.git}" 166 serial_update "${gitdir%%/.git}"
148 done 167 done
149 fi 168 fi
150 169
151 status=$? 170 status=$?
152 171
153 if [ "$status" -ne 0 ]; then 172 if [ "$status" -ne 0 ]; then
154 cat 1>&2 <<EOF 173 cat 1>&2 <<EOF
155 Please check the preceding terminal output for error messages. 174 Please check the preceding terminal output for error messages.
156 Run 'git submodule status' to see the current state of submodule checkouts. 175 Run 'git submodule status' to see the current state of submodule checkouts.
157 EOF 176 EOF
158 exit $status 177 exit $status
159 fi 178 fi
160 179
161 if [ "$hooks" = "yes" ]; then 180 if [ "$hooks" = "yes" ]; then
162 "$runhooks" 181 $ECHO $GIT_EXE runhooks
163 status=$? 182 status=$?
164 fi 183 fi
165 184
166 echo 185 echo
167 exit $status 186 exit $status
OLDNEW
« crup-runner.sh ('K') | « crup-runner.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698