#!/bin/bash export LOG_FILE=../akpm-import.log # shellcheck source=./common.sh . "$(dirname "$0")/common.sh" '' log() { echo "$@" | tee -a $LOG_FILE } execute() { log '$' "$@" "$@" 2>&1 | tee -a $LOG_FILE return ${PIPESTATUS[0]} } mmotm="../mmotm" sfile="$mmotm/series" cpwd=$(pwd) [ -f "$mmotm/broken-out/origin.patch" ] && base=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/origin.patch") [ "$base" ] || { base=$(tail -n 1 "$mmotm/.DATE") base=${base#v} base="v${base}" } nbase=$(sed -n '1s/^GIT *\([^ ]*\).*$/\1/p' "$mmotm/broken-out/linux-next.patch") git rev-parse --verify "$base" >/dev/null || { log "Unknown origin BASE $base" exit 1 } git rev-parse --verify "$nbase" >/dev/null || { log "Unknown linux-next BASE $nbase" exit 1 } db=$(git describe "$base") dnb=$(git describe --contains "$nbase") log "Importing akpm based on $db/$dnb" [ -d "../tmp-akpm" ] && { log "akpm import directory already exists" exit 1 } execute git worktree add -b tmp-akpm/master ../tmp-akpm "$db" || $SHELL -i || exit log '$' cd ../tmp-akpm cd ../tmp-akpm execute git branch tmp-akpm/current-base || $SHELL -i || exit sed_exp=' s/\r$// /NEXT_PATCHES_START/,/NEXT_PATCHES_END/{ s/[ \t]*#.*$// /^[ \t]*$/!p } /^linux-next.patch/p' patches=$(sed -n "$sed_exp" "$sfile") for f in $patches; do case "$f" in origin.patch) ;; linux-next.patch) execute git branch tmp-akpm/current || $SHELL -i || exit execute git merge --no-edit --no-stat "$dnb" || { check_unmerged_files akpm-current git diff 2>&1 | grep -E -q '<<<<<|^\*' && { $SHELL -i || exit } GIT_EDITOR=: execute git commit -v -a } [ -f "../merge-fixes/akpm-current" ] && { for p in $(cat "../merge-fixes/akpm-current"); do $(dirname $0)/merge_fix -n "$p" || $SHELL -i || exit done } execute git branch tmp-akpm/master-base || $SHELL -i || exit ;; *) execute git am -s --patch-format=mbox "$mmotm/broken-out/$f" || $SHELL -i || exit ;; esac done log '$' cd $cpwd cd $cpwd execute rm -rf ../tmp-akpm execute git worktree prune for i in akpm/current akpm/current-base akpm/master akpm/master-base; do execute git branch -f $i tmp-$i execute git branch -D tmp-$i done exit 0