]> git.ozlabs.org Git - next-scripts/blob - do_merge
do_merge: updates
[next-scripts] / do_merge
1 #!/bin/bash
2
3 LOG_FILE="../merge.log"
4 build_host="sprygo"
5 build_dir="/scratch/sfr/next"
6 build_cmd="bin/build_next"
7
8 no_build=false
9 start_from=""
10
11 [ "$1" = "-n" ] && {
12         shift
13         no_build=true
14 }
15 [ "$1" = "-s" ] && {
16         shift
17         start_from="$1"
18         [ -z "$start_from" ] && {
19                 echo "-s requires a start tree" 1>&2
20                 exit 1
21         }
22         shift
23 }
24 [ -n "$1" ] && build_host="$1"
25
26 log()
27 {
28         echo "$@" | tee -a $LOG_FILE
29 }
30
31 execute()
32 {
33         log "$" $@
34         $@ 2>&1 | tee -a $LOG_FILE
35         return ${PIPESTATUS[0]}
36 }
37
38 [ -n "$start_from" ] || {
39         cp /dev/null $LOG_FILE
40         execute git checkout master
41         execute git reset --hard stable
42 }
43
44 heads=$(grep -v '^#' ../real_control | awk -F ' ' '$2=="quilt" { printf("quilt/%s ", $3); } $2=="git" { printf("%s/%s ", $3, $5); }')
45
46 need_build=false
47
48 for h in $heads; do
49         tree=${h%%/*}
50         [ "$tree" == "quilt" ] && tree=${h#quilt/}
51
52         [ -n "$start_from" ] && {
53                 if [ "$tree" = "$start_from" ]; then
54                         start_from=""
55                 else
56                         continue
57                 fi
58         }
59
60         log Merging $h
61         old_head=$(git rev-parse HEAD)
62         execute git merge $h || {
63                 echo Merge failed 1>&2
64                 echo $h >>../merge.debug
65                 git diff >>../merge.debug 2>&1
66                 git diff 2>&1 | egrep -q '<<<<<|^\*' && {
67                         bash -i || exit
68                 }
69                 GIT_EDITOR=: execute git commit -v -a
70                 execute git diff -M --stat --summary 'HEAD^..'
71         }
72         [ -f "../merge-fixes/$tree" ] && {
73                 for p in $(cat "../merge-fixes/$tree"); do
74                         ../tools/merge_fix -n "$p" || {
75                                 bash -i || exit
76                         }
77                 done
78         }
79         $no_build && continue
80         $need_build || {
81                 # See if we need to build after merging this tree
82                 new_head=$(git rev-parse HEAD)
83                 [ "$old_head" = "$new_head" ] ||
84                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
85                                 need_build=true
86         }
87         $need_build ||
88                 continue
89         do_build=$(grep -v '^#' ../real_control | awk -F '      ' '$3=="'$tree'" { print $6; }')
90         [ "$do_build" = "yes" ] ||
91                 continue
92         rsync -avH --exclude .git --delete . "$build_host":"$build_dir"/. || {
93                 echo Rsync failed 1>&2
94                 bash -i || exit
95         }
96         ssh "$build_host" "$build_cmd" || {
97                 echo Build failed 1>&2
98                 bash -i || exit
99         }
100         need_build=false
101 done
102
103 exit 0