]> git.ozlabs.org Git - next-scripts/blob - do_merge
do_merge: make sure we generate a merge commit for each nonempty tree
[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         case "$h" in
112         *:*)
113                 do_rebase $h $tree
114                 ;;
115         *)
116                 execute git merge --no-ff $h || {
117                         echo Merge failed 1>&2
118                         echo $h >>../merge.debug
119                         git diff >>../merge.debug 2>&1
120                         git diff 2>&1 | egrep -q '<<<<<|^\*' && {
121                                 bash -i || exit
122                         }
123                         GIT_EDITOR=: execute git commit -v -a
124                         execute git diff -M --stat --summary 'HEAD^..'
125                 }
126                 ;;
127         esac
128         [ -f "../merge-fixes/$tree" ] && {
129                 for p in $(cat "../merge-fixes/$tree"); do
130                         "$bin_dir/merge_fix" -n "$p" || {
131                                 bash -i || exit
132                         }
133                 done
134         }
135         tab="\t"
136         [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
137         printf "%s$tab%s\n" $tree $(git show-ref --hash "${h/\/*://}") >> $SHA1_FILE
138         $no_build && continue
139         $need_build || {
140                 # See if we need to build after merging this tree
141                 new_head=$(git rev-parse HEAD)
142                 [ "$old_head" = "$new_head" ] ||
143                         [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
144                                 need_build=true
145         }
146         $need_build ||
147                 continue
148         do_build=$(grep -v '^#' $CTRL_FILE | awk -F '   ' '$3=="'$tree'" { print $6; }')
149         [ "$do_build" = "yes" ] ||
150                 continue
151         git push -f "$build_host":"$build_dir" master:refs/heads/next || {
152                 echo git push failed 1>&2
153                 bash -i || exit
154         }
155         "$bin_dir/do_build" || {
156                 echo Build failed 1>&2
157                 bash -i || exit
158         }
159         need_build=false
160 done
161
162 exit 0