vim-patch: handle tags, pass through git-log options (#10140)

* scripts/vim-patch.sh: fall back to "origin" for remote

Without this, it would fail e.g. with a locally cloned repo of Neovim.

* scripts/vim-patch.sh: assign_commit_details: handle tags  [ci skip]

- Handle "v" prefix from Vim tags.
- Exit in case of error therein already.

* -l/-L: pass through git-log options  [ci skip]

This allows for only listing missing patches for a given Vim file:

> scripts/vim-patch.sh -L src/edit.c
This commit is contained in:
Daniel Hahler
2019-07-30 07:45:59 +02:00
committed by GitHub
parent 35ec60f73a
commit 213b6b5c28

View File

@@ -21,8 +21,8 @@ usage() {
echo echo
echo "Options:" echo "Options:"
echo " -h Show this message and exit." echo " -h Show this message and exit."
echo " -l List missing Vim patches." echo " -l [git-log opts] List missing Vim patches."
echo " -L List missing Vim patches (for scripts)." echo " -L [git-log opts] List missing Vim patches (for scripts)."
echo " -M List all merged patch-numbers (at current v:version)." echo " -M List all merged patch-numbers (at current v:version)."
echo " -p {vim-revision} Download and generate a Vim patch. vim-revision" echo " -p {vim-revision} Download and generate a Vim patch. vim-revision"
echo " can be a Vim version (8.0.xxx) or a Git hash." echo " can be a Vim version (8.0.xxx) or a Git hash."
@@ -34,6 +34,11 @@ usage() {
echo echo
echo " \$VIM_SOURCE_DIR controls where Vim sources are found" echo " \$VIM_SOURCE_DIR controls where Vim sources are found"
echo " (default: '${VIM_SOURCE_DIR_DEFAULT}')" echo " (default: '${VIM_SOURCE_DIR_DEFAULT}')"
echo
echo "Examples:"
echo
echo " - List missing patches for a given file (in the Vim source):"
echo " $0 -l -- src/edit.c"
} }
msg_ok() { msg_ok() {
@@ -110,30 +115,44 @@ commit_message() {
} }
find_git_remote() { find_git_remote() {
git remote -v \ git_remote=$(git remote -v \
| awk '$2 ~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}' | awk '$2 ~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}')
if [[ -z "$git_remote" ]]; then
git_remote="origin"
fi
echo "$git_remote"
} }
# Assign variables for a given Vim tag, patch version, or commit.
# Might exit in case it cannot be found.
assign_commit_details() { assign_commit_details() {
if [[ ${1} =~ [0-9]\.[0-9]\.[0-9]{3,4} ]]; then local vim_commit_ref
if [[ ${1} =~ v?[0-9]\.[0-9]\.[0-9]{3,4} ]]; then
# Interpret parameter as version number (tag). # Interpret parameter as version number (tag).
vim_version="${1}" if [[ "${1:0:1}" == v ]]; then
vim_tag="v${1}" vim_version="${1:1}"
vim_commit=$(cd "${VIM_SOURCE_DIR}" \ vim_tag="${1}"
&& git log -1 --format="%H" "${vim_tag}") else
vim_version="${1}"
vim_tag="v${1}"
fi
vim_commit_ref="$vim_tag"
local munge_commit_line=true local munge_commit_line=true
else else
# Interpret parameter as commit hash. # Interpret parameter as commit hash.
vim_version="${1:0:12}" vim_version="${1:0:12}"
vim_tag= vim_tag=
vim_commit=$(cd "${VIM_SOURCE_DIR}" \ vim_commit_ref="$vim_version"
&& git log -1 --format="%H" "${vim_version}")
local munge_commit_line=false local munge_commit_line=false
fi fi
vim_commit=$(git -C "${VIM_SOURCE_DIR}" log -1 --format="%H" "${vim_commit_ref}" --) || {
>&2 msg_err "Couldn't find Vim revision '${vim_commit_ref}'."
exit 3
}
vim_commit_url="https://github.com/vim/vim/commit/${vim_commit}" vim_commit_url="https://github.com/vim/vim/commit/${vim_commit}"
vim_message="$(cd "${VIM_SOURCE_DIR}" \ vim_message="$(git -C "${VIM_SOURCE_DIR}" log -1 --pretty='format:%B' "${vim_commit}" \
&& git log -1 --pretty='format:%B' "${vim_commit}" \
| sed -e 's/\(#[0-9]\{1,\}\)/vim\/vim\1/g')" | sed -e 's/\(#[0-9]\{1,\}\)/vim\/vim\1/g')"
if [[ ${munge_commit_line} == "true" ]]; then if [[ ${munge_commit_line} == "true" ]]; then
# Remove first line of commit message. # Remove first line of commit message.
@@ -198,10 +217,6 @@ get_vimpatch() {
LC_ALL=C sed -e 's@\( [ab]/runtime\)/colors/\(tools/check_colors.vim\)@\1/\2@g' \ LC_ALL=C sed -e 's@\( [ab]/runtime\)/colors/\(tools/check_colors.vim\)@\1/\2@g' \
"$file" > "$file".tmp && mv "$file".tmp "$file" "$file" > "$file".tmp && mv "$file".tmp "$file"
} }
get_vimpatch() {
get_vim_sources
get_vimpatch() { get_vimpatch() {
get_vim_sources get_vim_sources
@@ -357,7 +372,7 @@ submit_pr() {
continue continue
fi fi
rm -- "${NVIM_SOURCE_DIR}/${patch_file}" rm -- "${NVIM_SOURCE_DIR}/${patch_file}"
msg_ok "Removed '${NVIM_SOURCE_DIR}/${patch_file}'." msg_ok "Removed '${NVIM_SOURCE_DIR}/${patch_file}'."
done done
} }
@@ -380,6 +395,7 @@ list_vimpatch_numbers() {
# a "vim-patch:xxx" token in the Nvim git log. # a "vim-patch:xxx" token in the Nvim git log.
list_vimpatch_numbers() { list_vimpatch_numbers() {
# Transform "vim-patch:X.Y.ZZZZ" to "ZZZZ". # Transform "vim-patch:X.Y.ZZZZ" to "ZZZZ".
list_vimpatch_tokens | while read -r vimpatch_token; do
echo "$vimpatch_token" | grep '8\.0\.' | sed 's/.*vim-patch:8\.0\.\([0-9a-z]\+\).*/\1/' echo "$vimpatch_token" | grep '8\.0\.' | sed 's/.*vim-patch:8\.0\.\([0-9a-z]\+\).*/\1/'
done done
} }
@@ -404,7 +420,7 @@ list_missing_vimpatches() {
--shell) --shell)
)" )"
# Exit in case of errors from the above eval (empty vim_commit_tags). # Exit in case of errors from the above eval (empty vim_commit_tags).
if ! (( "${#vim_commit_tags[@]}" )); then if ! (( "${#vim_commit_tags[@]}" )); then
msg_err "Could not get Vim commits/tags." msg_err "Could not get Vim commits/tags."
exit 1 exit 1
fi fi
@@ -435,7 +451,7 @@ show_vimpatches() {
show_vimpatches() { show_vimpatches() {
get_vim_sources get_vim_sources
printf "\nVim patches missing from Neovim:\n" printf "\nVim patches missing from Neovim:\n"
local -A runtime_commits local -A runtime_commits
for commit in $(git -C "${VIM_SOURCE_DIR}" log --format="%H %D" -- runtime | sed 's/,\? tag: / /g'); do for commit in $(git -C "${VIM_SOURCE_DIR}" log --format="%H %D" -- runtime | sed 's/,\? tag: / /g'); do
runtime_commits[$commit]=1 runtime_commits[$commit]=1
@@ -561,11 +577,13 @@ while getopts "hlLMVp:P:g:r:s" opt; do
} }
while getopts "hlLMVp:P:g:r:s" opt; do while getopts "hlLMVp:P:g:r:s" opt; do
case ${opt} in case ${opt} in
h)
usage usage
exit 0 exit 0
;; ;;
;; l)
shift # remove opt
show_vimpatches "$@" show_vimpatches "$@"
exit 0 exit 0
;; ;;