]> git.ozlabs.org Git - next-scripts/blob - do_merge
d1c52e71dea8bf4ba672b21ed1cea5d416f0e778
[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); } $2=="branch" { printf("branch/%s ", $1); }')
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         [ "$tree" = "branch" ] && {
110                 git branch -f "${h#branch/}"
111                 continue
112         }
113
114         hlog=$(git log -1 --oneline "${h/\/*://}") 2>/dev/null
115         old_head=$(git rev-parse HEAD)
116         [ -f "../pre-merge/$tree" ] && {
117                 for p in $(cat "../pre-merge/$tree"); do
118                         "$bin_dir/do_patch" -n "$p" || {
119                                 notify-send -u critical -t 0 "premerge patch failed"
120                                 bash -i || exit
121                         }
122                 done
123         }
124         log Merging "$h" "($hlog)"
125         case "$h" in
126         *:*)
127                 do_rebase "$h" "$tree"
128                 ;;
129         *)
130                 execute git merge "$h" || {
131                         echo Merge failed 1>&2
132                         echo "$h" >>../merge.debug
133                         git diff >>../merge.debug 2>&1
134                         um_files=$(git diff 2>&1 | sed -n 's/^\* Unmerged path //p')
135                         [ "$um_files" ] && [ -f "../merge-files/$tree" ] && {
136                                 rm_files=$(grep -F "$um_files" "../merge-files/$tree")
137                                 [ "$rm_files" ] &&
138                                         "$bin_dir/do_rm" $rm_files
139                         }
140                         git diff 2>&1 | egrep -q '<<<<<|^\*' && {
141                                 notify-send -t 0 -u critical "linux-next new conflict found merging $tree!"
142                                 pushover "linux-next new conflict found merging $tree!"
143                                 if [ -f "../merge-fixes/$tree" ]; then
144                                         echo "Merge fixes exist for this tree:"
145                                         cat "../merge-fixes/$tree"
146                                 fi
147                                 bash -i || exit
148                         }
149 #                       [ "$(git status --porcelain)" ] && {
150                                 GIT_EDITOR=: execute git commit -v -a || {
151                                         notify-send -t 0 -u critical "linux-next commit failed for $tree!"
152                                         pushover "linux-next commit failed for $tree!"
153                                         bash -i || exit
154                                 }
155                                 execute git diff -M --stat --summary 'HEAD^..'
156 #                       }
157                 }
158                 ;;
159         esac
160         [ -f "../merge-fixes/$tree" ] && {
161                 for p in $(cat "../merge-fixes/$tree"); do
162                         "$bin_dir/merge_fix" -n "$p" || {
163                                 notify-send -t 0 -u critical "linux-next merge fix failed for $tree!"
164                                 pushover "linux-next merge fix failed for $tree!"
165                                 bash -i || exit
166                         }
167                 done
168         }
169         tab="\t"
170         [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
171         printf "%s$tab%s\n" $tree $(git rev-parse "${h/\/*://}^{}") >> $SHA1_FILE
172         $no_build && continue
173         $need_build || {
174                 # See if we need to build after merging this tree
175                 new_head=$(git rev-parse HEAD)
176                 [ "$old_head" = "$new_head" ] ||
177                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
178                                 need_build=true
179         }
180         $need_build ||
181                 continue
182         do_build=$(grep -v '^#' $CTRL_FILE | awk -F '   ' '$3=="'$tree'" { print $6; }')
183         [ "$do_build" = "yes" ] ||
184                 continue
185         git push -f "${build_host}${build_host:+:}${build_dir}" master:refs/heads/next || {
186                 echo git push failed 1>&2
187                 notify-send -t 0 -u critical "linux-next push failed for $tree!"
188                 pushover "linux-next push failed for $tree!"
189                 bash -i || exit
190         }
191         [ -x "../pre-build/$tree" ] && {
192                 "../pre-build/$tree" || {
193                         echo Prebuild script failed 1>&2
194                         notify-send -t 0 -u critical "linux-next pre-build script failed for $tree!"
195                         pushover "linux-next pre-build script failed for $tree!"
196                         bash -i || exit
197                 }
198         }
199         "$bin_dir/do_build" "$tree" || {
200                 echo Build failed 1>&2
201                 notify-send -t 0 -u critical "linux-next build failed for $tree!"
202                 pushover "linux-next build failed for $tree!"
203                 bash -i || exit
204         }
205
206         notify-send -u normal "Merge and build of $tree successful"
207
208         need_build=false
209 done
210
211 exit 0