]> git.ozlabs.org Git - next-scripts/blob - update_trees
only create/remove quilt-tmp once
[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
25         # don't bother importing things that haven't changed
26         change_size=$(cd ../quilt;git diff last_merge.. -- "$name/" | wc -c)
27         [ $change_size -eq 0 ] && {
28                 log "Unchanged quilt series $name"
29                 continue
30         }
31
32         sfile="../quilt/$name/series"
33         base=$(sed -n 's/^#[    ]*NEXT_BASE[    ]*\(.*\)[       ]*$/\1/p' "$sfile")
34         if [ -n "$base" ]; then
35                 base=$(grep -v '^#' ../real_control | awk -F '  ' '$3=="'"$base"'" { if ($2=="quilt") printf("quilt/%s", "'"$base"'"); else printf("%s/%s", "'"$base"'", $5); }')
36         else
37                 base=$(sed -n 's/^#[    ]*BASE[         ]*\(.*\)[       ]*$/\1/p' "$sfile")
38                 [ -n "$base" ] || {
39                         # for stgit
40                         base=$(sed '1{s/^#.*GIT commit \(.*\)$/\1/;q}' "$sfile")
41                         [ -n "$base" ] ||
42                                 base="origin/master"
43                 }
44         fi
45         rbase="$base"
46         case "$base" in
47         *-git[0-9]*)    rbase=$(wget -q -O - "http://www.kernel.org/pub/linux/kernel/v2.6/snapshots/patch-${base}.id")
48                         ;;
49         commit*)        rbase=$(expr "$base" : "commit[         ]*\(.*\)")
50                         ;;
51         [0-9]*.*)       rbase="v$base"
52                         ;;
53         esac
54         log "Importing $name based on $base"
55         rbase_sha1=$(git rev-parse --verify "$rbase^{commit}") || {
56                 log "Unknown BASE"
57                 continue
58         }
59         mv -f "$sfile" "$sfile.orig"
60         if grep -q NEXT_PATCHES "$sfile.orig"; then
61                 do_echo=:
62                 while read line; do
63                         case $line in
64                         *NEXT_PATCHES_START*)   do_echo=echo
65                                                 ;;
66                         *NEXT_PATCHES_END*)     do_echo=:
67                                                 ;;
68                         esac
69                         $do_echo $line
70                 done <"$sfile.orig" >"$sfile"
71         else
72                 cp "$sfile.orig" "$sfile"
73         fi
74
75         git show-ref --quiet --verify "refs/heads/quilt/$name" ||
76                 execute git branch "quilt/$name" "$rbase_sha1"
77
78         mv -f "$sfile" "$sfile.tmp"
79         sed -e '/^[     ]*$/d' -e '/^[  ]*#/d' <"$sfile.tmp" >"$sfile"
80         rm -f "$sfile.tmp"
81         [ -s "$sfile" ] || {
82                 log "   quilt series is empty"
83                 [ -f "$sfile.orig" ] &&
84                         mv -f "$sfile.orig" "$sfile"
85                 execute git update-ref "refs/heads/quilt/$name" "$rbase_sha1"
86                 continue
87         }
88
89         [ -d "../quilt-tmp" ] ||
90                 execute git clone -s -l -n -q . ../quilt-tmp
91
92         log '$' cd ../quilt-tmp
93         cd ../quilt-tmp
94         execute git reset --hard "$rbase_sha1"
95
96         author=$(grep -v '^#' ../real_control | awk -F '        ' '$3=="'"$name"'" { printf("%s", $1); }' | sed 's/,.*$//')
97         execute git quiltimport --author "$author" --patches "../quilt/$name"
98
99         log '$' cd ../next
100         cd ../next
101
102         execute git fetch -f ../quilt-tmp master:"quilt/$name"
103
104         [ -f "$sfile.orig" ] &&
105                 mv -f "$sfile.orig" "$sfile"
106 done
107
108 [ -d "../quilt-tmp" ] &&
109         rm -rf ../quilt-tmp
110
111 ( cd ../quilt; git update-ref refs/heads/last_merge HEAD )
112
113 exit 0