mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
vim-patch.sh: Add --review option to compare PR and original diffs. #3083
Helped-by: Michael Reed <m.reed@mykolab.com>
This commit is contained in:
parent
9f350e615c
commit
95a4dc6487
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
set -o pipefail
|
||||
|
||||
readonly NEOVIM_SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
@ -12,21 +13,31 @@ usage() {
|
||||
echo "Helper script for porting Vim patches. For more information, see"
|
||||
echo "https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
||||
echo
|
||||
echo "Usage: ${BASENAME} [option]"
|
||||
echo " ${BASENAME} vim-revision"
|
||||
echo "Usage: ${BASENAME} [-h | -l | -p vim-revision | -r pr-number]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this message."
|
||||
echo " -l, --list Show list of Vim patches missing from Neovim."
|
||||
echo
|
||||
echo "vim-revision can be a version number of the format '7.4.xxx'"
|
||||
echo "or a Mercurial commit hash."
|
||||
echo " -h Show this message and exit."
|
||||
echo " -l Show list of Vim patches missing from Neovim."
|
||||
echo " -p {vim-revision} Download and apply the Vim patch vim-revision."
|
||||
echo " vim-revision can be a version number of the "
|
||||
echo " format '7.4.xxx' or a Mercurial commit hash."
|
||||
echo " -r {pr-number} Review a vim-patch pull request to Neovim."
|
||||
echo
|
||||
echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored."
|
||||
echo "The default is '${VIM_SOURCE_DIR_DEFAULT}'."
|
||||
}
|
||||
|
||||
# Checks if a program is in the user's PATH, and is executable.
|
||||
check_executable() {
|
||||
if [[ ! -x $(command -v "${1}") ]]; then
|
||||
>&2 echo "${BASENAME}: '${1}' not found in PATH or not executable."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_vim_sources() {
|
||||
check_executable hg
|
||||
|
||||
echo "Retrieving Vim sources."
|
||||
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
|
||||
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'."
|
||||
@ -41,20 +52,39 @@ get_vim_sources() {
|
||||
fi
|
||||
}
|
||||
|
||||
get_vim_patch() {
|
||||
commit_message() {
|
||||
echo "vim-patch:${vim_version}
|
||||
|
||||
${vim_message}
|
||||
|
||||
${vim_commit_url}"
|
||||
}
|
||||
|
||||
assign_commit_details() {
|
||||
if [[ ${1} =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then
|
||||
# Interpret parameter as version number.
|
||||
vim_version="${1}"
|
||||
vim_commit="v${1//./-}"
|
||||
strip_commit_line=true
|
||||
local strip_commit_line=true
|
||||
vim_commit_url="https://github.com/vim/vim/commit/${vim_commit}"
|
||||
else
|
||||
# Interpret parameter as commit hash.
|
||||
vim_version="${1:0:7}"
|
||||
vim_commit="${1}"
|
||||
strip_commit_line=false
|
||||
local strip_commit_line=false
|
||||
vim_commit_url="https://code.google.com/p/vim/source/detail?r=${vim_commit}"
|
||||
fi
|
||||
vim_message="$(hg log --template "{desc}" --rev "${vim_commit}")"
|
||||
if [[ ${strip_commit_line} == "true" ]]; then
|
||||
# Remove first line of commit message.
|
||||
vim_message="$(echo "${vim_message}" | sed -e '1d')"
|
||||
fi
|
||||
}
|
||||
|
||||
get_vim_patch() {
|
||||
get_vim_sources
|
||||
|
||||
assign_commit_details "${1}"
|
||||
|
||||
hg log --rev "${vim_commit}" >/dev/null 2>&1 || {
|
||||
>&2 echo "✘ Couldn't find Vim revision '${vim_commit}'."
|
||||
@ -65,19 +95,9 @@ get_vim_patch() {
|
||||
|
||||
# Collect patch details and store into variables.
|
||||
vim_full="$(hg log --patch --git --verbose --rev "${vim_commit}")"
|
||||
vim_message="$(hg log --template "{desc}" --rev "${vim_commit}")"
|
||||
if [[ ${strip_commit_line} == "true" ]]; then
|
||||
# Remove first line of commit message.
|
||||
vim_message="$(echo "${vim_message}" | sed -e '1d')"
|
||||
fi
|
||||
vim_diff="$(hg diff --show-function --git --change "${vim_commit}" \
|
||||
| sed -e 's/\( [ab]\/src\)/\1\/nvim/g')" # Change directory to src/nvim.
|
||||
neovim_message="
|
||||
vim-patch:${vim_version}
|
||||
|
||||
${vim_message}
|
||||
|
||||
${vim_commit_url}"
|
||||
neovim_message="$(commit_message)"
|
||||
neovim_pr="
|
||||
\`\`\`
|
||||
${vim_message}
|
||||
@ -108,7 +128,7 @@ ${vim_diff}
|
||||
echo
|
||||
echo "Creating files."
|
||||
echo "${vim_diff}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff"
|
||||
echo "✔ Saved patch to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'."
|
||||
echo "✔ Saved diff to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'."
|
||||
echo "${vim_full}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch"
|
||||
echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch'."
|
||||
echo "${neovim_pr}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr"
|
||||
@ -132,6 +152,8 @@ ${vim_diff}
|
||||
}
|
||||
|
||||
list_vim_patches() {
|
||||
get_vim_sources
|
||||
|
||||
echo
|
||||
echo "Vim patches missing from Neovim:"
|
||||
|
||||
@ -184,24 +206,88 @@ list_vim_patches() {
|
||||
echo " '${BASENAME} 1e8ebf870720e7b671f98f22d653009826304c4f'"
|
||||
}
|
||||
|
||||
if [[ ${1} == "--help" || ${1} == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
elif [[ ${#} != 1 ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
review_pr() {
|
||||
check_executable curl
|
||||
check_executable nvim
|
||||
|
||||
# Checks if mercurial is in the user's PATH, and is executable.
|
||||
if [[ ! -x $(command -v hg) ]]; then
|
||||
>&2 echo "${BASENAME}: 'hg' (mercurial) not found in PATH or not executable"
|
||||
exit 1
|
||||
fi
|
||||
get_vim_sources
|
||||
|
||||
get_vim_sources
|
||||
local pr="${1}"
|
||||
echo
|
||||
echo "Downloading data for pull request #${pr}."
|
||||
|
||||
if [[ ${1} == "--list" || ${1} == "-l" ]]; then
|
||||
list_vim_patches
|
||||
else
|
||||
get_vim_patch "${1}"
|
||||
fi
|
||||
local git_patch_prefix='Subject: \[PATCH\] '
|
||||
local neovim_patch="$(curl -Ssf "https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/${pr}.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")"
|
||||
|
||||
if [[ -n "${vim_version}" ]]; then
|
||||
echo "✔ Detected Vim patch '${vim_version}'."
|
||||
else
|
||||
echo "✘ Could not detect the Vim patch number."
|
||||
echo " This script assumes that the PR contains a single commit"
|
||||
echo " with 'vim-patch:XXX' as its title."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
assign_commit_details "${vim_version}"
|
||||
|
||||
local expected_commit_message="$(commit_message)"
|
||||
local message_length="$(wc -l <<< "${expected_commit_message}")"
|
||||
local commit_message="$(tail -n +4 <<< "${neovim_patch}" | head -n "${message_length}")"
|
||||
if [[ "${commit_message#${git_patch_prefix}}" == "${expected_commit_message}" ]]; then
|
||||
echo "✔ Found expected commit message."
|
||||
else
|
||||
echo "✘ Wrong commit message."
|
||||
echo " Expected:"
|
||||
echo "${expected_commit_message}"
|
||||
echo " Actual:"
|
||||
echo "${commit_message#${git_patch_prefix}}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local base_name="vim-${vim_version}"
|
||||
echo
|
||||
echo "Creating files."
|
||||
curl -Ssfo "${NEOVIM_SOURCE_DIR}/n${base_name}.diff" "https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/${pr}.diff"
|
||||
echo "✔ Saved pull request diff to '${NEOVIM_SOURCE_DIR}/n${base_name}.diff'."
|
||||
echo "${neovim_patch}" > "${NEOVIM_SOURCE_DIR}/n${base_name}.patch"
|
||||
echo "✔ Saved full pull request commit details to '${NEOVIM_SOURCE_DIR}/n${base_name}.patch'."
|
||||
hg diff --show-function --git --change "${vim_commit}" > "${NEOVIM_SOURCE_DIR}/${base_name}.diff"
|
||||
echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${base_name}.diff'."
|
||||
hg log --patch --git --verbose --rev "${vim_commit}" > "${NEOVIM_SOURCE_DIR}/${base_name}.patch"
|
||||
echo "✔ Saved full Vim commit details to '${NEOVIM_SOURCE_DIR}/${base_name}.patch'."
|
||||
echo "You can use 'git clean' to remove these files when you're done."
|
||||
|
||||
echo
|
||||
echo "Launching nvim."
|
||||
exec nvim -O "${NEOVIM_SOURCE_DIR}/${base_name}.diff" "${NEOVIM_SOURCE_DIR}/n${base_name}.diff"
|
||||
}
|
||||
|
||||
while getopts "hlp:r:" opt; do
|
||||
case ${opt} in
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
l)
|
||||
list_vim_patches
|
||||
exit 0
|
||||
;;
|
||||
p)
|
||||
get_vim_patch "${OPTARG}"
|
||||
exit 0
|
||||
;;
|
||||
r)
|
||||
review_pr "${OPTARG}"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
usage
|
||||
|
||||
# vim: et sw=2
|
||||
|
Loading…
Reference in New Issue
Block a user