]> git.ozlabs.org Git - next-scripts/blob - do_merge
no_sig: send messages about missing SOB lines
[next-scripts] / do_merge
1 #!/bin/bash
2
3 no_build=false
4 start_from=""
5
6 [ "$1" = "-n" ] && {
7         shift
8         no_build=true
9 }
10 [ "$1" = "-s" ] && {
11         shift
12         start_from="$1"
13         [ -z "$start_from" ] && {
14                 echo "-s requires a start tree" 1>&2
15                 exit 1
16         }
17         shift
18 }
19
20 tool_dir=$(dirname "$0")
21 . "$tool_dir/common.sh"
22
23 log()
24 {
25         echo "$@" | tee -a "$LOG_FILE"
26 }
27
28 execute()
29 {
30         log "$" "$@"
31         "$@" 2>&1 | tee -a "$LOG_FILE"
32         return "${PIPESTATUS[0]}"
33 }
34
35 do_rebase()
36 {
37         rbase=${1#*/}
38         rbase="$2/${rbase%%:*}"
39         rtop="$2/${1#*:}"
40         rbid=$(git rev-parse "$rbase")
41         rtid=$(git rev-parse "$rtop")
42         [ "$rbid" = "$rtid" ] && {
43                 echo Empty tree
44                 return
45         }
46         [ "$(git rev-list HEAD..$rtop)" ] || {
47                 echo Already merged
48                 return
49         }
50         execute git clone -s -l -n -q . ../rebase-tmp || {
51                 echo Clone failed 1>&2
52                 bash -i || exit
53         }
54         log '$' cd ../rebase-tmp
55         cd ../rebase-tmp
56         execute git fetch --no-tags ../next "refs/remotes/$rtop:$rtop" || {
57                 echo Fetch of top failed 1>&2
58                 bash -i || exit
59         }
60         execute git fetch --no-tags ../next "refs/remotes/$rbase:$rbase" || {
61                 echo Fetch of base failed 1>&2
62                 bash -i || exit
63         }
64         execute git checkout "$rtop" || {
65                 echo Checkout of top failed 1>&2
66                 bash -i || exit
67         }
68         execute git rebase --onto master "$rbase" || {
69                 echo Rebase failed 1>&2
70                 bash -i || exit
71         }
72         log '$' cd ../next
73         cd ../next
74         execute git pull -f ../rebase-tmp "$rtop" || {
75                 echo Pull failed 1>&2
76                 echo "$h" >>../merge.debug
77                 git diff >>../merge.debug 2>&1
78                 git diff 2>&1 | egrep -q '<<<<<|^\*' && {
79                         bash -i || exit
80                 }
81         }
82         execute rm -rf ../rebase-tmp
83 }
84
85 [ -n "$start_from" ] || {
86         cp /dev/null "$LOG_FILE"
87         execute date -R
88         execute git checkout master
89         execute git reset --hard stable
90         printf 'Name\t\tSHA1\n----\t\t----\n' > "$SHA1_FILE"
91
92 }
93
94 heads=$(grep -v '^#' "$CTRL_FILE" | awk -F '\t' '$2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); }')
95
96 need_build=false
97
98 for h in $heads; do
99         tree=${h%%/*}
100
101         [ -n "$start_from" ] && {
102                 if [ "$tree" = "$start_from" ]; then
103                         start_from=""
104                 else
105                         continue
106                 fi
107         }
108
109         hlog=$(git log -1 --oneline "${h/\/*://}") 2>/dev/null
110         old_head=$(git rev-parse HEAD)
111         [ -f "../pre-merge/$tree" ] && {
112                 for p in $(cat "../pre-merge/$tree"); do
113                         "$bin_dir/do_patch" -n "$p" || {
114                                 notify-send -u critical -t 0 "premerge patch failed"
115                                 bash -i || exit
116                         }
117                 done
118         }
119         log Merging "$h" "($hlog)"
120         case "$h" in
121         *:*)
122                 do_rebase "$h" "$tree"
123                 ;;
124         *)
125                 execute git merge "$h" || {
126                         echo Merge failed 1>&2
127                         echo "$h" >>../merge.debug
128                         git diff >>../merge.debug 2>&1
129                         um_files=$(git diff 2>&1 | sed -n 's/^\* Unmerged path //p')
130                         [ "$um_files" ] && [ -f "../merge-files/$tree" ] && {
131                                 rm_files=$(grep -F "$um_files" "../merge-files/$tree")
132                                 [ "$rm_files" ] &&
133                                         "$bin_dir/do_rm" $rm_files
134                         }
135                         git diff 2>&1 | egrep -q '<<<<<|^\*' && {
136                                 notify-send -t 0 -u critical "linux-next new conflict found merging $tree!"
137                                 pushover "linux-next new conflict found merging $tree!"
138                                 if [ -f "../merge-fixes/$tree" ]; then
139                                         echo "Merge fixes exist for this tree:"
140                                         cat "../merge-fixes/$tree"
141                                 fi
142                                 bash -i || exit
143                         }
144 #                       [ "$(git status --porcelain)" ] && {
145                                 GIT_EDITOR=: execute git commit -v -a || {
146                                         notify-send -t 0 -u critical "linux-next commit failed for $tree!"
147                                         pushover "linux-next commit failed for $tree!"
148                                         bash -i || exit
149                                 }
150                                 execute git diff -M --stat --summary 'HEAD^..'
151 #                       }
152                 }
153                 ;;
154         esac
155         [ -f "../merge-fixes/$tree" ] && {
156                 for p in $(cat "../merge-fixes/$tree"); do
157                         "$bin_dir/merge_fix" -n "$p" || {
158                                 notify-send -t 0 -u critical "linux-next merge fix failed for $tree!"
159                                 pushover "linux-next merge fix failed for $tree!"
160                                 bash -i || exit
161                         }
162                 done
163         }
164         tab="\t"
165         [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
166         printf "%s$tab%s\n" $tree $(git rev-parse "${h/\/*://}^{}") >> $SHA1_FILE
167         $no_build && continue
168         $need_build || {
169                 # See if we need to build after merging this tree
170                 new_head=$(git rev-parse HEAD)
171                 [ "$old_head" = "$new_head" ] ||
172                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
173                                 need_build=true
174         }
175         $need_build ||
176                 continue
177         do_build=$(grep -v '^#' $CTRL_FILE | awk -F '   ' '$3=="'$tree'" { print $6; }')
178         [ "$do_build" = "yes" ] ||
179                 continue
180         git push -f "${build_host}${build_host:+:}${build_dir}" master:refs/heads/next || {
181                 echo git push failed 1>&2
182                 notify-send -t 0 -u critical "linux-next push failed for $tree!"
183                 pushover "linux-next push failed for $tree!"
184                 bash -i || exit
185         }
186         [ -x "../pre-build/$tree" ] && {
187                 "../pre-build/$tree" || {
188                         echo Prebuild script failed 1>&2
189                         notify-send -t 0 -u critical "linux-next pre-build script failed for $tree!"
190                         pushover "linux-next pre-build script failed for $tree!"
191                         bash -i || exit
192                 }
193         }
194         "$bin_dir/do_build" "$tree" || {
195                 echo Build failed 1>&2
196                 notify-send -t 0 -u critical "linux-next build failed for $tree!"
197                 pushover "linux-next build failed for $tree!"
198                 bash -i || exit
199         }
200
201         notify-send -u normal "Merge and build of $tree successful"
202
203         need_build=false
204 done
205
206 exit 0