]> git.ozlabs.org Git - next-scripts/blobdiff - do_merge
use firejail for builds
[next-scripts] / do_merge
index 44b90d7f65ec86fff754377b1e0d52d1d268478c..d1c52e71dea8bf4ba672b21ed1cea5d416f0e778 100755 (executable)
--- a/do_merge
+++ b/do_merge
 #!/bin/bash
 
-LOG_FILE="../merge.log"
-build_host="sprygo"
-build_dir="/scratch/sfr/next"
-build_cmd="bin/build_next"
-
 no_build=false
+start_from=""
+
 [ "$1" = "-n" ] && {
        shift
        no_build=true
 }
-[ -n "$1" ] && build_host="$1"
+[ "$1" = "-s" ] && {
+       shift
+       start_from="$1"
+       [ -z "$start_from" ] && {
+               echo "-s requires a start tree" 1>&2
+               exit 1
+       }
+       shift
+}
 
-cp /dev/null $LOG_FILE
+tool_dir=$(dirname "$0")
+. "$tool_dir/common.sh"
 
 log()
 {
-       echo "$@" | tee -a $LOG_FILE
+       echo "$@" | tee -a "$LOG_FILE"
 }
 
 execute()
 {
-       log "$" $@
-       $@ 2>&1 | tee -a $LOG_FILE
-       return ${PIPESTATUS[0]}
+       log "$" "$@"
+       "$@" 2>&1 | tee -a "$LOG_FILE"
+       return "${PIPESTATUS[0]}"
+}
+
+do_rebase()
+{
+       rbase=${1#*/}
+       rbase="$2/${rbase%%:*}"
+       rtop="$2/${1#*:}"
+       rbid=$(git rev-parse "$rbase")
+       rtid=$(git rev-parse "$rtop")
+       [ "$rbid" = "$rtid" ] && {
+               echo Empty tree
+               return
+       }
+       [ "$(git rev-list HEAD..$rtop)" ] || {
+               echo Already merged
+               return
+       }
+       execute git clone -s -l -n -q . ../rebase-tmp || {
+               echo Clone failed 1>&2
+               bash -i || exit
+       }
+       log '$' cd ../rebase-tmp
+       cd ../rebase-tmp
+       execute git fetch --no-tags ../next "refs/remotes/$rtop:$rtop" || {
+               echo Fetch of top failed 1>&2
+               bash -i || exit
+       }
+       execute git fetch --no-tags ../next "refs/remotes/$rbase:$rbase" || {
+               echo Fetch of base failed 1>&2
+               bash -i || exit
+       }
+       execute git checkout "$rtop" || {
+               echo Checkout of top failed 1>&2
+               bash -i || exit
+       }
+       execute git rebase --onto master "$rbase" || {
+               echo Rebase failed 1>&2
+               bash -i || exit
+       }
+       log '$' cd ../next
+       cd ../next
+       execute git pull -f ../rebase-tmp "$rtop" || {
+               echo Pull failed 1>&2
+               echo "$h" >>../merge.debug
+               git diff >>../merge.debug 2>&1
+               git diff 2>&1 | egrep -q '<<<<<|^\*' && {
+                       bash -i || exit
+               }
+       }
+       execute rm -rf ../rebase-tmp
 }
 
-execute git checkout master
-execute git reset --hard stable
+[ -n "$start_from" ] || {
+       cp /dev/null "$LOG_FILE"
+       execute date -R
+       execute git checkout master
+       execute git reset --hard stable
+       printf 'Name\t\tSHA1\n----\t\t----\n' > "$SHA1_FILE"
 
-heads=$(grep -v '^#' ../real_control | awk -F '        ' '$2=="quilt" { printf("quilt/%s ", $3); } $2=="git" { printf("%s/%s ", $3, $5); }')
+}
+
+heads=$(grep -v '^#' "$CTRL_FILE" | awk -F '\t' '$2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); } $2=="branch" { printf("branch/%s ", $1); }')
+
+need_build=false
 
 for h in $heads; do
-       log Merging $h
+       tree=${h%%/*}
+
+       [ -n "$start_from" ] && {
+               if [ "$tree" = "$start_from" ]; then
+                       start_from=""
+               else
+                       continue
+               fi
+       }
+
+       [ "$tree" = "branch" ] && {
+               git branch -f "${h#branch/}"
+               continue
+       }
+
+       hlog=$(git log -1 --oneline "${h/\/*://}") 2>/dev/null
        old_head=$(git rev-parse HEAD)
-       execute git merge $h || {
-               echo Merge failed 1>&2
-               bash -i || exit
-               GIT_EDITOR=: execute git commit -v -a
-               execute git diff -M --stat --summary 'HEAD^..'
+       [ -f "../pre-merge/$tree" ] && {
+               for p in $(cat "../pre-merge/$tree"); do
+                       "$bin_dir/do_patch" -n "$p" || {
+                               notify-send -u critical -t 0 "premerge patch failed"
+                               bash -i || exit
+                       }
+               done
+       }
+       log Merging "$h" "($hlog)"
+       case "$h" in
+       *:*)
+               do_rebase "$h" "$tree"
+               ;;
+       *)
+               execute git merge "$h" || {
+                       echo Merge failed 1>&2
+                       echo "$h" >>../merge.debug
+                       git diff >>../merge.debug 2>&1
+                       um_files=$(git diff 2>&1 | sed -n 's/^\* Unmerged path //p')
+                       [ "$um_files" ] && [ -f "../merge-files/$tree" ] && {
+                               rm_files=$(grep -F "$um_files" "../merge-files/$tree")
+                               [ "$rm_files" ] &&
+                                       "$bin_dir/do_rm" $rm_files
+                       }
+                       git diff 2>&1 | egrep -q '<<<<<|^\*' && {
+                               notify-send -t 0 -u critical "linux-next new conflict found merging $tree!"
+                               pushover "linux-next new conflict found merging $tree!"
+                               if [ -f "../merge-fixes/$tree" ]; then
+                                       echo "Merge fixes exist for this tree:"
+                                       cat "../merge-fixes/$tree"
+                               fi
+                               bash -i || exit
+                       }
+#                      [ "$(git status --porcelain)" ] && {
+                               GIT_EDITOR=: execute git commit -v -a || {
+                                       notify-send -t 0 -u critical "linux-next commit failed for $tree!"
+                                       pushover "linux-next commit failed for $tree!"
+                                       bash -i || exit
+                               }
+                               execute git diff -M --stat --summary 'HEAD^..'
+#                      }
+               }
+               ;;
+       esac
+       [ -f "../merge-fixes/$tree" ] && {
+               for p in $(cat "../merge-fixes/$tree"); do
+                       "$bin_dir/merge_fix" -n "$p" || {
+                               notify-send -t 0 -u critical "linux-next merge fix failed for $tree!"
+                               pushover "linux-next merge fix failed for $tree!"
+                               bash -i || exit
+                       }
+               done
        }
-       new_head=$(git rev-parse HEAD)
-       [ "$old_head" = "$new_head" ] && continue
+       tab="\t"
+       [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
+       printf "%s$tab%s\n" $tree $(git rev-parse "${h/\/*://}^{}") >> $SHA1_FILE
        $no_build && continue
-       rsync -avH --exclude .git --delete . "$build_host":"$build_dir"/. || {
-               echo Rsync failed 1>&2
+       $need_build || {
+               # See if we need to build after merging this tree
+               new_head=$(git rev-parse HEAD)
+               [ "$old_head" = "$new_head" ] ||
+                       [ "$(git diff ${old_head}.. | wc -c)" -eq 0 ] ||
+                               need_build=true
+       }
+       $need_build ||
+               continue
+       do_build=$(grep -v '^#' $CTRL_FILE | awk -F '   ' '$3=="'$tree'" { print $6; }')
+       [ "$do_build" = "yes" ] ||
+               continue
+       git push -f "${build_host}${build_host:+:}${build_dir}" master:refs/heads/next || {
+               echo git push failed 1>&2
+               notify-send -t 0 -u critical "linux-next push failed for $tree!"
+               pushover "linux-next push failed for $tree!"
                bash -i || exit
        }
-       ssh "$build_host" "$build_cmd" || {
+       [ -x "../pre-build/$tree" ] && {
+               "../pre-build/$tree" || {
+                       echo Prebuild script failed 1>&2
+                       notify-send -t 0 -u critical "linux-next pre-build script failed for $tree!"
+                       pushover "linux-next pre-build script failed for $tree!"
+                       bash -i || exit
+               }
+       }
+       "$bin_dir/do_build" "$tree" || {
                echo Build failed 1>&2
+               notify-send -t 0 -u critical "linux-next build failed for $tree!"
+               pushover "linux-next build failed for $tree!"
                bash -i || exit
        }
+
+       notify-send -u normal "Merge and build of $tree successful"
+
+       need_build=false
 done
 
 exit 0