File update_git.sh of Package qemu-testsuite.openSUSE_Leap_42.1_Update

#!/bin/bash -e
#
# Instead of a quilt workflow, we use a git tree that contains
# all the commits on top of a stable tarball.
#
# When updating this package, just either update the git tree
# below (use rebase!) or change the tree path and use your own
#
# That way we can easily rebase against the next stable release
# when it comes.

GIT_TREE=https://gitlab.suse.de/virtualization/qemu.git
GIT_LOCAL_TREE=~/git/qemu
GIT_UPSTREAM_TREE=git://git.qemu-project.org/qemu.git
GIT_BRANCH=SLE12-SP1
GIT_UPSTREAM_TAG=v2.3.1
GIT_DIR=/dev/shm/qemu-sle12-git-dir
CMP_DIR=/dev/shm/qemu-sle12-cmp-dir

rm -rf $GIT_DIR
rm -rf $CMP_DIR

if [ -d "$GIT_LOCAL_TREE" ]; then
    echo "Processing $GIT_BRANCH branch of local git tree, using tag:" \
         "$GIT_UPSTREAM_TAG"
    if ! (cd $GIT_LOCAL_TREE && git show-branch $GIT_BRANCH &>/dev/null); then
        echo "Error: Branch $GIT_BRANCH not found - please create a remote" \
             "tracking branch of origin/$GIT_BRANCH"
        exit
    fi
    git clone -lsn $GIT_LOCAL_TREE $GIT_DIR -b $GIT_BRANCH
    if ! (cd $GIT_LOCAL_TREE && git show-ref --tags -q $GIT_UPSTREAM_TAG && \
          git remote show upstream &>/dev/null); then
        echo "Remote for upstream git tree (or tag) not found. Add remote" \
             "named upstream for git://git.qemu.org/qemu.git and update"
        (cd $GIT_DIR && git remote add upstream $GIT_UPSTREAM_TREE)
    	(cd $GIT_DIR && git fetch -q upstream +$GIT_UPSTREAM_TAG)
        BASE=FETCH_HEAD
   else
        BASE=$GIT_UPSTREAM_TAG
   fi
else
    echo "Processing $GIT_BRANCH branch of remote git tree, using tag:" \
         "$GIT_UPSTREAM_TAG"
    echo "(For much faster processing, create a local git tree at $GIT_LOCAL_TREE)"
    git init -q $GIT_DIR
    (cd $GIT_DIR && git config --global core.compression 0)
    (cd $GIT_DIR && git remote add origin $GIT_TREE)
    (cd $GIT_DIR && git fetch -q origin $GIT_BRANCH)
    (cd $GIT_DIR && git remote add upstream $GIT_UPSTREAM_TREE)
    (cd $GIT_DIR && git fetch -q upstream +$GIT_UPSTREAM_TAG)
    BASE=FETCH_HEAD
fi
(cd $GIT_DIR && git format-patch -N --start-number=1 $BASE..origin/$GIT_BRANCH --suffix= -o $CMP_DIR >/dev/null)
QEMU_VERSION=`(cd $GIT_DIR && git show origin/$GIT_BRANCH:VERSION)`
echo "QEMU version: $QEMU_VERSION"

rm -rf $GIT_DIR

(
    CHANGED_COUNT=0
    UNCHANGED_COUNT=0
    DELETED_COUNT=0
    ADDED_COUNT=0

    shopt -s nullglob

# Process patches to eliminate useless differences: limit file names to 40 chars
# before extension and remove git signature. ('28' below gets us past dir prefix)
    for i in $CMP_DIR/*; do
        if grep -q "GIT binary patch" $i; then
            echo "WARNING: Removing binary patch ${i:28:40}.patch"
        else
            head -n -3 $i > $CMP_DIR/${i:28:40}.patch
        fi
        rm $i
    done

    for i in 0???-*.patch; do
        if [ -e $CMP_DIR/$i ]; then
            if cmp -s $CMP_DIR/$i $i; then
                rm $CMP_DIR/$i
                let UNCHANGED_COUNT+=1
            else
                mv $CMP_DIR/$i .
                let CHANGED_COUNT+=1
            fi
        else
            osc rm --force $i
            let DELETED_COUNT+=1
            echo "  ${i##*/}" >> qemu.changes.deleted
        fi
    done

    for i in $CMP_DIR/*; do
        mv $i .
        osc add ${i##*/}
        let ADDED_COUNT+=1
        echo "  ${i##*/}" >> qemu.changes.added
    done

    for package in qemu qemu-linux-user; do
        while IFS= read -r line; do
            if [ "$line" = "PATCH_FILES" ]; then
                for i in 0???-*.patch; do
                    NUM=${i%%-*}
                    echo -e "Patch$NUM:      $i"
                done
            elif [ "$line" = "PATCH_EXEC" ]; then
                for i in 0???-*.patch; do
                    NUM=${i%%-*}
                    echo "%patch$NUM -p1"
                done
            elif [ "$line" = "QEMU_VERSION" ]; then
                echo "Version:        $QEMU_VERSION"
            elif [[ "$line" =~ ^Source: ]]; then
                QEMU_TARBALL=qemu-`echo "$line" | cut -d '-' -f 2-`
                VERSION_FILE=${QEMU_TARBALL%.tar.bz2}/roms/seabios/.version
                SEABIOS_VERSION=`tar jxfO "$QEMU_TARBALL" "$VERSION_FILE"`
                SEABIOS_VERSION=`echo $SEABIOS_VERSION | cut -d '-' -f 2`
                echo "$line"
            elif [ "$line" = "SEABIOS_VERSION" ]; then
                echo "Version:        $SEABIOS_VERSION"
            else
                echo "$line"
            fi
        done < $package.spec.in > $CMP_DIR/$package.spec
        if cmp -s $package.spec $CMP_DIR/$package.spec; then
            echo "$package.spec unchanged"
        else
            mv $CMP_DIR/$package.spec $package.spec
            echo "$package.spec regenerated"
        fi

        # All deleted and added patches are to be mentioned in change log
        if [ -e qemu.changes.deleted ] || [ -e qemu.changes.added ]; then
            echo "Patch queue updated from ${GIT_TREE} ${GIT_BRANCH}" > $package.changes.proposed
        fi
        if [ -e qemu.changes.deleted ]; then
            echo "* Patches dropped:" >> $package.changes.proposed
            cat qemu.changes.deleted  >> $package.changes.proposed
        fi
        if [ -e qemu.changes.added ]; then
            echo "* Patches added:" >> $package.changes.proposed
            cat qemu.changes.added  >> $package.changes.proposed
        fi
        if [ -e $package.changes.proposed ]; then
            osc vc --file=$package.changes.proposed $package
            rm -f $package.changes.proposed
        fi
    done
    if [ -e qemu.changes.deleted ]; then
        rm -f qemu.changes.deleted
    fi
    if [ -e qemu.changes.added ]; then
        rm -f qemu.changes.added
    fi
    echo "git patch summary"
    echo "  unchanged: $UNCHANGED_COUNT"
    echo "    changed: $CHANGED_COUNT"
    echo "    deleted: $DELETED_COUNT"
    echo "      added: $ADDED_COUNT"
)

rm -rf $CMP_DIR

sed -e 's|^\(Name:.*qemu\)|\1-testsuite|' < qemu.spec > qemu-testsuite.spec
osc service localrun format_spec_file

/bin/sh pre_checkin.sh -q

echo "Please remember to run pre_checkin.sh after modifying qemu.changes."
openSUSE Build Service is sponsored by