]> git.ozlabs.org Git - next-scripts/blob - do_merge
allow for restarting the merge from not the first tree
[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                 bash -i || exit
65                 GIT_EDITOR=: execute git commit -v -a
66                 execute git diff -M --stat --summary 'HEAD^..'
67         }
68         $no_build && continue
69         $need_build || {
70                 # See if we need to build after merging this tree
71                 new_head=$(git rev-parse HEAD)
72                 [ "$old_head" = "$new_head" ] ||
73                         need_build=true
74                 $need_build || 
75                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
76                         need_build=true
77         }
78         $need_build ||
79                 continue
80         do_build=$(grep -v '^#' ../real_control | awk -F '      ' '$3=="'$tree'" { print $6; }')
81         [ "$do_build" = "yes" ] ||
82                 continue
83         rsync -avH --exclude .git --delete . "$build_host":"$build_dir"/. || {
84                 echo Rsync failed 1>&2
85                 bash -i || exit
86         }
87         ssh "$build_host" "$build_cmd" || {
88                 echo Build failed 1>&2
89                 bash -i || exit
90         }
91         need_build=false
92 done
93
94 exit 0