mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	vim-patch.sh: extract list_vimpatch_tokens()
Use streams instead of for-loop (20x speedup for list_vimpatch_tokens).
This commit is contained in:
		| @@ -174,7 +174,7 @@ preprocess_patch() { | ||||
|   # Rename src/ paths to src/nvim/ | ||||
|   LC_ALL=C sed -e 's/\( [ab]\/src\)/\1\/nvim/g' \ | ||||
|     "$file" > "$file".tmp && mv "$file".tmp "$file" | ||||
|  | ||||
|  | ||||
|   # Rename path to matchit plugin. | ||||
|   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" | ||||
| @@ -200,7 +200,7 @@ get_vim_patch() { | ||||
|   echo "$patch_content" > "${NVIM_SOURCE_DIR}/${patch_file}" | ||||
|  | ||||
|   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" | ||||
| } | ||||
| @@ -329,31 +329,43 @@ submit_pr() { | ||||
|     patch_file="vim-${patch_file}.patch" | ||||
|     if [[ ! -f "${NVIM_SOURCE_DIR}/${patch_file}" ]]; then | ||||
|       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,}' \ | ||||
|     rm -- "${NVIM_SOURCE_DIR}/${patch_file}" | ||||
|     echo "✔ Removed '${NVIM_SOURCE_DIR}/${patch_file}'." | ||||
|   done | ||||
| } | ||||
|     | sed 's/.*\(vim-patch:[.0-9a-z]\+\).*/\1/' \ | ||||
|     | sort \ | ||||
|     | uniq | ||||
| } | ||||
| list_vim_patches() { | ||||
|   # Get missing Vim commits | ||||
|   local vim_commits | ||||
|  | ||||
| # 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 | ||||
|   tokens="$(cd "${NVIM_SOURCE_DIR}" && git log -E --grep='vim-patch:[^ ]+' | grep 'vim-patch')" | ||||
|   tokens="$(for i in $tokens ; do echo "$i" | grep -E 'vim-patch:[^ ]{7}' | sed 's/.*\(vim-patch:[.0-9a-z]\+\).*/\1/' ; done)" | ||||
|  | ||||
|   local vim_commit | ||||
|   # Find all "vim-patch:xxx" tokens in the Nvim git log. | ||||
|   tokens="$(list_vimpatch_tokens)" | ||||
|  | ||||
|   # Get missing Vim commits | ||||
|   vim_commits="$(list_vim_commits)" | ||||
|   for vim_commit in ${vim_commits}; do | ||||
|     # 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" ] \ | ||||
|       && 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 | ||||
|       # Vim version number (not commit hash). | ||||
|       # Check for vim-patch:<tag> (not commit hash). | ||||
| @@ -363,11 +375,11 @@ list_vim_patches() { | ||||
|     fi | ||||
|  | ||||
|     if ! [ "$is_missing" = "false" ]; then | ||||
|       echo "${vim_commit}" | ||||
|       echo "${vim_commit}" | ||||
|     fi | ||||
|   done | ||||
| } | ||||
|  | ||||
|  | ||||
| # Prints a human-formatted list of Vim commits, with instructional messages. | ||||
| show_vimpatches() { | ||||
|   get_vim_sources | ||||
| @@ -441,7 +453,7 @@ review_commit() { | ||||
|     echo "${commit_message#${git_patch_prefix}}" | ||||
|   fi | ||||
|  | ||||
|   echo | ||||
|   echo | ||||
|   echo "Creating files." | ||||
|   echo "${nvim_patch}" > "${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 | ||||
|   case ${opt} in | ||||
|   case ${opt} in | ||||
|     h) | ||||
|       usage | ||||
|       exit 0 | ||||
|       ;; | ||||
|       ;; | ||||
|     l) | ||||
|       show_vimpatches | ||||
|       exit 0 | ||||
| @@ -505,7 +517,7 @@ while getopts "hlLVp:P:g:r:s" opt; do | ||||
|     p) | ||||
|       stage_patch "${OPTARG}" | ||||
|       exit 0 | ||||
|       ;; | ||||
|       ;; | ||||
|     P) | ||||
|       stage_patch "${OPTARG}" TRY_APPLY | ||||
|       exit 0 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes