#!/bin/bash log_file=../akpm-import.log log() { echo "$@" | tee -a $log_file } execute() { log "$" $@ "$@" 2>&1 | tee -a $log_file [ ${PIPESTATUS[0]} -eq 0 ] || $SHELL -i || exit 1 } 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" log '$' cd ../tmp-akpm cd ../tmp-akpm execute git branch tmp-akpm/current-base sed_exp=' /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 execute git merge --no-edit --no-stat "$dnb" execute git branch tmp-akpm/master-base ;; *) execute git am -s --patch-format=mbox "$mmotm/broken-out/$f" ;; 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