]> git.ozlabs.org Git - next-scripts/blob - do_merge
01d7f1c01bbdc1220680286639b0419a2780d264
[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 [ -n "$start_from" ] || {
36         cp /dev/null "$LOG_FILE"
37         execute date -R
38         execute git checkout master
39         execute git reset --hard stable
40         printf 'Name\t\tSHA1\n----\t\t----\n' > "$SHA1_FILE"
41
42 }
43
44 heads=$(awk -F '\t' '/^#/ { next; } $2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); } $2=="branch" { printf("branch/%s ", $1); }' "$CTRL_FILE")
45
46 need_build=false
47
48 for h in $heads; do
49         tree=${h%%/*}
50
51         [ -n "$start_from" ] && {
52                 if [ "$tree" = "$start_from" ]; then
53                         start_from=""
54                 else
55                         continue
56                 fi
57         }
58
59         [ "$tree" = "branch" ] && {
60                 git branch -f "${h#branch/}"
61                 continue
62         }
63
64         hlog=$(git log -1 --oneline "${h/\/*://}") 2>/dev/null
65         old_head=$(git rev-parse HEAD)
66         [ -f "../pre-merge/$tree" ] && {
67                 for p in $(cat "../pre-merge/$tree"); do
68                         "$bin_dir/do_patch" -n "$p" || {
69                                 linux-next-notify "premerge patch failed"
70                                 bash -i || exit
71                         }
72                 done
73         }
74         log Merging "$h" "($hlog)"
75         execute git merge "$h" || {
76                 echo Merge failed 1>&2
77                 echo "$h" >>../merge.debug
78                 git diff >>../merge.debug 2>&1
79
80                 check_unmerged_files "$tree"
81
82                 git diff 2>&1 | egrep -q '<<<<<|^\*' && {
83                         linux-next-notify "new conflict found merging $tree"
84                         if [ -f "../merge-fixes/$tree" ]; then
85                                 echo "Merge fixes exist for this tree:"
86                                 cat "../merge-fixes/$tree"
87                         fi
88                         bash -i || exit
89                 }
90 #               [ "$(git status --porcelain)" ] && {
91                         GIT_EDITOR=: execute git commit -v -a || {
92                                 linux-next-notify "next commit failed for $tree"
93                                 bash -i || exit
94                         }
95                         execute git diff -M --stat --summary 'HEAD^..'
96 #               }
97         }
98         [ -f "../merge-fixes/$tree" ] && {
99                 for p in $(cat "../merge-fixes/$tree"); do
100                         "$bin_dir/merge_fix" -n "$p" || {
101                                 linux-next-notify "merge fix failed for $tree"
102                                 bash -i || exit
103                         }
104                 done
105         }
106         tab="\t"
107         [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
108         printf "%s$tab%s\n" $tree $(git rev-parse "${h/\/*://}^{}") >> $SHA1_FILE
109         $no_build && continue
110         $need_build || {
111                 # See if we need to build after merging this tree
112                 new_head=$(git rev-parse HEAD)
113                 [ "$old_head" = "$new_head" ] ||
114                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
115                                 need_build=true
116         }
117         $need_build ||
118                 continue
119         do_build=$(awk -F '\t' '/^[^#]/ && $3=="'$tree'" { print $6; }' "$CTRL_FILE")
120         [ "$do_build" = "yes" ] ||
121                 continue
122         git push -f "${build_host}${build_host:+:}${build_dir}" master:refs/heads/next || {
123                 echo git push failed 1>&2
124                 linux-next-notify "push failed for $tree"
125                 bash -i || exit
126         }
127         [ -x "../pre-build/$tree" ] && {
128                 "../pre-build/$tree" || {
129                         echo Prebuild script failed 1>&2
130                         linux-next-notify "pre-build script failed for $tree"
131                         bash -i || exit
132                 }
133         }
134         "$bin_dir/do_build" "$tree" || {
135                 echo Build failed 1>&2
136                 linux-next-notify "build failed for $tree"
137                 bash -i || exit
138         }
139
140         need_build=false
141 done
142
143 exit 0