diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index c2fac658a9..0854c2f627 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -280,49 +280,32 @@ preprocess_patch() { } uncrustify_patch() { - local commit="$1" - local changed_files=() - while IFS='' read -r file; do changed_files+=("$file"); done < <(git diff-tree --name-only --no-commit-id -r "${commit}") + git diff --quiet || { + >&2 echo 'Vim source working tree dirty, aborting.' + exit 1 + } local patch_path=$NVIM_SOURCE_DIR/build/vim_patch rm -rf "$patch_path" - mkdir -p "$patch_path"/{before,after,patch} + mkdir -p "$patch_path"/{a,b} - git checkout --quiet "$commit"~ - for file in "${changed_files[@]}"; do - if [[ -e $file ]]; then - cp "$file" "$patch_path"/before - fi + local commit="$1" + for file in $(git diff-tree --name-only --no-commit-id -r --diff-filter=a "$commit"); do + git --work-tree="$patch_path"/a checkout --quiet "$commit"~ -- "$file" done - - git checkout --quiet "$commit" - for file in "${changed_files[@]}"; do - if [[ -e $file ]]; then - cp "$file" "$patch_path"/after - fi + for file in $(git diff-tree --name-only --no-commit-id -r --diff-filter=d "$commit"); do + git --work-tree="$patch_path"/b checkout --quiet "$commit" -- "$file" done + git reset --quiet --hard HEAD # If the difference are drastic enough uncrustify may need to be used more # than once. This is obviously a bug that needs to be fixed on uncrustify's # end, but in the meantime this workaround is sufficient. for _ in {1..2}; do - uncrustify -c "$NVIM_SOURCE_DIR"/src/uncrustify.cfg -q --replace --no-backup "$patch_path"/{before,after}/*.[ch] + uncrustify -c "$NVIM_SOURCE_DIR"/src/uncrustify.cfg -q --replace --no-backup "$patch_path"/{a,b}/src/*.[ch] done - for file in "${changed_files[@]}"; do - local basename - basename=$(basename "$file") - local before=$patch_path/before/$basename - local after=$patch_path/after/$basename - local patchfile="$patch_path"/patch/"$basename".patch - [[ ! -e $before ]] && before=/dev/null - [[ ! -e $after ]] && after=/dev/null - git --no-pager diff --no-index --patch --unified=5 --color=never "$before" "$after" > "$patchfile" - [[ "$before" != /dev/null ]] && sed -E "s|$before|/$file|g" -i "$patchfile" - [[ "$after" != /dev/null ]] && sed -E "s|$after|/$file|g" -i "$patchfile" - done - - cat "$patch_path"/patch/*.patch + (cd "$patch_path" && (git --no-pager diff --no-index --no-prefix --patch --unified=5 --color=never a/ b/ || true)) } get_vimpatch() { @@ -335,7 +318,6 @@ get_vimpatch() { local patch_content if check_executable uncrustify; then patch_content="$(uncrustify_patch "${vim_commit}")" - git switch --quiet master else patch_content="$(git --no-pager show --unified=5 --color=never -1 --pretty=medium "${vim_commit}")" fi