Blame scripts/backport-support.sh

Packit 6c4009
#!/bin/bash
Packit 6c4009
# Create a patch which backports the support/ subdirectory.
Packit 6c4009
# Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
# This script does not backport the Makefile tweaks outside the
Packit 6c4009
# support/ directory (which need to be backported separately), or the
Packit 6c4009
# changes to test-skeleton.c (which should not be backported).
Packit 6c4009
Packit 6c4009
set -e
Packit 6c4009
Packit 6c4009
export LC_ALL=C
Packit 6c4009
export GIT_CONFIG=/dev/null
Packit 6c4009
export GTT_CONFIG_NOSYSTEM=0
Packit 6c4009
export GIT_PAGER=
Packit 6c4009
Packit 6c4009
usage () {
Packit 6c4009
    cat >&2 <
Packit 6c4009
usage: $0 {patch|commit}
Packit 6c4009
EOF
Packit 6c4009
    exit 1
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
if test $# -ne 1 ; then
Packit 6c4009
    usage
Packit 6c4009
fi
Packit 6c4009
Packit 6c4009
command="$1"
Packit 6c4009
Packit 6c4009
case "$command" in
Packit 6c4009
    patch|commit)
Packit 6c4009
    ;;
Packit 6c4009
    *)
Packit 6c4009
	usage
Packit 6c4009
	;;
Packit 6c4009
esac
Packit 6c4009
Packit 6c4009
# The upstream branch to work on.
Packit 6c4009
branch=origin/master
Packit 6c4009
Packit 6c4009
# The commit which added the support/ directory.
Packit 6c4009
initial_commit=c23de0aacbeaa7a091609b35764bed931475a16d
Packit 6c4009
Packit 6c4009
# We backport the support directory and this script.  Directories need
Packit 6c4009
# to end in a /.
Packit 6c4009
patch_targets="support/ scripts/backport-support.sh"
Packit 6c4009
Packit 6c4009
latest_commit="$(git log --max-count=1 --pretty=format:%H "$branch" -- \
Packit 6c4009
  $patch_targets)"
Packit 6c4009
Packit 6c4009
# Simplify the branch name somewhat for reporting.
Packit 6c4009
branch_name="$(echo "$branch" | sed s,^origin/,,)"
Packit 6c4009
Packit 6c4009
command_patch () {
Packit 6c4009
    cat <
Packit 6c4009
This patch creates the contents of the support/ directory up to this
Packit 6c4009
upstream commit on the $branch_name branch:
Packit 6c4009
Packit 6c4009
EOF
Packit 6c4009
    git log --max-count=1 "$latest_commit"
Packit 6c4009
    echo
Packit 6c4009
    git diff "$initial_commit"^.."$latest_commit" $patch_targets
Packit 6c4009
    echo "# Before applying the patch, run this command:" >&2
Packit 6c4009
    echo "# rm -rf $patch_targets" >&2
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
command_commit () {
Packit 6c4009
    git status --porcelain | while read line ; do
Packit 6c4009
	echo "error: working copy is not clean, cannot commit" >&2
Packit 6c4009
	exit 1
Packit 6c4009
    done
Packit 6c4009
    for path in $patch_targets; do
Packit 6c4009
	echo "# Processing $path" >&2
Packit 6c4009
	case "$path" in
Packit 6c4009
	    [a-zA-Z0-9]*/)
Packit 6c4009
		# Directory.
Packit 6c4009
		git rm --cached --ignore-unmatch -r "$path"
Packit 6c4009
		rm -rf "$path"
Packit 6c4009
		git read-tree --prefix="$path" "$latest_commit":"$path"
Packit 6c4009
		git checkout "$path"
Packit 6c4009
		;;
Packit 6c4009
	    *)
Packit 6c4009
		# File.
Packit 6c4009
		git show "$latest_commit":"$path" > "$path"
Packit 6c4009
		git add "$path"
Packit 6c4009
	esac
Packit 6c4009
    done
Packit 6c4009
    git commit -m "Synchronize support/ infrastructure with $branch_name
Packit 6c4009
Packit 6c4009
This commit updates the support/ subdirectory to
Packit 6c4009
commit $latest_commit
Packit 6c4009
on the $branch_name branch.
Packit 6c4009
"
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
command_$command