mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
vim-patch.sh: list related missing Vim patches [ci skip] #11514
* scripts/vim-patch.sh: factor out _set_tokens_and_tags This allows for caching `$tokens` and `$vim_commit_tags`, which will become relevant with the next commit adding `list_missing_previous_vimpatches_for_patch`.
This commit is contained in:

committed by
Justin M. Keyes

parent
b3686b1597
commit
34abe8fd23
@@ -395,13 +395,48 @@ list_vimpatch_numbers() {
|
|||||||
# Prints all patch-numbers (for the current v:version) for which there is
|
# Prints all patch-numbers (for the current v:version) for which there is
|
||||||
# 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".
|
||||||
|
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/'
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
declare -A tokens
|
||||||
|
declare -A vim_commit_tags
|
||||||
|
|
||||||
|
_set_tokens_and_tags() {
|
||||||
|
if [[ -n "${tokens[*]}" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find all "vim-patch:xxx" tokens in the Nvim git log.
|
||||||
|
for token in $(list_vimpatch_tokens); do
|
||||||
|
tokens[$token]=1
|
||||||
|
done
|
||||||
|
|
||||||
|
# Create an associative array mapping Vim commits to tags.
|
||||||
|
eval "vim_commit_tags=(
|
||||||
|
$(git -C "${VIM_SOURCE_DIR}" for-each-ref refs/tags \
|
||||||
|
--format '[%(objectname)]=%(refname:strip=2)' \
|
||||||
|
--sort='-*authordate' \
|
||||||
|
--shell)
|
||||||
|
)"
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
# Prints a newline-delimited list of Vim commits, for use by scripts.
|
||||||
|
# "$1": use extended format?
|
||||||
|
# "$@" is passed to list_vim_commits, as extra arguments to git-log.
|
||||||
|
list_missing_vimpatches() {
|
||||||
|
local -a missing_vim_patches=()
|
||||||
|
_set_missing_vimpatches "$@"
|
||||||
|
for line in "${missing_vim_patches[@]}"; do
|
||||||
|
printf '%s\n' "$line"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Prints a newline-delimited list of Vim commits, for use by scripts.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sets / appends to missing_vim_patches (useful to avoid a subshell when
|
# Sets / appends to missing_vim_patches (useful to avoid a subshell when
|
||||||
@@ -416,6 +451,7 @@ list_missing_vimpatches() {
|
|||||||
else
|
else
|
||||||
git_log_args=("--format=%H")
|
git_log_args=("--format=%H")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Massage arguments for git-log.
|
# Massage arguments for git-log.
|
||||||
declare -A git_log_replacements=(
|
declare -A git_log_replacements=(
|
||||||
[^\(.*/\)?src/nvim/\(.*\)]="\${BASH_REMATCH[1]}src/\${BASH_REMATCH[2]}"
|
[^\(.*/\)?src/nvim/\(.*\)]="\${BASH_REMATCH[1]}src/\${BASH_REMATCH[2]}"
|
||||||
@@ -426,23 +462,7 @@ list_missing_vimpatches() {
|
|||||||
for j in "${!git_log_replacements[@]}"; do
|
for j in "${!git_log_replacements[@]}"; do
|
||||||
if [[ "$i" =~ $j ]]; then
|
if [[ "$i" =~ $j ]]; then
|
||||||
eval "git_log_args+=(${git_log_replacements[$j]})"
|
eval "git_log_args+=(${git_log_replacements[$j]})"
|
||||||
continue 2
|
continue 2
|
||||||
fi
|
|
||||||
done
|
|
||||||
git_log_args+=("$i")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Find all "vim-patch:xxx" tokens in the Nvim git log.
|
|
||||||
for token in $(list_vimpatch_tokens); do
|
|
||||||
tokens[$token]=1
|
|
||||||
done
|
|
||||||
|
|
||||||
# Create an associative array mapping Vim commits to tags.
|
|
||||||
eval "declare -A vim_commit_tags=(
|
|
||||||
$(git -C "${VIM_SOURCE_DIR}" for-each-ref refs/tags \
|
|
||||||
--format '[%(objectname)]=%(refname:strip=2)' \
|
|
||||||
--sort='-*authordate' \
|
|
||||||
--shell)
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
git_log_args+=("$i")
|
git_log_args+=("$i")
|
||||||
@@ -474,9 +494,9 @@ list_missing_vimpatches() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
vim_tag="${vim_commit_tags[$vim_commit]-}"
|
vim_tag="${vim_commit_tags[$vim_commit]-}"
|
||||||
if [[ -n "$vim_tag" ]]; then
|
if [[ -n "$vim_tag" ]]; then
|
||||||
# Check for vim-patch:<tag> (not commit hash).
|
# Check for vim-patch:<tag> (not commit hash).
|
||||||
patch_number="vim-patch:${vim_tag:1}" # "v7.4.0001" => "7.4.0001"
|
patch_number="vim-patch:${vim_tag:1}" # "v7.4.0001" => "7.4.0001"
|
||||||
if [[ "${tokens[$patch_number]-}" ]]; then
|
if [[ "${tokens[$patch_number]-}" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@@ -512,6 +532,59 @@ Instructions:
|
|||||||
Instructions:
|
Instructions:
|
||||||
To port one of the above patches to Neovim, execute this script with the patch revision as argument and follow the instructions, e.g.
|
To port one of the above patches to Neovim, execute this script with the patch revision as argument and follow the instructions, e.g.
|
||||||
'${BASENAME} -p v8.0.1234', or '${BASENAME} -P v8.0.1234'
|
'${BASENAME} -p v8.0.1234', or '${BASENAME} -P v8.0.1234'
|
||||||
|
|
||||||
|
NOTE: Please port the _oldest_ patch if you possibly can.
|
||||||
|
You can use '${BASENAME} -l path/to/file' to see what patches are missing for a file.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
list_missing_previous_vimpatches_for_patch() {
|
||||||
|
local for_vim_patch="${1}"
|
||||||
|
local vim_commit vim_tag
|
||||||
|
assign_commit_details "${for_vim_patch}"
|
||||||
|
|
||||||
|
local file
|
||||||
|
local -a missing_list
|
||||||
|
local -a fnames
|
||||||
|
while IFS= read -r line ; do
|
||||||
|
fnames+=("$line")
|
||||||
|
done < <(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id --name-only -r "${vim_commit}")
|
||||||
|
local i=0
|
||||||
|
local n=${#fnames[@]}
|
||||||
|
printf '=== getting missing patches for %d files ===\n' "$n"
|
||||||
|
if [[ -z "${vim_tag}" ]]; then
|
||||||
|
printf 'NOTE: "%s" is not a Vim tag - listing all oldest missing patches\n' "${for_vim_patch}" >&2
|
||||||
|
fi
|
||||||
|
for fname in "${fnames[@]}"; do
|
||||||
|
i=$(( i+1 ))
|
||||||
|
printf '[%.*d/%d] %s: ' "${#n}" "$i" "$n" "$fname"
|
||||||
|
|
||||||
|
local -a missing_vim_patches=()
|
||||||
|
_set_missing_vimpatches 1 -- "${fname}"
|
||||||
|
|
||||||
|
local missing_vim_commit_info="${missing_vim_patches[0]}"
|
||||||
|
if [[ -z "${missing_vim_commit_info}" ]]; then
|
||||||
|
printf -- "-\n"
|
||||||
|
else
|
||||||
|
local missing_vim_commit="${missing_vim_commit_info%%:*}"
|
||||||
|
if [[ -z "${vim_tag}" ]] || [[ "${missing_vim_commit}" < "${vim_tag}" ]]; then
|
||||||
|
printf -- "%s\n" "$missing_vim_commit_info"
|
||||||
|
missing_list+=("$missing_vim_commit_info")
|
||||||
|
else
|
||||||
|
printf -- "-\n"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "${missing_list[*]}" ]]; then
|
||||||
|
msg_ok 'no missing previous Vim patches'
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local -a missing_unique
|
||||||
|
while IFS= read -r line; do
|
||||||
|
missing_unique+=("$line")
|
||||||
|
done < <(printf '%s\n' "${missing_list[@]}" | sort -u)
|
||||||
|
|
||||||
msg_err "$(printf '%d missing previous Vim patches:' ${#missing_unique[@]})"
|
msg_err "$(printf '%d missing previous Vim patches:' ${#missing_unique[@]})"
|
||||||
printf ' - %s\n' "${missing_unique[@]}"
|
printf ' - %s\n' "${missing_unique[@]}"
|
||||||
@@ -609,7 +682,7 @@ review_pr() {
|
|||||||
if [[ "${reply}" == n ]]; then
|
if [[ "${reply}" == n ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
clean_files
|
clean_files
|
||||||
@@ -629,6 +702,11 @@ while getopts "hlLMVp:P:g:r:s" opt; do
|
|||||||
L)
|
L)
|
||||||
shift # remove opt
|
shift # remove opt
|
||||||
list_missing_vimpatches 0 "$@"
|
list_missing_vimpatches 0 "$@"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
M)
|
||||||
|
list_vimpatch_numbers
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
m)
|
m)
|
||||||
shift # remove opt
|
shift # remove opt
|
||||||
|
Reference in New Issue
Block a user