From 0f70a211eab8fa96097b52b4ffe5243876f7bfce Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Fri, 6 Aug 2021 15:17:32 +0200 Subject: [PATCH] Use bash, no rsync, add doc --- maintainers/patches | 116 +++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 38 deletions(-) diff --git a/maintainers/patches b/maintainers/patches index 4e2c505..f7b50e9 100755 --- a/maintainers/patches +++ b/maintainers/patches @@ -1,37 +1,22 @@ -#!/bin/zsh +#!/bin/bash +set -e -PROGRAM=$0 +PROGRAM="$0" success() { - echo "\e[1;32mDone:\e[m $1" + echo -e "\e[1;32mDone:\e[m $1" exit 0 } fail() { - echo "\e[1;31mError:\e[m $1" + echo -e "\e[1;31mError:\e[m $1" exit 1 } -help() { - cat < + + 3. Create a fix commit per affected patch by repeating the following commands + until there are no more files to add: + + git add -p + git commit -m'fix ' + + 4. Merge the fixes into their patches by moving their line below their patch + and changing their "edit" into "fixup": + + git rebase -i ${root} + + 5. Save the changes: + + cd ../.. + ${PROGRAM} save + + 6. Either continue repeating steps 2 to 5, or return to the normal state: + + ./setup.sh +EOF + exit 0 +} + apply() { - git submodule -q update third_party/tock - ( cd third_party/tock + local root="$(get_root)" + ( set -e + cd third_party/tock git reset -q --hard git clean -qfxd - rsync -a ../../boards . + git checkout -q "${root}" + cp -a ../../boards . commit '00-boards' for file in ../../patches/tock/*; do - patch -sp1 < $file - commit "${${file#../../patches/tock/}%.patch}" + git apply "${file}" + commit "$(basename "${file}" .patch)" done ) success 'Applied the patches to the Tock submodule.' } save() { - local root=$(get_root) - ( cd third_party/tock + local root="$(get_root)" + ( set -e + cd third_party/tock [[ -z "$(git status -s)" ]] || fail 'The Tock submodule is not clean.' rm ../../patches/tock/*.patch - for file in $(git format-patch $root); do - sed -n '/^diff/,$p' $file | head -n-3 > ../../patches/tock/${file#*-} + for file in $(git format-patch "${root}"); do + sed -n '/^diff/,$p' "${file}" \ + | head -n-3 > "../../patches/tock/${file#*-}" done git clean -qfxd - top=$(get_head) - git checkout -q $root + top="$(get_head)" + git checkout -q "${root}" rm -r boards - patch -sp1 < ../../patches/tock/00-boards.patch + git apply --whitespace=nowarn ../../patches/tock/00-boards.patch rm ../../patches/tock/00-boards.patch - rsync -a --delete boards ../.. + rm -r ../../boards + cp -a boards ../.. git reset -q --hard git clean -qfxd - git checkout -q $top - ) || exit + git checkout -q "${top}" + ) success 'Saved the Tock submodule to the patches.' } -[[ $(basename $PWD) == OpenSK ]] || fail 'Not running from OpenSK directory.' +grep -q third_party/tock .gitmodules 2>/dev/null \ + || fail 'Not running from OpenSK directory.' [[ $# -eq 1 ]] || help case $1 in apply) apply ;;