]> git.ozlabs.org Git - next-scripts/blobdiff - do_merge
update to_build_host a bit
[next-scripts] / do_merge
index 21cdf118bfe8b9e90dbc0f299d05ec05a5f7549c..d7ecb2f06c373da945bd450740172ec210b4b1d8 100755 (executable)
--- a/do_merge
+++ b/do_merge
 #!/bin/bash
 
-bin_dir="$(dirname $0)"
-
-LOG_FILE="../merge.log"
-SHA1_FILE="../SHA1s"
-
-build_host="ka2"
-build_dir="/scratch/sfr/next"
-[ "$NEXT_BUILD_HOST" ] && build_host="$NEXT_BUILD_HOST"
-[ "$NEXT_BUILD_DIR" ] && build_dir="$NEXT_BUILD_DIR"
-
 no_build=false
 start_from=""
 
-[ "$1" = "-n" ] && {
-       shift
-       no_build=true
-}
-[ "$1" = "-s" ] && {
-       shift
-       start_from="$1"
-       [ -z "$start_from" ] && {
-               echo "-s requires a start tree" 1>&2
+while getopts 'ns:' opt; do
+       case "$opt" in
+       n)
+               no_build=true
+               ;;
+       s)
+               start_from="$OPTARG"
+               ;;
+       *)
                exit 1
-       }
-       shift
-}
-[ -n "$1" ] && {
-       build_host="$1"
-       shift
-}
-[ -n "$1" ] && {
-       build_dir="$1"
-       shift
-}
+               ;;
+       esac
+done
+shift $((OPTIND - 1))
 
-export NEXT_BUILD_HOST="$build_host"
-export NEXT_BUILD_DIR="$build_dir"
+# 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]}"
 }
 
-do_rebase()
+fix_up()
 {
-       rbase=${1#*/}
-       rbase=${rbase%%:*}
-       rtop=${1#*:}
-       rbid=$(git rev-parse $2/$rbase)
-       rtid=$(git rev-parse $2/$rtop)
-       [ "$rbid" = "$rtid" ] && {
-               echo Empty tree
-               return
-       }
-       [ "$(git rev-list HEAD..$2/$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/$2/$rtop:$2/$rtop || {
-               echo Fetch of top failed 1>&2
-               bash -i || exit
-       }
-       execute git fetch --no-tags ../next refs/remotes/$2/$rbase:$2/$rbase || {
-               echo Fetch of base failed 1>&2
-               bash -i || exit
-       }
-       execute git checkout $2/$rtop || {
-               echo Checkout of top failed 1>&2
-               bash -i || exit
-       }
-       execute git rebase --onto master $2/$rbase || {
-               echo Rebase failed 1>&2
-               bash -i || exit
-       }
-       log '$' cd ../next
-       cd ../next
-       execute git pull -f ../rebase-tmp $2/$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
+       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
 }
 
-[ -n "$start_from" ] || {
-       cp /dev/null $LOG_FILE
-       execute date
+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
-
-}
+       printf 'Name\t\tSHA1\n----\t\t----\n' > "$SHA1_FILE"
+fi
 
-heads=$(grep -v '^#' ../etc/control | awk -F '\t' '$2=="quilt" || $2=="git" { printf("%s/%s ", $3, $5); }')
+heads=$(awk -F '\t' '
+       /^#/ { next; }
+       $2=="git" { printf("%s/%s ", $3, $5); }
+       $2=="branch" { printf("branch/%s ", $1); }' "$CTRL_FILE")
 
 need_build=false
 
 for h in $heads; do
        tree=${h%%/*}
 
-       [ -n "$start_from" ] && {
+       if [ -n "$start_from" ]; then
                if [ "$tree" = "$start_from" ]; then
                        start_from=""
                else
                        continue
                fi
-       }
+       fi
 
-       hlog=$(git log -1 --oneline ${h/\/*://}) 2>/dev/null
-       log Merging $h "($hlog)"
+       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)
-       [ -x "../pre-merge/$tree" ] && {
-               "../pre-merge/$tree" || bash -i || exit
-       }
-       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
-                       git diff 2>&1 | egrep -q '<<<<<|^\*' && {
-                               bash -i || exit
-                       }
-                       GIT_EDITOR=: execute git commit -v -a
+       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)"
+       printf -v msg "Merge branch '%s' of %s" "${h#*/}" "$(get_url "$tree")"
+       if ! execute git merge -m "$msg" "$h"; then
+               echo Merge failed 1>&2
+               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^..'
-               }
-               ;;
-       esac
-       [ -f "../merge-fixes/$tree" ] && {
-               for p in $(cat "../merge-fixes/$tree"); do
-                       "$bin_dir/merge_fix" -n "$p" || {
-                               bash -i || exit
-                       }
-               done
-       }
-       tab="\t"
-       [ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
-       printf "%s$tab%s\n" $tree $(git show-ref --hash "${h/\/*://}") >> $SHA1_FILE
-       [ -x "../pre-build/$tree" ] && {
-               "../pre-build/$tree" || bash -i || exit
-       }
-       $no_build && continue
-       $need_build || {
+#              fi
+       fi
+
+       tab=$'\t'
+       if [ "${#tree}" -lt 8 ]; then
+               tab=$'\t\t'
+       fi
+       printf '%s%s%s\n' "$tree" "$tab" "$(git rev-parse "$h^{}")" >> "$SHA1_FILE"
+
+       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
+
+       if $no_build; then
+               continue
+       fi
+
+       if ! $need_build; then
                # 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 ||
+               if [ -n "$(git diff "$old_head"..)" ]; then
+                       need_build=true
+               fi
+       fi
+       if ! $need_build; then
                continue
-       do_build=$(grep -v '^#' ../etc/control | awk -F '       ' '$3=="'$tree'" { print $6; }')
-       [ "$do_build" = "yes" ] ||
+       fi
+
+       if [ "$(get_build_flag "$tree")" != "yes" ]; then
                continue
-       git push -f "$build_host":"$build_dir" master:refs/heads/next || {
-               echo git push failed 1>&2
-               bash -i || exit
-       }
-       "$bin_dir/do_build" || {
-               echo Build failed 1>&2
-               bash -i || exit
-       }
+       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