edit-patches.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # Recommended command-line:
  3. #
  4. # GIT_DIR=/your/rust/dir/.git ./edit-patches.sh
  5. prompt_changes() {
  6. bold_arrow; echo "Editing $IO_COMMIT"
  7. bold_arrow; echo -e "Remember to test your changes with: \e[1;36mcargo build\e[0m"
  8. local MAIN_GIT_DIR="$GIT_DIR"
  9. local GIT_DIR=./.git CORE_IO_COMMIT=$IO_COMMIT
  10. export CORE_IO_COMMIT
  11. git init > /dev/null
  12. git add .
  13. git commit -m "rust src import" > /dev/null
  14. IMPORT_COMMIT=$(git log -n1 --pretty=format:%H)
  15. patch -s -p1 < $PATCH_DIR/$IO_COMMIT.patch
  16. git commit -a -m "existing patch for $IO_COMMIT" > /dev/null
  17. bold_arrow; echo -e "Applying patch from \e[1;36m$TMP_PATCH\e[0m"
  18. patch -p1 < $TMP_PATCH || true
  19. bold_arrow; echo -e "Make your changes now (\e[1;36mctrl-D\e[0m when finished)"
  20. bash_diff_loop "No changes were made"
  21. bold_arrow; echo "Replacing $IO_COMMIT.patch with updated version"
  22. git diff > $TMP_PATCH
  23. git clean -f -x
  24. git diff > $PATCH_DIR/$IO_COMMIT.patch
  25. rm -rf .git
  26. }
  27. if [ ! -t 1 ] || [ ! -t 2 ]; then
  28. echo "==> /dev/stdout or /dev/stderr is not attached to a terminal!"
  29. echo "==> This script must be run interactively."
  30. exit 1
  31. fi
  32. cd "$(dirname "$0")"
  33. . ./functions.sh
  34. PATCH_DIR="$PWD/patches"
  35. PATCH_COMMITS=$(get_patch_commits|sort -u)
  36. TMP_PATCH=$(mktemp)
  37. set -e
  38. set -o pipefail
  39. find src -mindepth 1 -type d -prune -exec rm -rf {} \;
  40. for IO_COMMIT in $(git_commits_ordered %H $PATCH_COMMITS|tac); do
  41. prepare_version
  42. cd src/$IO_COMMIT
  43. prompt_changes
  44. cd ../..
  45. done
  46. rm -rf $TMP_PATCH
  47. bold_arrow; echo "Done"