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