Skip to content

Commit

Permalink
build: pre-process vim patches with uncrustify
Browse files Browse the repository at this point in the history
This will enable a larger amount of chunks being automatically included
due to fewer formatting differences between the vim and neovim files.

The strategy is straightforward, if a bit tedious:

- Get a list of all changed files.
- Checkout parent commit. Copy all relevant files to a temporary
  location.
- Checkout patch commit. Copy all relevant files to a temporary
  location.
- Format .c and .h files with uncrustify.
- Generate a diff from from these files.

Closes #6226
  • Loading branch information
dundargoc committed Oct 23, 2022
1 parent 7718241 commit e180ee8
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion scripts/vim-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,37 @@ preprocess_patch() {
"$file" > "$file".tmp && mv "$file".tmp "$file"
}

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}")

local patch_path=$NVIM_SOURCE_DIR/build/vim_patch
rm -rf "$patch_path"
mkdir -p "$patch_path"/{before,after,patch}

git checkout --quiet "$commit"~
cp "${changed_files[@]}" "$patch_path"/before

git checkout --quiet "$commit"
cp "${changed_files[@]}" "$patch_path"/after

uncrustify -c "$NVIM_SOURCE_DIR"/src/uncrustify.cfg -q --replace --no-backup "$patch_path"/{before,after}/*.[ch]

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
git diff --no-index --patch "$before" "$after" > "$patchfile"
sed -E "s|$before|/$file|g" -i "$patchfile"
sed -E "s|$after|/$file|g" -i "$patchfile"
done

cat "$patch_path"/patch/*.patch
}

get_vimpatch() {
get_vim_sources

Expand All @@ -287,7 +318,12 @@ get_vimpatch() {
msg_ok "Found Vim revision '${vim_commit}'."

local patch_content
patch_content="$(git --no-pager show --unified=5 --color=never -1 --pretty=medium "${vim_commit}")"
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

cd "${NVIM_SOURCE_DIR}"

Expand Down

0 comments on commit e180ee8

Please sign in to comment.