]> git.ozlabs.org Git - next-scripts/blobdiff - do_merge
change the order of arguments to send_email
[next-scripts] / do_merge
index b5ed78be51ffa361710722e71c39eb8a44bfe200..ec55df978936098261efb35508a21f6bd13bb067 100755 (executable)
--- a/do_merge
+++ b/do_merge
 #!/bin/bash
 
-LOG_FILE="../merge.log"
-build_host="sprygo"
-build_dir="/scatch/sfr/next"
-build_cmd="bin/build_next"
-
 no_build=false
-[ "$1" = "-n" ] && {
-       shift
-       no_build=true
-}
-[ -n "$1" ] && build_host="$1"
+start_from=""
 
-cp /dev/null $LOG_FILE
+while getopts 'ns:' opt; do
+       case "$opt" in
+       n)
+               no_build=true
+               ;;
+       s)
+               start_from="$OPTARG"
+               ;;
+       *)
+               exit 1
+               ;;
+       esac
+done
+shift $((OPTIND - 1))
+
+# shellcheck source=common.sh
+source "$(dirname "$0")/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]}"
+}
+
+fix_up()
+{
+       if [ -n "$1" ]; then
+               linux-next-notify "$1"
+       fi
+       if [ -n "$2" ]; then
+               printf '%s\n' "$2" 1>&2
+       fi
+       if ! bash -i; then
+               exit
+       fi
 }
 
-execute git checkout master
-execute git reset --hard stable
+if [ -z "$start_from" ]; then
+       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"
+fi
+
+heads=$(awk -F '\t' '
+       /^#/ { next; }
+       $2=="git" { printf("%s/%s ", $3, $5); }
+       $2=="branch" { printf("branch/%s ", $1); }' "$CTRL_FILE")
 
-heads=$(grep -v '^#' ../real_control | awk -F '        ' '$2=="quilt" { printf("quilt/%s ", $3); } $2=="git" { printf("%s/%s ", $3, $5); }')
+need_build=false
 
 for h in $heads; do
-       log Merging $h
+       tree=${h%%/*}
+
+       if [ -n "$start_from" ]; then
+               if [ "$tree" = "$start_from" ]; then
+                       start_from=""
+               else
+                       continue
+               fi
+       fi
+
+       if [ "$tree" = "branch" ]; then
+               git branch -f "${h#branch/}"
+               linux-next-notify "update branch ${h#branch/}"
+               continue
+       fi
+
+       hlog=$(git log -1 --oneline "$h") 2>/dev/null
        old_head=$(git rev-parse HEAD)
-       execute git merge $h || {
+       if [ -f "../pre-merge/$tree" ]; then
+               while read -r p <&7; do
+                       if ! "$bin_dir/do_patch" -n "$p"; then
+                               fix_up "premerge patch failed"
+                       fi 7<&-
+               done 7<"../pre-merge/$tree"
+       fi
+       log Merging "$h" "($hlog)"
+       if ! execute git merge "$h"; then
                echo Merge failed 1>&2
-               bash -i || exit
-               log '$' git commit -v -a
-               git commit -v -a
-               execute git diff -M --stat --summary 'HEAD^..'
-       }
-       new_head=$(git rev-parse HEAD)
-       [ "$old_head" = "$new_head" ] && continue
-       $no_build && continue
-       rsync -avH --exclude .git --delete . "$build_host":"$build_dir"/. || {
-               echo Rsync failed 1>&2
-               bash -i || exit
-       }
-       ssh "$build_host" "$build_cmd" || {
-               echo Build failed 1>&2
-               bash -i || exit
-       }
+               echo "$h" >>../merge.debug
+               git diff >>../merge.debug 2>&1
+
+               check_unmerged_files "$tree"
+
+               if git diff 2>&1 | grep -E -q '<<<<<|^\*'; then
+                       if [ -f "../merge-fixes/$tree" ]; then
+                               echo "Merge fixes exist for this tree:"
+                               cat "../merge-fixes/$tree"
+                       fi
+                       fix_up "new conflict found merging $tree"
+               fi
+#              if [ "$(git status --porcelain)" ]; then
+                       if ! execute git commit --no-edit -v -a; then
+                               fix_up "next commit failed for $tree"
+                       fi
+                       execute git diff -M --stat --summary 'HEAD^..'
+#              fi
+       fi
+       if [ -f "../merge-fixes/$tree" ]; then
+               while read -r p <&7; do
+                       if ! "$bin_dir/merge_fix" -n "$p"; then
+                               fix_up "merge fix failed for $tree"
+                       fi 7<&-
+               done 7<"../merge-fixes/$tree"
+       fi
+
+       tab=$'\t'
+       if [ "${#tree}" -le 8 ]; then
+               tab=$'\t\t'
+       fi
+       printf '%s%s%s\n' "$tree" "$tab" "$(git rev-parse "$h^{}")" >> "$SHA1_FILE"
+
+       if $no_build; then
+               continue
+       fi
+
+       if ! $need_build; then
+               # See if we need to build after merging this tree
+               if [ -n "$(git diff "$old_head"..)" ]; then
+                       need_build=true
+               fi
+       fi
+       if ! $need_build; then
+               continue
+       fi
+
+       do_build=$(awk -F '\t' '/^[^#]/ && $3=="'"$tree"'" { print $6; }' "$CTRL_FILE")
+       if [ "$do_build" != "yes" ]; then
+               continue
+       fi
+
+       repo="${build_host:+$build_host:}${build_dir}"
+       if ! git push -f "$repo" master:refs/heads/next; then
+               fix_up "push failed for $tree" "git push failed"
+       fi
+
+       if [ -x "../pre-build/$tree" ] &&
+          ! "../pre-build/$tree"; then
+               fix_up "pre-build script failed for $tree" "Prebuild script failed"
+       fi
+       if ! "$bin_dir/do_build" "$tree"; then
+               fix_up "build failed for $tree" "Build failed"
+       fi
+
+       need_build=false
 done
 
 exit 0