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