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