mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
vim-patch.sh: Add option to list missing Vim changesets.
This commit is contained in:
parent
050c6515f8
commit
0cbc48ea89
@ -7,19 +7,25 @@ NEOVIM_SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
VIM_SOURCE_DIR_DEFAULT=${NEOVIM_SOURCE_DIR}/.vim-src
|
||||
VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}"
|
||||
|
||||
if [[ ${#} != 1 ]]; then
|
||||
usage() {
|
||||
>&2 echo "Helper script for porting Vim patches. For more information,"
|
||||
>&2 echo "see https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim."
|
||||
>&2 echo
|
||||
>&2 echo "Usage: ${0} vim-revision"
|
||||
>&2 echo "Usage: ${0} [option]"
|
||||
>&2 echo " ${0} vim-revision"
|
||||
>&2 echo
|
||||
>&2 echo "Options:"
|
||||
>&2 echo " --help Show this message."
|
||||
>&2 echo " --list Show list of Vim patches missing from Neovim."
|
||||
>&2 echo
|
||||
>&2 echo "vim-revision can be a version number in format '7.4.xxx'"
|
||||
>&2 echo "or a Mercurial commit hash."
|
||||
>&2 echo
|
||||
>&2 echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored."
|
||||
>&2 echo "The default is '${VIM_SOURCE_DIR_DEFAULT}'."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_vim_sources() {
|
||||
echo "Retrieving Vim sources."
|
||||
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
|
||||
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'."
|
||||
@ -28,9 +34,13 @@ if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
|
||||
else
|
||||
echo "Updating Vim sources in '${VIM_SOURCE_DIR}'."
|
||||
cd ${VIM_SOURCE_DIR}
|
||||
hg pull --update || echo "✘ Could not update Vim sources."
|
||||
hg pull --update &&
|
||||
echo "✔ Updated Vim sources." ||
|
||||
echo "✘ Could not update Vim sources; ignoring error."
|
||||
fi
|
||||
}
|
||||
|
||||
get_vim_patch() {
|
||||
if [[ "${1}" =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then
|
||||
# Interpret parameter as version number.
|
||||
vim_version="${1}"
|
||||
@ -47,6 +57,7 @@ hg log --rev ${vim_commit} >/dev/null 2>&1 || {
|
||||
>&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.
|
||||
@ -81,18 +92,15 @@ neovim_branch="vim-${vim_version}"
|
||||
echo
|
||||
echo "Creating Git branch."
|
||||
cd ${NEOVIM_SOURCE_DIR}
|
||||
echo -n "✘ "
|
||||
# 'git checkout -b' writes to stderr in case of success :-(
|
||||
# Re-add newline (stripped by echo -n) in error case.
|
||||
git checkout -b "${neovim_branch}" 2>&1 | xargs echo -n || (echo; false)
|
||||
echo -n "." # Add trailing dot.
|
||||
echo -e "\r✔ " # Replace ✘ with ✔
|
||||
output="$(git checkout -b "${neovim_branch}" 2>&1)" &&
|
||||
echo "✔ ${output}" ||
|
||||
(echo "✘ ${output}"; false)
|
||||
|
||||
echo
|
||||
echo "Creating empty commit with correct commit message."
|
||||
echo -n "✘ "
|
||||
git commit --allow-empty --file - <<< "${neovim_message}" | xargs echo -n
|
||||
echo -e "\r✔ " # Replace ✘ with ✔
|
||||
output="$(git commit --allow-empty --file 2>&1 - <<< "${neovim_message}")" &&
|
||||
echo "✔ ${output}" ||
|
||||
(echo "✘ ${output}"; false)
|
||||
|
||||
echo
|
||||
echo "Creating files."
|
||||
@ -118,3 +126,70 @@ echo " to use the text in '${neovim_branch}.pr' as the description of this pull
|
||||
echo
|
||||
echo " See https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim"
|
||||
echo " for more information."
|
||||
}
|
||||
|
||||
list_vim_patches() {
|
||||
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.
|
||||
local vim_commits=$(cd ${VIM_SOURCE_DIR} && \
|
||||
hg log --removed --template='{if(startswith("Added tag", firstline(desc)),
|
||||
"{latesttag}\n",
|
||||
"{if(startswith(\"updated for version\", firstline(desc)),
|
||||
\"\",
|
||||
\"{node}\n\")}")}' -r tip:v7-4-442)
|
||||
# Append remaining vim patches.
|
||||
# Start from 7.4.160, where Neovim was forked.
|
||||
local vim_old_commits=$(cd ${VIM_SOURCE_DIR} && \
|
||||
hg log --removed --template='{if(startswith("Added tag",
|
||||
firstline(desc)),
|
||||
"{latesttag}\n")}' -r v7-4-442:v7-4-161)
|
||||
|
||||
local vim_commit
|
||||
for vim_commit in ${vim_commits} ${vim_old_commits}; do
|
||||
local is_missing
|
||||
if [[ "${vim_commit}" =~ v([0-9]-[0-9]-([0-9]{3,4})) ]]; then
|
||||
local patch_number="${BASH_REMATCH[2]}"
|
||||
# "Proper" Vim patch
|
||||
# Check version.c:
|
||||
is_missing="$(sed -n '/static int included_patches/,/}/p' ${NEOVIM_SOURCE_DIR}/src/nvim/version.c |
|
||||
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:
|
||||
is_missing="$(cd ${NEOVIM_SOURCE_DIR} &&
|
||||
git log -1 --no-merges --grep="vim\-patch:${vim_commit:0:7}" --pretty=format:"false")"
|
||||
fi
|
||||
|
||||
if [[ "${is_missing}" != "false" ]]; then
|
||||
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
|
||||
echo " Examples: './scripts/vim-patch.sh 7.4.487'"
|
||||
echo " './scripts/vim-patch.sh 1e8ebf870720e7b671f98f22d653009826304c4f'"
|
||||
}
|
||||
|
||||
if [[ ${#} != 1 || "${1}" == "--help" ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
get_vim_sources
|
||||
|
||||
if [[ "${1}" == "--list" ]]; then
|
||||
list_vim_patches
|
||||
else
|
||||
get_vim_patch ${1}
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user