]> git.ozlabs.org Git - next-scripts/blob - update_trees
make sure we always have a commit to give to update-ref
[next-scripts] / update_trees
1 #!/bin/bash
2
3 cp /dev/null ../quilt-import.log
4
5 log()
6 {
7         echo "$@" | tee -a ../quilt-import.log
8 }
9
10 execute()
11 {
12         log "$" $@
13         "$@" 2>&1 | tee -a ../quilt-import.log
14         [ ${PIPESTATUS[0]} -eq 0 ] || sh -i || {
15                 [ -f "$sfile.orig" ] &&
16                         mv -f "$sfile.orig" "$sfile"
17                 exit 1
18         }
19 }
20
21 quilters=$(grep -v '^#' ../real_control | awk -F '      ' '$2=="quilt" { print $3; }')
22
23 for name in $quilters; do
24         sfile="../quilt/$name/series"
25         base=$(sed -n 's/^[#    ]*NEXT_BASE[    ]*\(.*\)[       ]*$/\1/p' "$sfile")
26         if [ -n "$base" ]; then
27                 base=$(grep -v '^#' ../real_control | awk -F '  ' '$3=="'"$base"'" { if ($2=="quilt") printf("quilt/%s", "'"$base"'"); else printf("%s/%s", "'"$base"'", $5); }')
28         else
29                 base=$(sed -n 's/^[#    ]*BASE[         ]*\(.*\)[       ]*$/\1/p' "$sfile")
30         fi
31         rbase="$base"
32         case "$base" in
33         *-git[0-9]*)    rbase=$(wget -q -O - "http://www.kernel.org/pub/linux/kernel/v2.6/snapshots/patch-${base}.id")
34                         ;;
35         commit*)        rbase=$(expr "$base" : "commit[         ]*\(.*\)")
36                         ;;
37         [0-9]*.*)       rbase="v$base"
38                         ;;
39         esac
40         log "Importing $name based on $base"
41         rbase_sha1=$(git rev-parse --verify "$rbase^{commit}") || {
42                 log "Unknown BASE"
43                 continue
44         }
45         mv -f "$sfile" "$sfile.orig"
46         if grep -q NEXT_PATCHES "$sfile.orig"; then
47                 do_echo=:
48                 while read line; do
49                         case $line in
50                         *NEXT_PATCHES_START*)   do_echo=echo
51                                                 ;;
52                         *NEXT_PATCHES_END*)     do_echo=:
53                                                 ;;
54                         esac
55                         $do_echo $line
56                 done <"$sfile.orig" >"$sfile"
57         else
58                 cp "$sfile.orig" "$sfile"
59         fi
60
61         git show-ref --quiet --verify "refs/heads/quilt/$name" ||
62                 execute git branch "quilt/$name" "$rbase_sha1"
63
64         mv -f "$sfile" "$sfile.tmp"
65         sed -e '/^[     ]*$/d' -e '/^[  ]*#/d' <"$sfile.tmp" >"$sfile"
66         rm -f "$sfile.tmp"
67         [ -s "$sfile" ] || {
68                 log "   quilt series is empty"
69                 [ -f "$sfile.orig" ] &&
70                         mv -f "$sfile.orig" "$sfile"
71                 execute git update-ref "refs/heads/quilt/$name" "$rbase_sha1"
72                 continue
73         }
74
75         execute git checkout "quilt/$name"
76         execute git reset --hard "$rbase_sha1"
77
78         author=$(grep -v '^#' ../real_control | awk -F '        ' '$3=="'"$name"'" { printf("%s", $1); }' | sed 's/,.*$//')
79         execute git quiltimport --author "$author" --patches "../quilt/$name"
80
81         [ -f "$sfile.orig" ] &&
82                 mv -f "$sfile.orig" "$sfile"
83 done
84
85 git checkout master
86
87 exit 0