vim-patch.sh: extract list_vimpatch_tokens()

Use streams instead of for-loop (20x speedup for list_vimpatch_tokens).
This commit is contained in:
Justin M. Keyes
2017-12-16 21:38:53 +01:00
parent 973bd10a12
commit 903ed09a61

View File

@@ -174,7 +174,7 @@ preprocess_patch() {
# Rename src/ paths to src/nvim/ # Rename src/ paths to src/nvim/
LC_ALL=C sed -e 's/\( [ab]\/src\)/\1\/nvim/g' \ LC_ALL=C sed -e 's/\( [ab]\/src\)/\1\/nvim/g' \
"$file" > "$file".tmp && mv "$file".tmp "$file" "$file" > "$file".tmp && mv "$file".tmp "$file"
# Rename path to matchit plugin. # Rename path to matchit plugin.
LC_ALL=C sed -e 's@\( [ab]/runtime\)/pack/dist/opt/matchit/\(plugin/matchit.vim\)@\1/\2@g' \ LC_ALL=C sed -e 's@\( [ab]/runtime\)/pack/dist/opt/matchit/\(plugin/matchit.vim\)@\1/\2@g' \
"$file" > "$file".tmp && mv "$file".tmp "$file" "$file" > "$file".tmp && mv "$file".tmp "$file"
@@ -200,7 +200,7 @@ get_vim_patch() {
echo "$patch_content" > "${NVIM_SOURCE_DIR}/${patch_file}" echo "$patch_content" > "${NVIM_SOURCE_DIR}/${patch_file}"
printf "Pre-processing patch...\n" printf "Pre-processing patch...\n"
preprocess_patch "${NVIM_SOURCE_DIR}/${patch_file}" preprocess_patch "${NVIM_SOURCE_DIR}/${patch_file}"
printf "✔ Saved patch to '${NVIM_SOURCE_DIR}/${patch_file}'.\n" printf "✔ Saved patch to '${NVIM_SOURCE_DIR}/${patch_file}'.\n"
} }
@@ -329,31 +329,43 @@ submit_pr() {
patch_file="vim-${patch_file}.patch" patch_file="vim-${patch_file}.patch"
if [[ ! -f "${NVIM_SOURCE_DIR}/${patch_file}" ]]; then if [[ ! -f "${NVIM_SOURCE_DIR}/${patch_file}" ]]; then
continue continue
fi
rm -- "${NVIM_SOURCE_DIR}/${patch_file}"
echo "✔ Removed '${NVIM_SOURCE_DIR}/${patch_file}'."
done
}
# Gets all Vim commits since the "start" commit.
list_vim_commits() { (
cd "${VIM_SOURCE_DIR}" && git log --reverse --format='%H' v8.0.0000..HEAD
) }
# Prints all "vim-patch:xxx" tokens found in the Nvim git log.
list_vimpatch_tokens() {
local tokens
# Find all "vim-patch:xxx" tokens in the Nvim git log.
tokens="$(cd "${NVIM_SOURCE_DIR}" && git log -E --grep='vim-patch:[^ ]+' | grep 'vim-patch')"
echo "$tokens" | grep -E 'vim-patch:[^ ,{]{7,}' \ echo "$tokens" | grep -E 'vim-patch:[^ ,{]{7,}' \
rm -- "${NVIM_SOURCE_DIR}/${patch_file}" | sed 's/.*\(vim-patch:[.0-9a-z]\+\).*/\1/' \
echo "✔ Removed '${NVIM_SOURCE_DIR}/${patch_file}'." | sort \
done
}
| uniq | uniq
} }
list_vim_patches() {
# Get missing Vim commits
local vim_commits
# Prints a newline-delimited list of Vim commits, for use by scripts. # Prints a newline-delimited list of Vim commits, for use by scripts.
list_missing_vimpatches() {
local tokens vim_commit vim_commits is_missing vim_tag patch_number
local tokens # Find all "vim-patch:xxx" tokens in the Nvim git log.
tokens="$(cd "${NVIM_SOURCE_DIR}" && git log -E --grep='vim-patch:[^ ]+' | grep 'vim-patch')" tokens="$(list_vimpatch_tokens)"
tokens="$(for i in $tokens ; do echo "$i" | grep -E 'vim-patch:[^ ]{7}' | sed 's/.*\(vim-patch:[.0-9a-z]\+\).*/\1/' ; done)"
# Get missing Vim commits
local vim_commit vim_commits="$(list_vim_commits)"
for vim_commit in ${vim_commits}; do
# Check for vim-patch:<commit_hash> (usually runtime updates). # Check for vim-patch:<commit_hash> (usually runtime updates).
local is_missing is_missing="$(echo "$tokens" | >/dev/null 2>&1 grep "vim\-patch:${vim_commit:0:7}" && echo false || echo true)"
if ! [ "$is_missing" = "false" ] \ if ! [ "$is_missing" = "false" ] \
&& vim_tag="$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null)" && vim_tag="$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null)"
vim_tag="$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null)" || true
if [[ -n "${vim_tag}" ]]; then
# Vim version number (not commit hash).
then then
# Vim version number (not commit hash). # Vim version number (not commit hash).
# Check for vim-patch:<tag> (not commit hash). # Check for vim-patch:<tag> (not commit hash).
@@ -363,11 +375,11 @@ list_vim_patches() {
fi fi
if ! [ "$is_missing" = "false" ]; then if ! [ "$is_missing" = "false" ]; then
echo "${vim_commit}" echo "${vim_commit}"
fi fi
done done
} }
# Prints a human-formatted list of Vim commits, with instructional messages. # Prints a human-formatted list of Vim commits, with instructional messages.
show_vimpatches() { show_vimpatches() {
get_vim_sources get_vim_sources
@@ -441,7 +453,7 @@ review_commit() {
echo "${commit_message#${git_patch_prefix}}" echo "${commit_message#${git_patch_prefix}}"
fi fi
echo echo
echo "Creating files." echo "Creating files."
echo "${nvim_patch}" > "${NVIM_SOURCE_DIR}/n${patch_file}" echo "${nvim_patch}" > "${NVIM_SOURCE_DIR}/n${patch_file}"
echo "✔ Saved pull request diff to '${NVIM_SOURCE_DIR}/n${patch_file}'." echo "✔ Saved pull request diff to '${NVIM_SOURCE_DIR}/n${patch_file}'."
@@ -489,11 +501,11 @@ while getopts "hlLVp:P:g:r:s" opt; do
} }
while getopts "hlLVp:P:g:r:s" opt; do while getopts "hlLVp:P:g:r:s" opt; do
case ${opt} in case ${opt} in
h) h)
usage usage
exit 0 exit 0
;; ;;
l) l)
show_vimpatches show_vimpatches
exit 0 exit 0
@@ -505,7 +517,7 @@ while getopts "hlLVp:P:g:r:s" opt; do
p) p)
stage_patch "${OPTARG}" stage_patch "${OPTARG}"
exit 0 exit 0
;; ;;
P) P)
stage_patch "${OPTARG}" TRY_APPLY stage_patch "${OPTARG}" TRY_APPLY
exit 0 exit 0