-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepo
executable file
·412 lines (392 loc) · 10.7 KB
/
repo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#!/bin/bash
# Embedded Linux Platform Build
# Copyright (C) 2015 Nokia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -eu
BUGMAIL='[email protected]'
rootgit()
{
git "$@"
}
populatesubs()
{
SUBS=()
FULLSUBS=()
SUB_OFF=()
SUB_ON=()
SUB_MOD=()
for i in "$@"; do
case "$i" in
src/*)
SUBS[${#SUBS[@]}]="${i/src\/}"
FULLSUBS[${#FULLSUBS[@]}]="$i"
;;
*)
SUBS[${#SUBS[@]}]="$i"
FULLSUBS[${#FULLSUBS[@]}]="src/$i"
;;
esac
done
git submodule init
for i in $(git submodule status ${FULLSUBS[@]-} | sed -e 's|\(.\)\([0-9a-f]*\) \([^ ]*\).*|\1,\3|' | tr ' ' .); do
case "$i" in
+,*) SUB_MOD[${#SUB_MOD[@]}]="/${i/+,src\/}/";;
-,*) SUB_OFF[${#SUB_OFF[@]}]="/${i/-,src\/}/";;
.,*) SUB_ON[${#SUB_ON[@]}]="/${i/.,src\/}/";;
*) echo Error parsing git submodule status.; exit 1;;
esac
done
}
pull()
{
local dopull="$1"
shift
if test -r .basehash.linux; then
basehash=$(cat .basehash.linux)
else
basehash=$(git cat-file -p HEAD:src | sed -ne 's|^160000 commit \([0-9a-f]*\)[[:space:]]*'"linux"'$|\1|p')
fi
if test "$dopull" = 1; then
git pull
fi
if test -d .git/hooks -a -d hooks; then
for i in hooks/*; do
rm -f ".git/$i"
cp -a "$i" ".git/$i"
done
fi
populatesubs "$@"
if test ${#SUB_MOD[@]} != 0; then
for PRJ in "${SUB_MOD[@]//\/}"; do
if (
cd src/$PRJ
git log --pretty=format:%d -1 |
grep -q _persistent/ ||
git fetch
git log --pretty=format:%d -1 |
grep -q _persistent/
); then
#echo "refreshing checked out $PRJ..."
git submodule update --init src/$PRJ || true
case "$PRJ" in
linux)
rm -f .basehash.linux
basehash=$(git cat-file -p HEAD:src | sed -ne 's|^160000 commit \([0-9a-f]*\)[[:space:]]*'"linux"'$|\1|p')
;;
esac
SUB_ON[${#SUB_ON[@]}]="/$PRJ/"
SUB_MOD=( ${SUB_MOD[@]/"/$PRJ/"} )
else
echo "NOT refreshing $PRJ with local modifications!"
case "$PRJ" in
linux)
echo "$basehash" > .basehash.linux
;;
esac
fi
done
fi
}
push()
{
retryid=
for retry in 0 1 2; do
pull 1 "$@"
if test ${#SUB_MOD[@]} = 0; then
echo No modifications to push.
exit 1
fi
cat <<EOT > .tmp.alllogs
# Create a commit message from all the commits below and
=== DELETE AT LEAST THIS LINE ===
EOT
ALLDIRS=
includeslinux=0
for i in "${SUB_MOD[@]//\/}"; do
echo "$i"
ALLDIRS="$ALLDIRS src/$i"
uphash=$(git cat-file -p HEAD:src | sed -ne 's|^160000 commit \([0-9a-f]*\)[[:space:]]*'"$i"'$|\1|p')
cd src/$i
case "$i" in
linux)
includeslinux=1
downhash=$(git show-ref --head | sed -ne 's| HEAD$||p')
if test $basehash = $uphash; then
uptype=none
elif test $(git merge-base $basehash $uphash) = $basehash; then
uptype=ff
else
uptype=complex
fi
if test $basehash = $downhash; then
downtype=none
elif test $(git merge-base $basehash $downhash) = $basehash; then
downtype=ff
else
downtype=complex
fi
if test $downtype = none -o $uphash = $downhash; then
git checkout $uphash
elif test $uptype = none -o $downtype = ff; then
if test $uptype != none; then
git rebase --onto $uphash $basehash $downhash
fi
git log --no-merges --format=format:'# commit %h from linux%n%s%n%n%b' $basehash..$downhash >> ../../.tmp.alllogs
else
if test $uptype = ff; then
cat <<EOT
You did a complex change but upstream there were a few commits you may
want to merge into your tree before continuing:
EOT
git log --oneline $basehash..$uphash
else
cat <<EOT
You did a complex change but upstream there was also a complex change.
Thus you may want to merge things together before continuing.
EOT
fi
echo
exit 1
fi
;;
*)
if ! git merge -m '[repo push] automated merge' $uphash; then
cat <<EOT
Automated merge failed.
Do this:
\$ cd $PWD
[ merge conflicts ]
[ git add conflicting files ]
\$ git commit
After having that completed rerun this tool.
EOT
rm .tmp.alllogs
exit 1
fi
git log --no-merges --format=format:"# commit %h from $i%n%s%n%n%b" $uphash..HEAD >> ../../.tmp.alllogs
;;
esac
git push origin +HEAD:refs/heads/tmp
cd ../..
done
if test "$retryid"; then
git commit -C "$retryid" $ALLDIRS
else
git commit -t .tmp.alllogs $ALLDIRS
fi
if git push origin HEAD; then
retryid=
else
retryid=$(git rev-parse HEAD)
git reset HEAD^
fi
rm .tmp.alllogs
case "$i" in
linux)
rm -f .basehash.linux
;;
esac
if test -z "$retryid"; then
break;
fi
done
if test "$retryid"; then
cat <<EOT
It seems the push failed. :(
Typically you should get an idea of what went wrong from the git message.
This might be a problem with atomicity of the operation. In that case you
may just try to rerun this tool.
If this does not help and you need further assistance please send a mail
to $BUGMAIL with the command line and the output of this
tool and all other information that you think might be useful to diagnose
this issue.
EOT
exit 1
fi
}
status()
{
populatesubs "$@"
if test ${#SUB_MOD[@]} != 0; then
echo modified: "${SUB_MOD[@]//\/}"
fi
if test ${#SUB_ON[@]} != 0; then
echo unmodified: "${SUB_ON[@]//\/}"
fi
if test ${#SUB_OFF[@]} != 0; then
echo not checked out: "${SUB_OFF[@]//\/}"
fi
}
drop()
{
local force=0
if test $# -gt 0; then
if test "$1" = -f; then
force=1
shift
fi
fi
populatesubs "$@"
if test ${#SUB_MOD[@]} != 0; then
if test $force = 0; then
echo "Local modifications exit in ${SUB_MOD[@]//\/}, use -f for force."
exit 1
fi
for PRJ in "${SUB_MOD[@]//\/}"; do
if test "$PRJ" = buildtool; then
echo 'Not dropping buildtool.'
else
echo dropping $PRJ
rm -rf src/$PRJ
mkdir src/$PRJ
fi
done
fi
if test ${#SUB_ON[@]} != 0; then
for PRJ in "${SUB_ON[@]//\/}"; do
if test "$PRJ" = buildtool; then
echo 'Not dropping buildtool.'
else
echo dropping $PRJ
rm -rf src/$PRJ
mkdir src/$PRJ
fi
done
fi
}
fetch()
{
populatesubs "$@"
if test ${#SUB_MOD[@]} != 0; then
echo Not fetching ${SUB_MOD[@]//\/}, use pull instead.
fi
if test ${#SUB_OFF[@]} != 0; then
for PRJ in "${SUB_OFF[@]//\/}"; do
echo fetching $PRJ
git submodule update src/$PRJ
done
fi
}
switch()
{
if test $# == 0; then # without parameters print actual branch
git branch -v
fi
if test $# != 1; then
echo >&2 repo switch takes exactly one branch name as parameter.
exit 1
fi
local branch="$1"
git fetch
if git show "origin/$branch" >/dev/null 2>/dev/null; then
if ! git show "$branch" >/dev/null 2>/dev/null; then
echo git branch -t "$branch" "origin/$branch"
fi
git checkout "$branch"
pull 1
else
if ! git checkout "$branch"; then
echo >&2 Unknown branch or tag: $branch
exit 1
fi
pull 0
fi
}
diff()
{
subsopts=""
dirty=""
if [[ $# > 0 && "${1}" = "--dirty" ]]; then
dirty=1
subsopts="--ignore-submodules=none"
shift
[[ $# > 1 ]] && echo "--dirty only allows one commit-id" && exit 1
fi
git --no-pager diff --ignore-submodules --no-prefix "$@"
git --no-pager diff --raw $subsopts "$@" src | while read MODEA MODEB HASHA HASHB MODTYPE MODULE; do
if test \
"$MODEA" = ":160000" -a \
"$MODEB" = "160000" -a \
"$MODTYPE" = "M"; then
(
if test "$dirty" != "1" && test ! "$(ls -A $MODULE )"; then # check if submodul empty -> fetch submodule
echo "fetching $MODULE for diff"
fetch $MODULE;
fi
cd $MODULE
test "$HASHB" = 0000000... || test "$dirty" = "1" && HASHB=
git --no-pager diff --src-prefix=$MODULE/ --dst-prefix=$MODULE/ ${HASHA/...} ${HASHB/...}
)
else
echo "WARNING: Unhandled change $MODEA $MODEB $HASHA $HASHB $MODTYPE $MODULE"
fi
done
}
usage()
{
cat <<EOT
Usage:
repo diff <commit>{0,2} Calculate a global diff between committed
changes. The specified commits follow the
same rules as for the regular git diff command.
repo diff --dirty [commit] Calculate a global diff against uncommited and
unstaged changes in the workspace. The specified
commit follows the same rules as for the regular
git diff command.
repo drop [-f] [SUBMODULE]... Delete the checked out sources for the
specified submodules from the local disk. If no
submodule is specified delete all sources. To
delete sources with local commits the option -f
needs to be specified.
repo fetch [SUBMODULE]... Check out sources for the specified submodules.
If no submodule is specified check out all
sources.
repo git [PARAM]... Invoke git with the specified parameters PARAM
from the root of the source repository.
repo pull [SUBMODULE]... Pull the changes for the specified submodules
from the server. If no submodule is specified
pull the changes for all submodules.
repo push [SUBMODULE]... Push all changes for the specified submodules
to the server. If no submodule is specified
push all changes for all submodules.
repo status [SUBMODULE]... Print the status for the specified submodules.
If no submodule is specified print overall
status.
repo switch [BRANCH] Switch to specified branch.
repo help Print this message and exit.
Report bugs to <$BUGMAIL>
EOT
exit $1
}
cd "$(dirname $0)"
test $# != 0 || usage 1
CMD=$1
shift
case "$CMD" in
diff) diff "$@";;
drop) drop "$@";;
fetch) fetch "$@";;
git) rootgit "$@";;
pull) pull 1 "$@";;
push) push "$@";;
status) status "$@";;
switch) switch "$@";;
help|--help) usage 0;;
*)
echo Unknown command $CMD
;;
esac
echo done.