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