mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
scripts/vim-patch.sh: Misc. improvements #2108
- Check for mercurial before using it - Make 'Merging patches...' wiki page easier to copy - Use `basename` instead of assuming the user is running vim-patch.sh via the repo root - Appease shellcheck by quoting path variables - Remove unneeded variable quoting inside [[ ]] blocks - Don't unconditionally 'exit 1' '-h' and '--help' are both recognized options, so current behavior is misleading.
This commit is contained in:
parent
3946810d54
commit
08d2f7b562
@ -3,37 +3,38 @@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
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}}"
|
||||
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}")"
|
||||
|
||||
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} [option]"
|
||||
>&2 echo " ${0} vim-revision"
|
||||
>&2 echo
|
||||
>&2 echo "Options:"
|
||||
>&2 echo " -h, --help Show this message."
|
||||
>&2 echo " -l, --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}'."
|
||||
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
|
||||
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
|
||||
echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored."
|
||||
echo "The default is '${VIM_SOURCE_DIR_DEFAULT}'."
|
||||
}
|
||||
|
||||
get_vim_sources() {
|
||||
echo "Retrieving Vim sources."
|
||||
if [[ ! -d ${VIM_SOURCE_DIR} ]]; then
|
||||
echo "Cloning Vim sources into '${VIM_SOURCE_DIR}'."
|
||||
hg clone https://code.google.com/p/vim ${VIM_SOURCE_DIR}
|
||||
cd ${VIM_SOURCE_DIR}
|
||||
hg clone https://code.google.com/p/vim "${VIM_SOURCE_DIR}"
|
||||
cd "${VIM_SOURCE_DIR}"
|
||||
else
|
||||
echo "Updating Vim sources in '${VIM_SOURCE_DIR}'."
|
||||
cd ${VIM_SOURCE_DIR}
|
||||
cd "${VIM_SOURCE_DIR}"
|
||||
hg pull --update &&
|
||||
echo "✔ Updated Vim sources." ||
|
||||
echo "✘ Could not update Vim sources; ignoring error."
|
||||
@ -41,7 +42,7 @@ get_vim_sources() {
|
||||
}
|
||||
|
||||
get_vim_patch() {
|
||||
if [[ "${1}" =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then
|
||||
if [[ ${1} =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then
|
||||
# Interpret parameter as version number.
|
||||
vim_version="${1}"
|
||||
vim_commit="v${1//./-}"
|
||||
@ -53,7 +54,7 @@ get_vim_patch() {
|
||||
strip_commit_line=false
|
||||
fi
|
||||
|
||||
hg log --rev ${vim_commit} >/dev/null 2>&1 || {
|
||||
hg log --rev "${vim_commit}" >/dev/null 2>&1 || {
|
||||
>&2 echo "✘ Couldn't find Vim revision '${vim_commit}'."
|
||||
exit 3
|
||||
}
|
||||
@ -61,13 +62,13 @@ get_vim_patch() {
|
||||
echo "✔ Found Vim revision '${vim_commit}'."
|
||||
|
||||
# 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
|
||||
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} \
|
||||
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}
|
||||
@ -91,7 +92,7 @@ get_vim_patch() {
|
||||
|
||||
echo
|
||||
echo "Creating Git branch."
|
||||
cd ${NEOVIM_SOURCE_DIR}
|
||||
cd "${NEOVIM_SOURCE_DIR}"
|
||||
output="$(git checkout -b "${neovim_branch}" 2>&1)" &&
|
||||
echo "✔ ${output}" ||
|
||||
(echo "✘ ${output}"; false)
|
||||
@ -104,11 +105,11 @@ get_vim_patch() {
|
||||
|
||||
echo
|
||||
echo "Creating files."
|
||||
echo "${vim_diff}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff
|
||||
echo "${vim_diff}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff"
|
||||
echo "✔ Saved patch to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'."
|
||||
echo "${vim_full}" > ${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch
|
||||
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
|
||||
echo "${neovim_pr}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr"
|
||||
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."
|
||||
|
||||
@ -136,7 +137,7 @@ list_vim_patches() {
|
||||
# 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} && \
|
||||
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)),
|
||||
@ -144,7 +145,7 @@ list_vim_patches() {
|
||||
\"{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} && \
|
||||
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)
|
||||
@ -152,21 +153,21 @@ list_vim_patches() {
|
||||
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
|
||||
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 |
|
||||
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} &&
|
||||
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
|
||||
if [[ ${is_missing} != "false" ]]; then
|
||||
echo " • ${vim_commit}"
|
||||
fi
|
||||
done
|
||||
@ -177,19 +178,28 @@ list_vim_patches() {
|
||||
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'"
|
||||
echo " Examples: '${BASENAME} 7.4.487'"
|
||||
echo " '${BASENAME} 1e8ebf870720e7b671f98f22d653009826304c4f'"
|
||||
}
|
||||
|
||||
if [[ ${#} != 1 || "${1}" == "--help" || "${1}" == "-h" ]]; then
|
||||
if [[ ${1} == "--help" || ${1} == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
elif [[ ${#} != 1 ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
if [[ "${1}" == "--list" || "${1}" == "-l" ]]; then
|
||||
if [[ ${1} == "--list" || ${1} == "-l" ]]; then
|
||||
list_vim_patches
|
||||
else
|
||||
get_vim_patch ${1}
|
||||
get_vim_patch "${1}"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user