backport-support.sh 2.8 KB

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