Last active
February 8, 2019 15:23
-
-
Save kokosing/372cb2883e7c21107d28ea626693df90 to your computer and use it in GitHub Desktop.
Migrate changes from prestodb/presto to prestosql/presto ~/misc/migrate_changes.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
usage() { | |
echo "Usage: $0 <git change set>" | |
exit 1; | |
} | |
ask() { | |
echo "$@ [y|N]" | |
read answer | |
[[ "$answer" == y || "$answer" == Y ]] | |
} | |
if [[ $# != 1 ]]; then | |
usage | |
fi | |
commits="$(git log $1 --pretty='%H' --reverse)" | |
touch migrated | |
for commit in $commits; do | |
if grep $commit migrated -q; then | |
echo "Commit $commit is already migrated, see 'migrated' file" | |
continue | |
fi | |
git show $commit > $commit.diff | |
sed -i \ | |
-e 's@com/facebook/presto.hive@io/prestosql/plugin/hive@g' \ | |
-e 's@com/facebook/presto@io/prestosql@g' \ | |
-e 's@facebook/presto@prestosql@g' \ | |
-e '[email protected]@io.prestosql.plugin.hive@g' \ | |
-e '[email protected]@io.prestosql@g' \ | |
$commit.diff | |
if ! git apply -3 < $commit.diff; then | |
git mergetool | |
if ask "Apply manually?" && ! git apply --reject < $commit.diff; then | |
rejected_files_count="$(find -name '*.rej' | wc -l)" | |
if [[ "$rejected_files_count" -ne 0 ]]; then | |
echo "There are $rejected_files_count rejected files" | |
ask "Would you like to fix them manually?" | |
for rejected in $(find -name '*.rej'); do | |
# care about new imports, assuming that old imports will be optimized | |
if new_imports="$(cat "$rejected" | grep +import | sed 's/+//g' | tr -d '\n')"; then | |
sed -i "s/\(^package.*;\)/&$new_imports/" -i ${rejected%.rej} | |
if [[ $(cat "$rejected" | grep '^[+-]' | grep -v '[+-]import' | wc -l) -eq 0 ]]; then | |
echo "Skipping $rejected, only import changes" | |
else | |
vim -o "$rejected" "${rejected%.rej}" | |
fi | |
else | |
vim -o "$rejected" "${rejected%.rej}" | |
fi | |
rm "$rejected" | |
done | |
fi | |
fi | |
fi | |
modules="$(cat $commit.diff | grep '^[-+][+-][+-]' | cut -d / -f 2 | sort -u | tr '\n' , | sed 's/.$//')" | |
git add '*java' | |
git add '*pom.xml' | |
git status | |
if ask "Would you like to rebuild ($modules)? Also now is a good moment to optimize imports."; then | |
./mvnw package -pl "$modules" -DskipTests=true -TC1 | |
fi | |
# in case imports were optimized | |
git add '*java' | |
git commit -a \ | |
--author="$(git log $commit -1 --format='%an <%ae>')" \ | |
--message="$(git log $commit -1 --format='%B')" | |
rm $commit.diff | |
echo $commit >> migrated | |
done | |
rm migrated | |
echo "All patches are applied" | |
modules="$(git show $1 | grep '^[-+][+-][+-]' | grep -v dev/null | cut -d / -f 2 | sort -u | tr '\n' , | sed 's/.$//')" | |
if ask "Would you like to rebuild ($modules)? Also now is a good moment to optimize imports."; then | |
./mvnw package -pl "$modules" -DskipTests=true | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment