]> git.ozlabs.org Git - next-scripts/blob - do_merge
add the control file to common.sh
[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 . "$(dirname $0)/common.sh"
21
22 log()
23 {
24         echo "$@" | tee -a $LOG_FILE
25 }
26
27 execute()
28 {
29         log "$" $@
30         $@ 2>&1 | tee -a $LOG_FILE
31         return ${PIPESTATUS[0]}
32 }
33
34 do_rebase()
35 {
36         rbase=${1#*/}
37         rbase=${rbase%%:*}
38         rtop=${1#*:}
39         rbid=$(git rev-parse $2/$rbase)
40         rtid=$(git rev-parse $2/$rtop)
41         [ "$rbid" = "$rtid" ] && {
42                 echo Empty tree
43                 return
44         }
45         [ "$(git rev-list HEAD..$2/$rtop)" ] || {
46                 echo Already merged
47                 return
48         }
49         execute git clone -s -l -n -q . ../rebase-tmp || {
50                 echo Clone failed 1>&2
51                 bash -i || exit
52         }
53         log '$' cd ../rebase-tmp
54         cd ../rebase-tmp
55         execute git fetch --no-tags ../next refs/remotes/$2/$rtop:$2/$rtop || {
56                 echo Fetch of top failed 1>&2
57                 bash -i || exit
58         }
59         execute git fetch --no-tags ../next refs/remotes/$2/$rbase:$2/$rbase || {
60                 echo Fetch of base failed 1>&2
61                 bash -i || exit
62         }
63         execute git checkout $2/$rtop || {
64                 echo Checkout of top failed 1>&2
65                 bash -i || exit
66         }
67         execute git rebase --onto master $2/$rbase || {
68                 echo Rebase failed 1>&2
69                 bash -i || exit
70         }
71         log '$' cd ../next
72         cd ../next
73         execute git pull -f ../rebase-tmp $2/$rtop || {
74                 echo Pull failed 1>&2
75                 echo $h >>../merge.debug
76                 git diff >>../merge.debug 2>&1
77                 git diff 2>&1 | egrep -q '<<<<<|^\*' && {
78                         bash -i || exit
79                 }
80         }
81         execute rm -rf ../rebase-tmp
82 }
83
84 [ -n "$start_from" ] || {
85         cp /dev/null $LOG_FILE
86         execute date
87         execute git checkout master
88         execute git reset --hard stable
89         printf 'Name\t\tSHA1\n----\t\t----\n' > $SHA1_FILE
90
91 }
92
93 heads=$(grep -v '^#' $CTRL_FILE | awk -F '\t' '$2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); }')
94
95 need_build=false
96
97 for h in $heads; do
98         tree=${h%%/*}
99
100         [ -n "$start_from" ] && {
101                 if [ "$tree" = "$start_from" ]; then
102                         start_from=""
103                 else
104                         continue
105                 fi
106         }
107
108         hlog=$(git log -1 --oneline ${h/\/*://}) 2>/dev/null
109         log Merging $h "($hlog)"
110         old_head=$(git rev-parse HEAD)
111         [ -x "../pre-merge/$tree" ] && {
112                 "../pre-merge/$tree" || bash -i || exit
113         }
114         case "$h" in
115         *:*)
116                 do_rebase $h $tree
117                 ;;
118         *)
119                 execute git merge $h || {
120                         echo Merge failed 1>&2
121                         echo $h >>../merge.debug
122                         git diff >>../merge.debug 2>&1
123                         git diff 2>&1 | egrep -q '<<<<<|^\*' && {
124                                 bash -i || exit
125                         }
126                         GIT_EDITOR=: execute git commit -v -a
127                         execute git diff -M --stat --summary 'HEAD^..'
128                 }
129                 ;;
130         esac
131         [ -f "../merge-fixes/$tree" ] && {
132                 for p in $(cat "../merge-fixes/$tree"); do
133                         "$bin_dir/merge_fix" -n "$p" || {
134                                 bash -i || exit
135                         }
136                 done
137         }
138         tab="\t"
139         [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
140         printf "%s$tab%s\n" $tree $(git show-ref --hash "${h/\/*://}") >> $SHA1_FILE
141         [ -x "../pre-build/$tree" ] && {
142                 "../pre-build/$tree" || bash -i || exit
143         }
144         $no_build && continue
145         $need_build || {
146                 # See if we need to build after merging this tree
147                 new_head=$(git rev-parse HEAD)
148                 [ "$old_head" = "$new_head" ] ||
149                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
150                                 need_build=true
151         }
152         $need_build ||
153                 continue
154         do_build=$(grep -v '^#' $CTRL_FILE | awk -F '   ' '$3=="'$tree'" { print $6; }')
155         [ "$do_build" = "yes" ] ||
156                 continue
157         git push -f "$build_host":"$build_dir" master:refs/heads/next || {
158                 echo git push failed 1>&2
159                 bash -i || exit
160         }
161         "$bin_dir/do_build" || {
162                 echo Build failed 1>&2
163                 bash -i || exit
164         }
165         need_build=false
166 done
167
168 exit 0