NEWS: Add advisories.
[glibc.git] / scripts / backport-support.sh
blobdffbf2ee3f551a09eb75e7b3425c07f5f85b76ee
1 #!/bin/bash
2 # Create a patch which backports the support/ subdirectory.
3 # Copyright (C) 2017-2024 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
20 # This script does not backport the Makefile tweaks outside the
21 # support/ directory (which need to be backported separately), or the
22 # changes to test-skeleton.c (which should not be backported).
24 set -e
26 export LC_ALL=C
27 export GIT_CONFIG=/dev/null
28 export GTT_CONFIG_NOSYSTEM=0
29 export GIT_PAGER=
31 usage () {
32 cat >&2 <<EOF
33 usage: $0 {patch|commit}
34 EOF
35 exit 1
38 if test $# -ne 1 ; then
39 usage
42 command="$1"
44 case "$command" in
45 patch|commit)
48 usage
50 esac
52 # The upstream branch to work on.
53 branch=origin/master
55 # The commit which added the support/ directory.
56 initial_commit=c23de0aacbeaa7a091609b35764bed931475a16d
58 # We backport the support directory and this script. Directories need
59 # to end in a /.
60 patch_targets="support/ scripts/backport-support.sh"
62 latest_commit="$(git log --max-count=1 --pretty=format:%H "$branch" -- \
63 $patch_targets)"
65 # Simplify the branch name somewhat for reporting.
66 branch_name="$(echo "$branch" | sed s,^origin/,,)"
68 command_patch () {
69 cat <<EOF
70 This patch creates the contents of the support/ directory up to this
71 upstream commit on the $branch_name branch:
73 EOF
74 git log --max-count=1 "$latest_commit"
75 echo
76 git diff "$initial_commit"^.."$latest_commit" $patch_targets
77 echo "# Before applying the patch, run this command:" >&2
78 echo "# rm -rf $patch_targets" >&2
81 command_commit () {
82 git status --porcelain | while read line ; do
83 echo "error: working copy is not clean, cannot commit" >&2
84 exit 1
85 done
86 for path in $patch_targets; do
87 echo "# Processing $path" >&2
88 case "$path" in
89 [a-zA-Z0-9]*/)
90 # Directory.
91 git rm --cached --ignore-unmatch -r "$path"
92 rm -rf "$path"
93 git read-tree --prefix="$path" "$latest_commit":"$path"
94 git checkout "$path"
97 # File.
98 git show "$latest_commit":"$path" > "$path"
99 git add "$path"
100 esac
101 done
102 git commit -m "Synchronize support/ infrastructure with $branch_name
104 This commit updates the support/ subdirectory to
105 commit $latest_commit
106 on the $branch_name branch.
110 command_$command