X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=update_trees;h=b09a01aa392458fe2db37a74d58853a2ab359471;hb=53b2cfd4081729a70705c19e4c9723dab415f1b7;hp=a1925e6c7047ff557ec53bee7b4e3808b7a9eb6f;hpb=f7997575c4d9c7fa7cee4e11c97d80a10a08cc00;p=next-scripts diff --git a/update_trees b/update_trees index a1925e6..b09a01a 100755 --- a/update_trees +++ b/update_trees @@ -1,85 +1,105 @@ #!/bin/bash -set -o pipefail +. "$(dirname $0)/common.sh" -cp /dev/null ../quilt-import.log +log_file=../quilt-import.log +#cp /dev/null $log_file log() { - echo "$@" | tee -a ../quilt-import.log + echo "$@" | tee -a $log_file } execute() { log "$" $@ - "$@" 2>&1 | tee -a ../quilt-import.log + "$@" 2>&1 | tee -a $log_file + [ ${PIPESTATUS[0]} -eq 0 ] || $SHELL -i || exit 1 } -quilters=$(grep -v '^#' ../real_control | awk -F ' ' '$2=="quilt" { print $3; }') +cpwd=$(pwd) + +quilters=$(awk -F '\t' '/^[^#]/ && $2=="quilt" { print $3; }' "$CTRL_FILE") for name in $quilters; do + sfile="../quilt/$name/series" - base=$(sed -n 's/^[# ]*NEXT_BASE[ ]*\(.*\)[ ]*$/\1/p' "$sfile") + base=$(sed -n 's/^#[ \t]*NEXT[-_]BASE[ \t]*\([^ \t]*\)[ \t]*$/\1/p' "$sfile") if [ -n "$base" ]; then - base=$(grep -v '^#' ../real_control | awk -F ' ' '$3=="'"$base"'" { if ($2=="quilt") printf("quilt/%s", "'"$base"'"); else printf("%s/%s", "'"$base"'", $5); }') + nbase=$(awk -F '\t' '/^[^#]/ && $3=="'"$base"'" { printf("%s/%s", "'"$base"'", $5); }' "$CTRL_FILE") + [ -n "$nbase" ] && base="$nbase" else - base=$(sed -n 's/^[# ]*BASE[ ]*\(.*\)[ ]*$/\1/p' "$sfile") + base=$(sed -n 's/^#[ \t]*BASE[ \t]*\(.*\)[ \t]*$/\1/p' "$sfile") + [ -n "$base" ] || { + # for stgit + base=$(sed '1{s/^#.*GIT commit \(.*\)$/\1/;q}' "$sfile") + [ -n "$base" ] || + base="origin/master" + } fi rbase="$base" case "$base" in - *-git[0-9]*) rbase=$(wget -q -O - "http://www.kernel.org/pub/linux/kernel/v2.6/snapshots/patch-${base}.id") + *-git[0-9]*) rbase=$("$bin_dir/get_gitid" "${base}") ;; - commit*) rbase=$(expr "$base" : "commit[ ]*\(.*\)") + commit*) rbase=${base##commit*[[:space:]]} ;; [0-9]*.*) rbase="v$base" ;; esac log "Importing $name based on $base" - git rev-list -n 1 "$rbase" -- >/dev/null 2>&1 || { + rbase_sha1=$(git rev-parse --verify "$rbase^{commit}") || { log "Unknown BASE" continue } - grep -q NEXT_PATCHES "$sfile" && { - mv -f "$sfile" "$sfile.orig" - do_echo=: - while read line; do - case $line in - *NEXT_PATCHES_START*) do_echo=echo - ;; - *NEXT_PATCHES_END*) do_echo=: - ;; - esac - $do_echo $line - done <"$sfile.orig" >"$sfile" + + # don't bother importing things that haven't changed + mb=$(git merge-base "$rbase_sha1" "$name/master") + change_size=$(cd ../quilt;git diff last_merge.. -- "$name/" | wc -c) + [ "$mb" = "$rbase_sha1" ] && [ $change_size -eq 0 ] && { + log "Unchanged quilt series $name" + continue } - mv -f "$sfile" "$sfile.tmp" - sed -e '/^[ ]*$/d' -e '^[ ]*#/d' <"$sfile.tmp" >"$sfile" - rm -f "$sfile.tmp" - [ -s "$sfile" ] || { + sed_exp='s/[ \t]*#.*$//;/^[ \t]*$/!p' + grep -q NEXT_PATCHES "$sfile" && + sed_exp='/NEXT_PATCHES_START/,/NEXT_PATCHES_END/{'"$sed_exp"';}' + patches=$(sed -n "$sed_exp" "$sfile") + + git show-ref --quiet --verify "refs/heads/$name/master" || + execute git branch "$name/master" "$rbase_sha1" + + [ -n "$patches" ] || { log " quilt series is empty" - [ -f "$sfile.orig" ] && - mv -f "$sfile.orig" "$sfile" + execute git branch -f "$name/master" "$rbase_sha1" continue } - execute git branch -D "quilt/$name" - execute git checkout -b "quilt/$name" "$rbase" || sh -i || { - [ -f "$sfile.orig" ] && - mv -f "$sfile.orig" "$sfile" - exit 1 - } - author=$(grep -v '^#' ../real_control | awk -F ' ' '$3=="'"$name"'" { printf("%s", $1); }' | sed 's/,.*$//') - execute git quiltimport --author "$author" --patches "../quilt/$name" || sh -i || { - [ -f "$sfile.orig" ] && - mv -f "$sfile.orig" "$sfile" - exit 1 - } + [ -d "../quilt-tmp" ] || + execute git clone -s -l -n -q . ../quilt-tmp + + log '$' cd ../quilt-tmp + cd ../quilt-tmp + execute git reset --hard "$rbase_sha1" - [ -f "$sfile.orig" ] && - mv -f "$sfile.orig" "$sfile" + for f in $patches; do + old_head=$(git rev-parse --verify HEAD) + execute git am -s --patch-format=mbox "../quilt/$name/$f" + new_head=$(git rev-parse --verify HEAD) + [ "$new_head" = "$old_head" ] && { + echo "Tree unchanged, please check ..." + bash -i || exit + } + done + + log '$' cd $cpwd + cd $cpwd + + execute git fetch -f ../quilt-tmp master:"$name/master" done -git checkout master +[ -d "../quilt-tmp" ] && + rm -rf ../quilt-tmp + +( cd ../quilt; git branch -f last_merge HEAD ) exit 0