2014-12-25 12:50:28 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
2015-07-22 08:00:17 -07:00
|
|
|
set -u
|
2014-12-25 12:50:28 -07:00
|
|
|
set -o pipefail
|
2014-11-21 06:39:35 -07:00
|
|
|
|
2015-03-05 19:49:03 -07:00
|
|
|
readonly NEOVIM_SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
readonly VIM_SOURCE_DIR_DEFAULT=${NEOVIM_SOURCE_DIR}/.vim-src
|
|
|
|
readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
|
|
|
readonly BASENAME="$(basename "${0}")"
|
2014-11-21 06:39:35 -07:00
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
usage() {
|
2015-03-05 19:49:03 -07:00
|
|
|
echo "Helper script for porting Vim patches. For more information, see"
|
|
|
|
echo "https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
|
|
|
echo
|
2015-07-22 08:00:17 -07:00
|
|
|
echo "Usage: ${BASENAME} [-h | -l | -p vim-revision | -r pr-number]"
|
2015-03-05 19:49:03 -07:00
|
|
|
echo
|
|
|
|
echo "Options:"
|
2015-07-22 08:00:17 -07:00
|
|
|
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 "
|
2015-08-18 21:21:11 -07:00
|
|
|
echo " format '7.4.xxx' or a Git commit hash."
|
2015-07-22 08:00:17 -07:00
|
|
|
echo " -r {pr-number} Review a vim-patch pull request to Neovim."
|
2015-03-05 19:49:03 -07:00
|
|
|
echo
|
|
|
|
echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored."
|
|
|
|
echo "The default is '${VIM_SOURCE_DIR_DEFAULT}'."
|
2015-01-07 12:52:10 -07:00
|
|
|
}
|
|
|
|
|
2015-07-22 08:00:17 -07:00
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
get_vim_sources() {
|
2015-08-18 21:21:11 -07:00
|
|
|
check_executable git
|
2015-07-22 08:00:17 -07:00
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "Retrieving Vim sources."
|
|
|
|
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
|
|
|
|
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'."
|
2015-08-18 21:21:11 -07:00
|
|
|
git clone --depth=1000 https://github.com/vim/vim.git "${VIM_SOURCE_DIR}"
|
2015-03-05 19:49:03 -07:00
|
|
|
cd "${VIM_SOURCE_DIR}"
|
2015-01-07 12:52:10 -07:00
|
|
|
else
|
2015-08-18 21:21:11 -07:00
|
|
|
if [[ ! -d "${VIM_SOURCE_DIR}/.git" ]]; then
|
|
|
|
echo "✘ ${VIM_SOURCE_DIR} does not appear to be a git repository."
|
|
|
|
echo " Please remove it and try again."
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "Updating Vim sources in '${VIM_SOURCE_DIR}'."
|
2015-03-05 19:49:03 -07:00
|
|
|
cd "${VIM_SOURCE_DIR}"
|
2015-08-18 21:21:11 -07:00
|
|
|
git pull &&
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "✔ Updated Vim sources." ||
|
|
|
|
echo "✘ Could not update Vim sources; ignoring error."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:00:17 -07:00
|
|
|
commit_message() {
|
|
|
|
echo "vim-patch:${vim_version}
|
|
|
|
|
|
|
|
${vim_message}
|
|
|
|
|
|
|
|
${vim_commit_url}"
|
|
|
|
}
|
|
|
|
|
|
|
|
assign_commit_details() {
|
2015-03-05 19:49:03 -07:00
|
|
|
if [[ ${1} =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then
|
2015-01-07 12:52:10 -07:00
|
|
|
# Interpret parameter as version number.
|
|
|
|
vim_version="${1}"
|
2015-08-18 21:21:11 -07:00
|
|
|
vim_commit="v${1}"
|
2015-07-22 08:00:17 -07:00
|
|
|
local strip_commit_line=true
|
2015-08-18 21:21:11 -07:00
|
|
|
vim_commit_url="https://github.com/vim/vim/tree/${vim_commit}"
|
2015-01-07 12:52:10 -07:00
|
|
|
else
|
|
|
|
# Interpret parameter as commit hash.
|
|
|
|
vim_version="${1:0:7}"
|
|
|
|
vim_commit="${1}"
|
2015-07-22 08:00:17 -07:00
|
|
|
local strip_commit_line=false
|
2015-08-18 21:21:11 -07:00
|
|
|
vim_commit_url="https://github.com/vim/vim/commit/${vim_commit}"
|
2015-01-07 12:52:10 -07:00
|
|
|
fi
|
2015-08-18 21:21:11 -07:00
|
|
|
vim_message="$(git log --pretty='format:%B' "${vim_commit}^\!")"
|
2015-07-22 08:00:17 -07:00
|
|
|
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}"
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2015-08-18 21:21:11 -07:00
|
|
|
git log "${vim_commit}^\!" -- >/dev/null 2>&1 || {
|
2015-01-07 12:52:10 -07:00
|
|
|
>&2 echo "✘ Couldn't find Vim revision '${vim_commit}'."
|
|
|
|
exit 3
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
echo "✔ Found Vim revision '${vim_commit}'."
|
|
|
|
|
|
|
|
# Collect patch details and store into variables.
|
2015-08-18 21:21:11 -07:00
|
|
|
vim_full="$(git log --pretty=medium "${vim_commit}^\!")"
|
|
|
|
vim_diff="$(git diff "${vim_commit}^\!" \
|
2015-01-07 12:52:10 -07:00
|
|
|
| sed -e 's/\( [ab]\/src\)/\1\/nvim/g')" # Change directory to src/nvim.
|
2015-07-22 08:00:17 -07:00
|
|
|
neovim_message="$(commit_message)"
|
2015-01-07 12:52:10 -07:00
|
|
|
neovim_pr="
|
2015-04-28 02:34:43 -07:00
|
|
|
\`\`\`
|
|
|
|
${vim_message}
|
|
|
|
\`\`\`
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2015-04-28 02:34:43 -07:00
|
|
|
${vim_commit_url}
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2015-04-28 02:34:43 -07:00
|
|
|
Original patch:
|
2015-01-07 12:52:10 -07:00
|
|
|
|
2015-04-28 02:34:43 -07:00
|
|
|
\`\`\`diff
|
|
|
|
${vim_diff}
|
|
|
|
\`\`\`"
|
2015-01-07 12:52:10 -07:00
|
|
|
neovim_branch="vim-${vim_version}"
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Creating Git branch."
|
2015-03-05 19:49:03 -07:00
|
|
|
cd "${NEOVIM_SOURCE_DIR}"
|
2015-01-07 12:52:10 -07:00
|
|
|
output="$(git checkout -b "${neovim_branch}" 2>&1)" &&
|
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; false)
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Creating empty commit with correct commit message."
|
|
|
|
output="$(git commit --allow-empty --file 2>&1 - <<< "${neovim_message}")" &&
|
|
|
|
echo "✔ ${output}" ||
|
|
|
|
(echo "✘ ${output}"; false)
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Creating files."
|
2015-03-05 19:49:03 -07:00
|
|
|
echo "${vim_diff}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff"
|
2015-07-22 08:00:17 -07:00
|
|
|
echo "✔ Saved diff to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'."
|
2015-03-05 19:49:03 -07:00
|
|
|
echo "${vim_full}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch"
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch'."
|
2015-03-05 19:49:03 -07:00
|
|
|
echo "${neovim_pr}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr"
|
2015-01-07 12:52:10 -07:00
|
|
|
echo "✔ Saved suggested PR description to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr'."
|
|
|
|
echo "You can use 'git clean' to remove these files when you're done."
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Instructions:"
|
|
|
|
echo
|
|
|
|
echo " Proceed to port the patch."
|
|
|
|
echo " You might want to try 'patch -p1 < ${neovim_branch}.diff' first."
|
|
|
|
echo
|
|
|
|
echo " Stage your changes ('git add ...') and use 'git commit --amend' to commit."
|
|
|
|
echo
|
|
|
|
echo " Push your changes with 'git push origin ${neovim_branch}' and create a"
|
|
|
|
echo " pull request called '[RFC] vim-patch:${vim_version}'. You might want "
|
|
|
|
echo " to use the text in '${neovim_branch}.pr' as the description of this pull request."
|
|
|
|
echo
|
|
|
|
echo " See https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
|
|
|
echo " for more information."
|
|
|
|
}
|
|
|
|
|
|
|
|
list_vim_patches() {
|
2015-07-22 08:00:17 -07:00
|
|
|
get_vim_sources
|
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
echo
|
|
|
|
echo "Vim patches missing from Neovim:"
|
|
|
|
|
|
|
|
# Get vim patches and runtime file updates.
|
|
|
|
# Start from 7.4.442. The runtime was re-integrated from 7.4.384, but
|
|
|
|
# runtime patches before between 384 and 442 have already been ported
|
|
|
|
# to Neovim as of the creation of this script.
|
2015-03-05 19:49:03 -07:00
|
|
|
local vim_commits=$(cd "${VIM_SOURCE_DIR}" && \
|
2015-08-18 21:21:11 -07:00
|
|
|
git log --pretty='tformat:%H|%d' v7.4.442..HEAD | awk -f ${NEOVIM_SOURCE_DIR}/scripts/vim-patch-helper.awk)
|
|
|
|
|
2015-01-07 12:52:10 -07:00
|
|
|
# Append remaining vim patches.
|
|
|
|
# Start from 7.4.160, where Neovim was forked.
|
2015-03-05 19:49:03 -07:00
|
|
|
local vim_old_commits=$(cd "${VIM_SOURCE_DIR}" && \
|
2015-08-18 21:21:11 -07:00
|
|
|
git log --pretty='tformat:%d' v7.4.160..v7.4.442 | awk '{ if ($1 != "") { gsub(/[()]/, "", $2); print($2); } }')
|
2015-01-07 12:52:10 -07:00
|
|
|
|
|
|
|
local vim_commit
|
|
|
|
for vim_commit in ${vim_commits} ${vim_old_commits}; do
|
|
|
|
local is_missing
|
2015-08-18 21:21:11 -07:00
|
|
|
if [[ ${vim_commit} =~ v([0-9].[0-9].([0-9]{3,4})) ]]; then
|
2015-01-07 12:52:10 -07:00
|
|
|
local patch_number="${BASH_REMATCH[2]}"
|
|
|
|
# "Proper" Vim patch
|
|
|
|
# Check version.c:
|
2015-03-05 19:49:03 -07:00
|
|
|
is_missing="$(sed -n '/static int included_patches/,/}/p' "${NEOVIM_SOURCE_DIR}/src/nvim/version.c" |
|
2015-01-07 12:52:10 -07:00
|
|
|
grep -x -e "[[:space:]]*//${patch_number} NA" -e "[[:space:]]*${patch_number}," >/dev/null && echo "false" || echo "true")"
|
|
|
|
vim_commit="${BASH_REMATCH[1]//-/.}"
|
|
|
|
else
|
|
|
|
# Untagged Vim patch, e.g. runtime updates.
|
|
|
|
# Check Neovim log:
|
2015-03-05 19:49:03 -07:00
|
|
|
is_missing="$(cd "${NEOVIM_SOURCE_DIR}" &&
|
2015-01-07 12:52:10 -07:00
|
|
|
git log -1 --no-merges --grep="vim\-patch:${vim_commit:0:7}" --pretty=format:"false")"
|
|
|
|
fi
|
|
|
|
|
2015-03-05 19:49:03 -07:00
|
|
|
if [[ ${is_missing} != "false" ]]; then
|
2015-01-07 12:52:10 -07:00
|
|
|
echo " • ${vim_commit}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Instructions:"
|
|
|
|
echo
|
|
|
|
echo " To port one of the above patches to Neovim, execute"
|
|
|
|
echo " this script with the patch revision as argument."
|
|
|
|
echo
|
2015-03-05 19:49:03 -07:00
|
|
|
echo " Examples: '${BASENAME} 7.4.487'"
|
|
|
|
echo " '${BASENAME} 1e8ebf870720e7b671f98f22d653009826304c4f'"
|
2015-01-07 12:52:10 -07:00
|
|
|
}
|
|
|
|
|
2015-07-22 08:00:17 -07:00
|
|
|
review_pr() {
|
|
|
|
check_executable curl
|
|
|
|
check_executable nvim
|
|
|
|
|
|
|
|
get_vim_sources
|
|
|
|
|
|
|
|
local pr="${1}"
|
|
|
|
echo
|
|
|
|
echo "Downloading data for pull request #${pr}."
|
|
|
|
|
|
|
|
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'."
|
2015-08-18 21:21:11 -07:00
|
|
|
git diff "${vim_commit}^\!" > "${NEOVIM_SOURCE_DIR}/${base_name}.diff"
|
2015-07-22 08:00:17 -07:00
|
|
|
echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${base_name}.diff'."
|
2015-08-18 21:21:11 -07:00
|
|
|
git show "${vim_commit}" > "${NEOVIM_SOURCE_DIR}/${base_name}.patch"
|
2015-07-22 08:00:17 -07:00
|
|
|
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
|