Skip to content

Commit 903ed09

Browse files
committed
vim-patch.sh: extract list_vimpatch_tokens()
Use streams instead of for-loop (20x speedup for list_vimpatch_tokens).
1 parent 973bd10 commit 903ed09

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

scripts/vim-patch.sh

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ preprocess_patch() {
174174
"$file" > "$file".tmp && mv "$file".tmp "$file"
175175
}
176176

177-
get_vim_patch() {
177+
get_vimpatch() {
178178
get_vim_sources
179179

180180
assign_commit_details "${1}"
@@ -200,7 +200,7 @@ get_vim_patch() {
200200
}
201201

202202
stage_patch() {
203-
get_vim_patch "$1"
203+
get_vimpatch "$1"
204204
local try_apply="${2:-}"
205205

206206
local git_remote
@@ -329,31 +329,43 @@ submit_pr() {
329329
done
330330
}
331331

332-
# Prints a newline-delimited list of Vim commits, for use by scripts.
333-
list_vim_patches() {
334-
# Get missing Vim commits
335-
local vim_commits
336-
vim_commits="$(cd "${VIM_SOURCE_DIR}" && git log --reverse --format='%H' v8.0.0000..HEAD)"
332+
# Gets all Vim commits since the "start" commit.
333+
list_vim_commits() { (
334+
cd "${VIM_SOURCE_DIR}" && git log --reverse --format='%H' v8.0.0000..HEAD
335+
) }
337336

338-
# Find all "vim-patch:xxx" tokens in the Nvim git log.
337+
# Prints all "vim-patch:xxx" tokens found in the Nvim git log.
338+
list_vimpatch_tokens() {
339339
local tokens
340+
# Find all "vim-patch:xxx" tokens in the Nvim git log.
340341
tokens="$(cd "${NVIM_SOURCE_DIR}" && git log -E --grep='vim-patch:[^ ]+' | grep 'vim-patch')"
341-
tokens="$(for i in $tokens ; do echo "$i" | grep -E 'vim-patch:[^ ]{7}' | sed 's/.*\(vim-patch:[.0-9a-z]\+\).*/\1/' ; done)"
342+
echo "$tokens" | grep -E 'vim-patch:[^ ,{]{7,}' \
343+
| sed 's/.*\(vim-patch:[.0-9a-z]\+\).*/\1/' \
344+
| sort \
345+
| uniq
346+
}
347+
348+
# Prints a newline-delimited list of Vim commits, for use by scripts.
349+
list_missing_vimpatches() {
350+
local tokens vim_commit vim_commits is_missing vim_tag patch_number
351+
352+
# Find all "vim-patch:xxx" tokens in the Nvim git log.
353+
tokens="$(list_vimpatch_tokens)"
342354

343-
local vim_commit
355+
# Get missing Vim commits
356+
vim_commits="$(list_vim_commits)"
344357
for vim_commit in ${vim_commits}; do
345-
local is_missing
346-
local vim_tag
347-
# This fails for untagged commits (e.g., runtime file updates) so mask the return status
348-
vim_tag="$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null)" || true
349-
if [[ -n "${vim_tag}" ]]; then
358+
# Check for vim-patch:<commit_hash> (usually runtime updates).
359+
is_missing="$(echo "$tokens" | >/dev/null 2>&1 grep "vim\-patch:${vim_commit:0:7}" && echo false || echo true)"
360+
361+
if ! [ "$is_missing" = "false" ] \
362+
&& vim_tag="$(cd "${VIM_SOURCE_DIR}" && git describe --tags --exact-match "${vim_commit}" 2>/dev/null)"
363+
then
350364
# Vim version number (not commit hash).
351-
local patch_number="${vim_tag:1}" # "v7.4.0001" => "7.4.0001"
365+
# Check for vim-patch:<tag> (not commit hash).
366+
patch_number="${vim_tag:1}" # "v7.4.0001" => "7.4.0001"
352367
is_missing="$(echo "$tokens" | >/dev/null 2>&1 grep "vim\-patch:${patch_number}" && echo false || echo true)"
353368
vim_commit="${vim_tag#v}"
354-
else
355-
# Untagged Vim patch (e.g. runtime updates).
356-
is_missing="$(echo "$tokens" | >/dev/null 2>&1 grep "vim\-patch:${vim_commit:0:7}" && echo false || echo true)"
357369
fi
358370

359371
if ! [ "$is_missing" = "false" ]; then
@@ -363,11 +375,11 @@ list_vim_patches() {
363375
}
364376

365377
# Prints a human-formatted list of Vim commits, with instructional messages.
366-
show_vim_patches() {
378+
show_vimpatches() {
367379
get_vim_sources
368380
printf "\nVim patches missing from Neovim:\n"
369381

370-
list_vim_patches | while read vim_commit; do
382+
list_missing_vimpatches | while read vim_commit; do
371383
if (cd "${VIM_SOURCE_DIR}" && git --no-pager show --color=never --name-only "v${vim_commit}" 2>/dev/null) | grep -q ^runtime; then
372384
printf "${vim_commit} (+runtime)\n"
373385
else
@@ -441,7 +453,7 @@ review_commit() {
441453
echo "✔ Saved pull request diff to '${NVIM_SOURCE_DIR}/n${patch_file}'."
442454
CREATED_FILES+=("${NVIM_SOURCE_DIR}/n${patch_file}")
443455

444-
get_vim_patch "${vim_version}"
456+
get_vimpatch "${vim_version}"
445457
CREATED_FILES+=("${NVIM_SOURCE_DIR}/${patch_file}")
446458

447459
echo
@@ -489,11 +501,11 @@ while getopts "hlLVp:P:g:r:s" opt; do
489501
exit 0
490502
;;
491503
l)
492-
show_vim_patches
504+
show_vimpatches
493505
exit 0
494506
;;
495507
L)
496-
list_vim_patches
508+
list_missing_vimpatches
497509
exit 0
498510
;;
499511
p)
@@ -505,7 +517,7 @@ while getopts "hlLVp:P:g:r:s" opt; do
505517
exit 0
506518
;;
507519
g)
508-
get_vim_patch "${OPTARG}"
520+
get_vimpatch "${OPTARG}"
509521
exit 0
510522
;;
511523
r)

0 commit comments

Comments
 (0)