mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 19:35:37 +00:00
vim-patch.sh: Improvements for review functionality.
* Support pull requests with multiple commits. * Offer to clean up files after review. * Always use full commit hash in assign_commit_details().
This commit is contained in:
@@ -9,6 +9,8 @@ readonly VIM_SOURCE_DIR_DEFAULT=${NEOVIM_SOURCE_DIR}/.vim-src
|
|||||||
readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
||||||
readonly BASENAME="$(basename "${0}")"
|
readonly BASENAME="$(basename "${0}")"
|
||||||
|
|
||||||
|
CREATED_FILES=()
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Helper script for porting Vim patches. For more information, see"
|
echo "Helper script for porting Vim patches. For more information, see"
|
||||||
echo "https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
echo "https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
||||||
@@ -35,6 +37,27 @@ check_executable() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clean_files() {
|
||||||
|
if [[ ${#CREATED_FILES[@]} -eq 0 ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Created files:"
|
||||||
|
local file
|
||||||
|
for file in ${CREATED_FILES[@]}; do
|
||||||
|
echo " • ${file}"
|
||||||
|
done
|
||||||
|
|
||||||
|
read -p "Delete these files (Y/n)? " -n 1 -r reply
|
||||||
|
echo
|
||||||
|
if [[ "${reply}" =~ ^[Yy]$ ]]; then
|
||||||
|
rm -- ${CREATED_FILES[@]}
|
||||||
|
else
|
||||||
|
echo "You can use 'git clean' to remove these files when you're done."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
get_vim_sources() {
|
get_vim_sources() {
|
||||||
check_executable git
|
check_executable git
|
||||||
|
|
||||||
@@ -72,7 +95,8 @@ assign_commit_details() {
|
|||||||
else
|
else
|
||||||
# Interpret parameter as commit hash.
|
# Interpret parameter as commit hash.
|
||||||
vim_version="${1:0:7}"
|
vim_version="${1:0:7}"
|
||||||
vim_commit="${1}"
|
vim_commit=$(cd "${VIM_SOURCE_DIR}" \
|
||||||
|
&& git log -1 --format="%H" ${vim_version})
|
||||||
local strip_commit_line=false
|
local strip_commit_line=false
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -198,21 +222,14 @@ list_vim_patches() {
|
|||||||
echo " Out-of-order patches increase the possibility of bugs."
|
echo " Out-of-order patches increase the possibility of bugs."
|
||||||
}
|
}
|
||||||
|
|
||||||
review_pr() {
|
review_commit() {
|
||||||
check_executable curl
|
local neovim_commit_url="${1}"
|
||||||
check_executable nvim
|
|
||||||
|
|
||||||
get_vim_sources
|
|
||||||
|
|
||||||
local pr="${1}"
|
|
||||||
echo
|
|
||||||
echo "Downloading data for pull request #${pr}."
|
|
||||||
|
|
||||||
local git_patch_prefix='Subject: \[PATCH\] '
|
local git_patch_prefix='Subject: \[PATCH\] '
|
||||||
local neovim_patch="$(curl -Ssf "https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/${pr}.patch")"
|
local neovim_patch="$(curl -Ssf "${neovim_commit_url}.patch")"
|
||||||
echo "${neovim_patch}" > a
|
|
||||||
local vim_version="$(head -n 4 <<< "${neovim_patch}" | sed -n "s/${git_patch_prefix}vim-patch:\([a-z0-9.]*\)$/\1/p")"
|
local vim_version="$(head -n 4 <<< "${neovim_patch}" | sed -n "s/${git_patch_prefix}vim-patch:\([a-z0-9.]*\)$/\1/p")"
|
||||||
|
|
||||||
|
echo
|
||||||
if [[ -n "${vim_version}" ]]; then
|
if [[ -n "${vim_version}" ]]; then
|
||||||
echo "✔ Detected Vim patch '${vim_version}'."
|
echo "✔ Detected Vim patch '${vim_version}'."
|
||||||
else
|
else
|
||||||
@@ -235,23 +252,55 @@ review_pr() {
|
|||||||
echo "${expected_commit_message}"
|
echo "${expected_commit_message}"
|
||||||
echo " Actual:"
|
echo " Actual:"
|
||||||
echo "${commit_message#${git_patch_prefix}}"
|
echo "${commit_message#${git_patch_prefix}}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local base_name="vim-${vim_version}"
|
local base_name="vim-${vim_version}"
|
||||||
echo
|
echo
|
||||||
echo "Creating files."
|
echo "Creating files."
|
||||||
curl -Ssfo "${NEOVIM_SOURCE_DIR}/n${base_name}.diff" "https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/${pr}.diff"
|
curl -Ssfo "${NEOVIM_SOURCE_DIR}/n${base_name}.diff" "${neovim_commit_url}.diff"
|
||||||
echo "✔ Saved pull request diff to '${NEOVIM_SOURCE_DIR}/n${base_name}.diff'."
|
echo "✔ Saved pull request diff to '${NEOVIM_SOURCE_DIR}/n${base_name}.diff'."
|
||||||
echo "${neovim_patch}" > "${NEOVIM_SOURCE_DIR}/n${base_name}.patch"
|
CREATED_FILES+=("${NEOVIM_SOURCE_DIR}/n${base_name}.diff")
|
||||||
echo "✔ Saved full pull request commit details to '${NEOVIM_SOURCE_DIR}/n${base_name}.patch'."
|
|
||||||
git show "${vim_commit}" > "${NEOVIM_SOURCE_DIR}/${base_name}.diff"
|
git show -b --format= "${vim_commit}" > "${NEOVIM_SOURCE_DIR}/${base_name}.diff"
|
||||||
echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${base_name}.diff'."
|
echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${base_name}.diff'."
|
||||||
echo "You can use 'git clean' to remove these files when you're done."
|
CREATED_FILES+=("${NEOVIM_SOURCE_DIR}/${base_name}.diff")
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Launching nvim."
|
echo "Launching nvim."
|
||||||
exec nvim -O "${NEOVIM_SOURCE_DIR}/${base_name}.diff" "${NEOVIM_SOURCE_DIR}/n${base_name}.diff"
|
nvim -c "cd ${NEOVIM_SOURCE_DIR}" \
|
||||||
|
-O "${NEOVIM_SOURCE_DIR}/${base_name}.diff" "${NEOVIM_SOURCE_DIR}/n${base_name}.diff"
|
||||||
|
}
|
||||||
|
|
||||||
|
review_pr() {
|
||||||
|
check_executable curl
|
||||||
|
check_executable nvim
|
||||||
|
check_executable jq
|
||||||
|
|
||||||
|
get_vim_sources
|
||||||
|
|
||||||
|
local pr="${1}"
|
||||||
|
echo
|
||||||
|
echo "Downloading data for pull request #${pr}."
|
||||||
|
|
||||||
|
local pr_commit_urls=($(curl -Ssf "https://api.github.com/repos/neovim/neovim/pulls/${pr}/commits" \
|
||||||
|
| jq -r '.[].html_url'))
|
||||||
|
|
||||||
|
echo "Found ${#pr_commit_urls[@]} commit(s)."
|
||||||
|
|
||||||
|
local pr_commit_url
|
||||||
|
local reply
|
||||||
|
for pr_commit_url in ${pr_commit_urls[@]}; do
|
||||||
|
review_commit "${pr_commit_url}"
|
||||||
|
if [[ "${pr_commit_url}" != "${pr_commit_urls[-1]}" ]]; then
|
||||||
|
read -p "Continue with next commit (Y/n)? " -n 1 -r reply
|
||||||
|
echo
|
||||||
|
if [[ ! "${reply}" =~ ^[Yy]$ ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
clean_files
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "hlp:r:" opt; do
|
while getopts "hlp:r:" opt; do
|
||||||
|
|||||||
Reference in New Issue
Block a user