robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1#!/usr/bin/env bash 2 3set -e 4set -u 5# Use privileged mode, which e.g. skips using CDPATH. 6set -p 7# https://www.shellcheck.net/wiki/SC2031 8shopt -s lastpipe 9 10# Ensure that the user has a bash that supports -A 11if [[" ${ BASH_VERSINFO [0]} " -lt 4 ]];then 12 >&2echo "error: script requires bash 4+ (you have ${ BASH_VERSION } )." 13exit 1 14fi 15 16readonlyNVIM_SOURCE_DIR =" ${ NVIM_SOURCE_DIR :-$( cd " $( dirname " ${ BASH_SOURCE [0]} " ) /.." && pwd )} " 17readonlyVIM_SOURCE_DIR_DEFAULT =" ${ NVIM_SOURCE_DIR } /.vim-src" 18readonlyVIM_SOURCE_DIR =" ${ VIM_SOURCE_DIR :-${ VIM_SOURCE_DIR_DEFAULT }} " 19BASENAME =" $( basename " ${0} " ) " 20readonlyBASENAME 21readonlyBRANCH_PREFIX ="vim-" 22readonlyVIMPATCH_RANGE =38fb83585421c45828a4934fc75f7952b2baf116..HEAD 23 24CREATED_FILES =() 25 26usage () { 27echo "Port Vim patches to Neovim" 28echo "https://neovim.io/doc/user/dev_vimpatch.html" 29echo 30echo "Usage: ${ BASENAME } [-h | -l | -p vim-revision | -r pr-number]" 31echo 32echo "Options:" 33echo " -h Show this message and exit." 34echo " -l [git-log opts] List missing Vim patches." 35echo " -L [git-log opts] List missing Vim patches (for scripts)." 36echo " -m {vim-revision} List previous (older) missing Vim patches." 37echo " -M List all merged patch-numbers (since current v:version) in ascending order." 38echo " -n List possible N/A Vim patches." 39echo " -p {vim-revision} Download and generate a Vim patch. vim-revision" 40echo " can be a Vim version (8.1.xxx) or a Git hash." 41echo " -P {vim-revision} Download, generate and apply a Vim patch." 42echo " -g {vim-revision} Download a Vim patch." 43echo " -s [pr args] Create a vim-patch pull request." 44echo " -r {pr-number} Review a vim-patch pull request." 45echo " -V Clone the Vim source code to \$VIM_SOURCE_DIR." 46echo 47echo " \$VIM_SOURCE_DIR controls where Vim sources are found" 48echo " (default: ' ${ VIM_SOURCE_DIR_DEFAULT } ')" 49echo 50echo "Examples:" 51echo 52echo " - List missing patches for a given file (in the Vim source):" 53echo " $ 0 -l -- src/edit.c" 54} 55 56# Run git with inline config to avoid error with developer's .gitconfig. 57_git () { 58 local -agit_args 59git_args =(" $ @" ) 60git -c log.showSignature=false" ${ git_args [@]} " 61} 62 63msg_ok () { 64printf '\e[32m✔\e[0m %s\n' " $ @" 65} 66 67msg_err () { 68printf '\e[31m✘\e[0m %s\n' " $ @" >&2 69} 70 71# Checks if a program is in the user's PATH, and is executable. 72check_executable () { 73test -x " $( command -v " ${ 1 } " ) " 74} 75 76require_executable () { 77if !check_executable " ${ 1 } " ;then 78 >&2echo " ${ BASENAME } : ' ${ 1 } ' not found in PATH or not executable." 79exit 1 80fi 81} 82 83clean_files () { 84if [[${# CREATED_FILES [@]} -eq 0 ]];then 85return 86fi 87 88echo 89echo "Created files:" 90 localfile 91for file in " ${ CREATED_FILES [@]} " ;do 92echo " • ${ file } " 93done 94 95read -p "Delete these files (Y/n)? " -n 1-r reply 96echo 97if [[" ${ reply } " == n ]];then 98echo "You can use 'git clean' to remove these files when you're done." 99else 100rm -- " ${ CREATED_FILES [@]} " 101fi 102} 103 104get_vim_sources () { 105require_executable git 106 107if [[ ! -d${ VIM_SOURCE_DIR } ]];then 108echo "Cloning Vim into: ${ VIM_SOURCE_DIR } " 109git clone https://github.com/vim/vim.git" ${ VIM_SOURCE_DIR } " 110cd " ${ VIM_SOURCE_DIR } " 111elif [[" ${ 1 -} " == update ]];then 112cd " ${ VIM_SOURCE_DIR } " 113if ! [ -d".git" ] \ 114&& ! [" $( git rev-parse --show-toplevel ) " =" ${ VIM_SOURCE_DIR } " ];then 115msg_err " ${ VIM_SOURCE_DIR } does not appear to be a git repository." 116echo " Please remove it and try again." 117exit 1 118fi 119echo "Updating Vim sources: ${ VIM_SOURCE_DIR } " 120if git pull--ff ;then 121msg_ok "Updated Vim sources." 122else 123msg_err "Could not update Vim sources; ignoring error." 124fi 125else 126cd " ${ VIM_SOURCE_DIR } " 127fi 128} 129 130commit_message () { 131if [[" ${ vim_message } " =="vim-patch: ${ vim_version } :" * ]];then 132printf '%s\n\n%s\n\n%s' " ${ vim_message } " " ${ vim_commit_url } " " ${ vim_coauthors } " 133else 134printf 'vim-patch:%s: %s\n\n%s\n\n%s' " ${ vim_version :0:7} " " ${ vim_message } " " ${ vim_commit_url } " " ${ vim_coauthors } " 135fi 136} 137 138find_git_remote () { 139 localgit_remote 140if [[" ${ 1 -} " == fork ]];then 141git_remote =$( git remote -v | awk '$2 !~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}' ) 142else 143git_remote =$( git remote -v | awk '$2 ~ /github.com[:\/]neovim\/neovim/ && $3 == "(fetch)" {print $1; exit}' ) 144fi 145if [[ -z" $ git_remote " ]];then 146git_remote ="origin" 147fi 148echo " $ git_remote " 149} 150 151# Assign variables for a given Vim tag, patch version, or commit. 152# Might exit in case it cannot be found, after updating Vim sources. 153assign_commit_details () { 154 localvim_commit_ref 155if [[${ 1 } =~ v?[0-9]\.[0-9]\.[0-9]{3,4} ]];then 156# Interpret parameter as version number (tag). 157if [[" ${ 1 :0:1} " == v ]];then 158vim_version =" ${ 1 :1} " 159vim_tag =" ${ 1 } " 160else 161vim_version =" ${ 1 } " 162vim_tag ="v ${ 1 } " 163fi 164vim_commit_ref =" $ vim_tag " 165 localmunge_commit_line =true 166else 167# Interpret parameter as commit hash. 168vim_version =" ${ 1 :0:7} " 169vim_tag = 170vim_commit_ref =" $ vim_version " 171 localmunge_commit_line =false 172fi 173 174 localget_vim_commit_cmd ="_git -C ${ VIM_SOURCE_DIR } log -1 --format=%H ${ vim_commit_ref } --" 175vim_commit =$( $ get_vim_commit_cmd 2 >&1) || { 176# Update Vim sources. 177get_vim_sources update 178vim_commit =$( $ get_vim_commit_cmd 2 >&1) || { 179 >&2msg_err "Couldn't find Vim revision ' ${ vim_commit_ref } ': git error: ${ vim_commit } ." 180exit 3 181 } 182 } 183 184vim_commit_url ="https://github.com/vim/vim/commit/ ${ vim_commit } " 185vim_message =" $( _git -C " ${ VIM_SOURCE_DIR } " log -1 --pretty= 'format:%B' " ${ vim_commit } " \ 186| sed -Ee 's/([^A-Za-z0-9])(#[0-9]{1,})/\1vim\/vim\2/g' ) " 187 localvim_coauthor0 188vim_coauthor0 =" $( _git -C " ${ VIM_SOURCE_DIR } " log -1 --pretty= 'format:Co-authored-by: %an <%ae>' " ${ vim_commit } " ) " 189# Extract co-authors from the commit message. 190vim_coauthors =" $( echo " ${ vim_message } " | ( grep -E '^Co-[Aa]uthored-[Bb]y: ' || true ) | ( grep -Fxv " ${ vim_coauthor0 } " || true )) " 191vim_coauthors =" $( echo " ${ vim_coauthor0 } " ; echo " ${ vim_coauthors } " ) " 192# Upstream may credit an AI tool; we don't advertise those, see AGENTS.md. 193vim_coauthors =" $( echo " ${ vim_coauthors } " \ 194| ( grep -Eiv '^Co-authored-by: .*(aider|anthropic|chatgpt|claude|codex|copilot|cursor|devin|gemini|openai|opencode|windsurf)' || true )) " 195# Remove Co-authored-by and Signed-off-by lines from the commit message. 196vim_message =" $( echo " ${ vim_message } " | grep -Ev '^(Co-[Aa]uthored|Signed-[Oo]ff)-[Bb]y: ' ) " 197if [[${ munge_commit_line } =="true" ]];then 198# Remove first line of commit message. 199vim_message =" $( echo " ${ vim_message } " | sed -Ee '1s/^patch /vim-patch:/' ) " 200fi 201patch_file ="vim- ${ vim_version } .patch" 202} 203 204# Patch surgery 205preprocess_patch () { 206 localfile =" $ 1 " 207 localnvim ="nvim -u NONE -n -i NONE --headless" 208 209# Remove Filelist, README 210 localna_files ='Filelist\|README.*' 2112 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/\<\%('" ${ na_files } "'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 212 213# Remove *.proto, Make*, INSTALL*, gui_*, beval.*, some if_*, gvim, libvterm, tee, VisVim, xpm, xxd 214 localna_src ='auto\|configure.*\|GvimExt\|hardcopy.*\|libvterm\|proto\|tee\|VisVim\|xpm\|xxd\|Make.*\|INSTALL.*\|beval.*\|gui.*\|if_cscop\|if_lua\|if_mzsch\|if_olepp\|if_ole\|if_perl\|if_py\|if_ruby\|if_tcl\|if_xcmdsrv' 2152 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/src/\S*\<\%(testdir/\)\@<!\%('" ${ na_src } "'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 216 217# Remove runtime/print/ 218 localna_rt ='print\/.*' 2192 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/runtime/\<\%('" ${ na_rt } "'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 220 221# Remove unwanted Vim doc files. 222 localna_doc ='channel\.txt\|if_cscop\.txt\|netbeans\.txt\|os_\w\+\.txt\|print\.txt\|term\.txt\|testing\.txt\|todo\.txt\|vim9\.txt\|tags\|test_urls\.vim' 2232 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/runtime/doc/\<\%('" ${ na_doc } "'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 224 225# Remove "Last change ..." changes in doc files. 2262 > /dev/null$ nvim --cmd 'set dir=/tmp' +'%s/^@@.*\n.*For Vim version.*Last change.*\n.*For Vim version.*Last change.*//' +w +q" $ file " 227 228# Remove gui, setup, screen dumps, testdir/Make_*.mak files 229 localna_src_testdir ='gui_.*\|Make_amiga\.mak\|Make_dos\.mak\|Make_ming\.mak\|Make_vms\.mms\|dumps/.*\.dump\|setup_gui\.vim' 2302 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/src/testdir/\<\%('" ${ na_src_testdir } "'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 231 232# Remove testdir/test_*.vim files 233 localna_src_testdir ='balloon.*\|behave\.vim\|channel.*\|crypt\.vim\|cscope\.vim\|hardcopy\.vim\|job_fails\.vim\|json\.vim\|listener\.vim\|mzscheme\.vim\|netbeans.*\|paste\.vim\|popupwin.*\|python2\.vim\|pyx2\.vim\|restricted\.vim\|shortpathname\.vim\|sound\.vim\|tcl\.vim\|terminal.*\|xxd\.vim' 2342 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/src/testdir/\<test_\%('" ${ na_src_testdir } "'\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 235 236# Remove runtime/*/testdir/ files 237 localna_runtime_testdir ='.\+' 2382 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/runtime/\f\+/testdir/\%(' ${ na_runtime_testdir } '\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 239 240# Remove N/A src/*.[ch] files: sound.c, version.c 241 localna_src_c ='sound\|version' 2422 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/src/\<\%('" ${ na_src_c } "'\)\.[ch]\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 243 244# Remove some *.po files. #5622 245# Also remove vim.pot which is updated on almost every source change. 246 localna_po ='sjiscorr\.c\|ja\.sjis\.po\|ko\.po\|pl\.cp1250\.po\|pl\.po\|ru\.cp1251\.po\|uk\.cp1251\.po\|zh_CN\.cp936\.po\|zh_CN\.po\|zh_TW\.po\|vim\.pot' 2472 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/src/po/\<\%(' ${ na_po } '\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 248 249# Remove vimrc_example.vim 250 localna_vimrcexample ='vimrc_example\.vim' 2512 > /dev/null$ nvim --cmd 'set dir=/tmp' +'g@^diff --git [ab]/runtime/\<\%(' ${ na_vimrcexample } '\)\>@exe "norm! d/\\v(^diff)|%$\r"' +w +q" $ file " 252 253# Rename src/testdir/ paths to test/old/testdir/ 254LC_ALL =Csed -Ee 's/( [ab])\/src\/testdir/\1\/test\/old\/testdir/g' \ 255" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 256 257# Rename src/ paths to src/nvim/ 258LC_ALL =Csed -Ee 's/( [ab]\/src)/\1\/nvim/g' \ 259" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 260 261# Rename evalfunc.c to eval/funcs.c 262LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/evalfunc\.c/\1\/eval\/funcs.c/g' \ 263" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 264 265# Rename list.c to eval/list.c 266LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/list\.c/\1\/eval\/list.c/g' \ 267" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 268 269# Rename evalvars.c to eval/vars.c 270LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/evalvars\.c/\1\/eval\/vars.c/g' \ 271" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 272 273# Rename userfunc.c to eval/userfunc.c 274LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/userfunc\.c/\1\/eval\/userfunc.c/g' \ 275" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 276 277# Rename evalbuffer.c to eval/buffer.c 278LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/evalbuffer\.c/\1\/eval\/buffer.c/g' \ 279" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 280 281# Rename evalwindow.c to eval/window.c 282LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/evalwindow\.c/\1\/eval\/window.c/g' \ 283" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 284 285# Rename cindent.c to indent_c.c 286LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/cindent\.c/\1\/indent_c.c/g' \ 287" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 288 289# Rename map.c to mapping.c 290LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/map\.c/\1\/mapping.c/g' \ 291" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 292 293# Rename getchar.c to input.c 294LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/getchar\.c/\1\/input.c/g' \ 295" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 296 297# Rename edit.c to insert.c 298LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/edit\.c/\1\/insert.c/g' \ 299" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 300 301# Rename profiler.c to profile.c 302LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/profiler\.c/\1\/profile.c/g' \ 303" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 304 305# Rename regexp_(bt|nfa).c to regexp.c 306LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/regexp_(bt|nfa)\.c/\1\/regexp.c/g' \ 307" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 308 309# Rename scriptfile.c to runtime.c 310LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/scriptfile\.c/\1\/runtime.c/g' \ 311" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 312 313# Rename session.c to ex_session.c 314LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/session\.c/\1\/ex_session.c/g' \ 315" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 316 317# Rename highlight.c to highlight_group.c 318LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/highlight\.c/\1\/highlight_group.c/g' \ 319" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 320 321# Rename locale.c to os/lang.c 322LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/locale\.c/\1\/os\/lang.c/g' \ 323" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 324 325# Rename keymap.h to keycodes.h 326LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/keymap\.h/\1\/keycodes.h/g' \ 327" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 328 329# Rename term.c to keycodes.c 330LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/term\.c/\1\/keycodes.c/g' \ 331" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 332 333# Rename option.h to option_vars.h 334LC_ALL =Csed -Ee 's/( [ab]\/src\/nvim)\/option\.h/\1\/option_vars.h/g' \ 335" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 336 337# Rename runtime/doc/eval.txt to runtime/doc/vimeval.txt 338LC_ALL =Csed -Ee 's/( [ab]\/runtime\/doc)\/eval\.txt/\1\/vimeval.txt/g' \ 339" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 340 341# Rename <lang>.txt to l10n-<lang>.txt 342LC_ALL =Csed -Ee 's/( [ab]\/runtime\/doc)\/(arabic|hebrew|russian|vietnamese)\.txt/\1\/l10n-\2.txt/g' \ 343" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 344 345# Rename version*.txt to news.txt 346LC_ALL =Csed -Ee 's/( [ab]\/runtime\/doc)\/version[0-9]+\.txt/\1\/news.txt/g' \ 347" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 348 349# Rename sponsor.txt to intro.txt 350LC_ALL =Csed -Ee 's/( [ab]\/runtime\/doc)\/sponsor\.txt/\1\/intro.txt/g' \ 351" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 352 353# Rename path to check_colors.vim 354LC_ALL =Csed -Ee 's/( [ab]\/runtime)\/colors\/(tools\/check_colors\.vim)/\1\/\2/g' \ 355" $ file " > " $ file " .tmp&& mv " $ file " .tmp" $ file " 356} 357 358uncrustify_patch () { 359git diff--quiet || { 360 >&2echo 'Vim source working tree dirty, aborting.' 361exit 1 362 } 363 364 localpatch_path =" $ NVIM_SOURCE_DIR " /build/vim_patch 365rm -rf " $ patch_path " 366mkdir -p " $ patch_path " /{a,b} 367 368 localcommit =" $ 1 " 369for file in $( git diff-tree --name-only --no-commit-id -r --diff-filter=a " $ commit " ) ;do 370git --work-tree= " $ patch_path " /a checkout--quiet " $ commit " ~-- " $ file " 371done 372for file in $( git diff-tree --name-only --no-commit-id -r --diff-filter=d " $ commit " ) ;do 373git --work-tree= " $ patch_path " /b checkout--quiet " $ commit " -- " $ file " 374done 375git reset--quiet --hard HEAD 376 377# If the difference are drastic enough uncrustify may need to be used more 378# than once. This is obviously a bug that needs to be fixed on uncrustify's 379# end, but in the meantime this workaround is sufficient. 380for _ in {1..2};do 381" $ NVIM_SOURCE_DIR " /build/usr/bin/uncrustify -c " $ NVIM_SOURCE_DIR " /src/uncrustify.cfg-q --replace --no-backup " $ patch_path " /{a,b}/src/*.[ch] 382done 383 384 (cd " $ patch_path " && (git --no-pager diff--no-index --no-prefix --patch --unified=5 --color=never a/ b/ ||true )) 385} 386 387get_vimpatch () { 388get_vim_sources 389 390assign_commit_details " ${ 1 } " 391 392msg_ok "Found Vim revision ' ${ vim_commit } '." 393 394 localpatch_content 395if check_executable " $ NVIM_SOURCE_DIR " /build/usr/bin/uncrustify;then 396patch_content =" $( uncrustify_patch " ${ vim_commit } " ) " 397else 398patch_content =" $( git --no-pager show --unified=5 --color=never -1 --pretty=medium " ${ vim_commit } " ) " 399fi 400 401cd " ${ NVIM_SOURCE_DIR } " 402 403printf "Creating patch...\n" 404echo " $ patch_content " > " ${ NVIM_SOURCE_DIR } / ${ patch_file } " 405 406printf "Pre-processing patch...\n" 407preprocess_patch " ${ NVIM_SOURCE_DIR } / ${ patch_file } " 408 409msg_ok "Saved patch to ' ${ NVIM_SOURCE_DIR } / ${ patch_file } '." 410} 411 412stage_patch () { 413get_vimpatch " $ 1 " 414 localtry_apply =" ${ 2 :-} " 415 416 localnvim_remote 417nvim_remote =" $( find_git_remote ) " 418 localchecked_out_branch 419checked_out_branch =" $( git rev-parse --abbrev-ref HEAD) " 420 421if [[" ${ checked_out_branch } " ==${ BRANCH_PREFIX } * ]];then 422msg_ok "Current branch ' ${ checked_out_branch } ' seems to be a vim-patch" 423echo " branch; not creating a new branch." 424else 425printf '\nFetching "%s/master".\n' " ${ nvim_remote } " 426if output =" $( git fetch " $ nvim_remote " master 2 >&1) " ;then 427msg_ok " $ output " 428else 429msg_err " $ output " 430exit 1 431fi 432 433 localnvim_branch =" ${ BRANCH_PREFIX }${ vim_version } " 434echo 435echo "Creating new branch ' ${ nvim_branch } ' based on ' ${ nvim_remote } /master'." 436cd " ${ NVIM_SOURCE_DIR } " 437if output =" $( git checkout -b " $ nvim_branch " " $ nvim_remote /master" 2 >&1) " ;then 438msg_ok " $ output " 439else 440msg_err " $ output " 441exit 1 442fi 443fi 444 445printf "\nCreating empty commit with correct commit message.\n" 446if output =" $( commit_message | git commit --allow-empty --file 2 >&1 -) " ;then 447msg_ok " $ output " 448else 449msg_err " $ output " 450exit 1 451fi 452 453 localret =0 454if test -n " $ try_apply " ;then 455if !check_executable patch;then 456printf "\n" 457msg_err "'patch' command not found\n" 458else 459printf "\nApplying patch...\n" 460patch -p1 --fuzz=1 --no-backup-if-mismatch < " ${ patch_file } " ||ret =$ ? 461fi 462printf "\nInstructions:\n Proceed to port the patch.\n" 463else 464printf '\nInstructions:\n Proceed to port the patch.\n Try the "patch" command (or use "%s -P ..." next time):\n patch -p1 < %s\n' " ${ BASENAME } " " ${ patch_file } " 465fi 466 467printf ' 468Stage your changes ("git add ..."), then use "git commit --amend" to commit. 469 470To port more patches (if any) related to %s, 471run "%s" again. 472* Do this only for _related_ patches (otherwise it increases the 473size of the pull request, making it harder to review) 474 475When you are done, try "%s -s" to create the pull request, 476or "%s -s --draft" to create a draft pull request. 477 478See the wiki for more information: 479* https://neovim.io/doc/user/dev_vimpatch.html 480' " ${ vim_version } " " ${ BASENAME } " " ${ BASENAME } " " ${ BASENAME } " 481return $ ret 482} 483 484gh_pr () { 485 localpr_title 486 localpr_body 487pr_title =" $ 1 " 488pr_body =" $ 2 " 489shift 2 490gh pr create--title " ${ pr_title } " --body " ${ pr_body } " " $ @" 491} 492 493git_hub_pr () { 494 localpr_message 495pr_message =" $( printf '%s\n\n%s\n' " $ 1 " " $ 2 " ) " 496shift 2 497git hub pull new-m " ${ pr_message } " " $ @" 498} 499 500submit_pr () { 501require_executable git 502 localpush_first 503push_first =1 504 localsubmit_fn 505if check_executable gh;then 506submit_fn ="gh_pr" 507elif check_executable git-hub;then 508push_first =0 509submit_fn ="git_hub_pr" 510else 511 >&2echo " ${ BASENAME } : 'gh' or 'git-hub' not found in PATH or not executable." 512 >&2echo " Get it here: https://cli.github.com/" 513exit 1 514fi 515 516cd " ${ NVIM_SOURCE_DIR } " 517 localchecked_out_branch 518checked_out_branch =" $( git rev-parse --abbrev-ref HEAD) " 519if [[" ${ checked_out_branch } " !=${ BRANCH_PREFIX } * ]];then 520msg_err "Current branch ' ${ checked_out_branch } ' doesn't seem to be a vim-patch branch." 521exit 1 522fi 523 524 localnvim_remote 525nvim_remote =" $( find_git_remote ) " 526 localpr_body 527pr_body =" $( _git log --grep=vim-patch --reverse --format= '#### %s%n%n%b%n' " ${ nvim_remote } " /master..HEAD) " 528 localpatches 529# Extract just the "vim-patch:X.Y.ZZZZ" or "vim-patch:sha" portion of each log 530patches =(" $( _git log --grep=vim-patch --reverse --format= '%s' " ${ nvim_remote } " /master..HEAD | sed 's/: .*//' ) " ) 531# shellcheck disable=SC2206 532patches =(${ patches [@]//vim-patch:} )# Remove 'vim-patch:' prefix for each item in array. 533 localpr_title =" ${ patches [*]} " # Create space-separated string from array. 534pr_title =" ${ pr_title // /,} " # Replace spaces with commas. 535pr_title =" $( printf 'vim-patch:%s' " ${ pr_title #,} " ) " 536 537if [[$ push_first -ne 0 ]];then 538 localpush_remote 539push_remote =" $( git config --get branch. " ${ checked_out_branch } " .pushRemote || true ) " 540if [[ -z" $ push_remote " ]];then 541push_remote =" $( git config --get remote.pushDefault || true ) " 542if [[ -z" $ push_remote " ]];then 543push_remote =" $( git config --get branch. " ${ checked_out_branch } " .remote || true ) " 544if [[ -z" $ push_remote " ]] || [[" $ push_remote " ==" $ nvim_remote " ]];then 545push_remote =" $( find_git_remote fork) " 546fi 547fi 548fi 549echo "Pushing to ' ${ push_remote } / ${ checked_out_branch } '." 550if output =" $( git push " $ push_remote " " $ checked_out_branch " 2 >&1) " ;then 551msg_ok " $ output " 552else 553msg_err " $ output " 554exit 1 555fi 556 557echo 558fi 559 560echo "Creating pull request." 561if output =" $( $ submit_fn " $ pr_title " " $ pr_body " " $ @" 2 >&1) " ;then 562msg_ok " $ output " 563else 564msg_err " $ output " 565exit 1 566fi 567 568echo 569echo "Cleaning up files." 570 localpatch_file 571for patch_file in " ${ patches [@]} " ;do 572patch_file ="vim- ${ patch_file } .patch" 573if [[ ! -f" ${ NVIM_SOURCE_DIR } / ${ patch_file } " ]];then 574continue 575fi 576rm -- " ${ NVIM_SOURCE_DIR } / ${ patch_file } " 577msg_ok "Removed ' ${ NVIM_SOURCE_DIR } / ${ patch_file } '." 578done 579} 580 581# Prints all (sorted) "vim-patch:xxx" tokens found in the Nvim git log 582# where xxx is Git commit hash, not X.Y.Z version 583list_vimpatch_hashes () { 584 localpatch_pat ='[a-z0-9]{7,}' 585# Use sed…{7,7} to normalize (internal) Git hashes (for tokens caches). 586diff " ${ NVIM_SOURCE_DIR } /scripts/vimpatch_commit_ignore.txt" <( 587_git -C " ${ NVIM_SOURCE_DIR } " log --format= "%H" -E --grep= "vim-patch: $ patch_pat " " $ VIMPATCH_RANGE " 588) | 589grep -e '^> ' | 590sed -e 's/^> //' | 591_git -C " ${ NVIM_SOURCE_DIR } " log--no-walk --stdin \ 592| grep -oE "vim-patch: $ patch_pat " \ 593| grep -v "vim-patch:partial" | 594sed -nEe "s/^vim-patch:( $ patch_pat ).*/\1/p" | 595sort | 596uniq 597} 598 599# Prints all merged patches (since current v:version) in ascending order. 600# 601# Search "vim-patch:xxx" tokens in the Nvim git log. 602# Ignore tokens older than current v:version. 603# Left-pad the patch number of "vim-patch:xxx" for stable sort + dedupe. 604# Filter reverted Vim tokens. 605list_vimpatch_numbers () { 606 localpatch_pat ='(8\.[12]|9\.[0-9])\.[0-9]{1,4}' 607diff " ${ NVIM_SOURCE_DIR } /scripts/vimpatch_commit_ignore.txt" <( 608_git -C " ${ NVIM_SOURCE_DIR } " log --format= "%H" -E --grep= "^[* ]*vim-patch: ${ patch_pat } " " $ VIMPATCH_RANGE " 609) | 610grep -e '^> ' | 611sed -e 's/^> //' | 612_git -C " ${ NVIM_SOURCE_DIR } " log--no-walk --stdin --format= "%s%n%b" | 613grep -oE "^[* ]*vim-patch: ${ patch_pat } " | 614sed -nEe 's/^[* ]*vim-patch:('" ${ patch_pat } "').*$/\1/p' | 615awk '{split($0, a, "."); printf "%d.%d.%04d\n", a[1], a[2], a[3]}' | 616sort | 617uniq 618} 619 620# Prints a newline-delimited list of Vim commits, for use by scripts. 621# "$1": use extended format? (with subject) 622# "$@": extra arguments to git-log. 623list_missing_vimpatches () { 624 localVIM_VERSION_0_DATE git_log_format missing_hashes missing_numbers 625 declare -agit_log_args 626VIM_VERSION_0_DATE =2018-05-17:15:00:00Z 627 628 localextended_format =$ 1 ;shift 629if [[" $ extended_format " == 1 ]];then 630git_log_format ="%s" 631else 632git_log_format ="" 633fi 634 635# Massage arguments for git-log. 636 declare -Agit_log_replacements =( 637 [^\(.*/\)?src/nvim/\(.*\)]="\${BASH_REMATCH[1]}src/\${BASH_REMATCH[2]}" 638 [^\(.*/\)?test/old/\(.*\)]="\${BASH_REMATCH[1]}src/\${BASH_REMATCH[2]}" 639 [^\(.*/\)?\.vim-src/\(.*\)]="\${BASH_REMATCH[2]}" 640 ) 641 locali j 642for i in " $ @" ;do 643for j in " ${! git_log_replacements [@]} " ;do 644if [[" $ i " =~$ j ]];then 645eval "git_log_args+=( ${ git_log_replacements [ $ j ]} )" 646continue 2 647fi 648done 649git_log_args +=(" $ i " ) 650done 651 652missing_numbers =$( _git -C " ${ VIM_SOURCE_DIR } " log --decorate-refs= 'refs/tags/*' --reverse --since= " ${ VIM_VERSION_0_DATE } " --no-walk --tags --format= '%(decorate:prefix=,suffix=,tag=)' " ${ git_log_args [@]} " | 653grep -v -F -f <( list_vimpatch_numbers ) | 654sed -E 's/,.*$//' ) 655missing_hashes =$( _git -C " ${ VIM_SOURCE_DIR } " log --decorate-refs= 'refs/tags/*' --reverse --since= " ${ VIM_VERSION_0_DATE } " --format= '%H%D' " ${ git_log_args [@]} " | 656grep -v -e 'tag:' | 657grep -v -f <( list_vimpatch_hashes | sed -E 's/(.*)/^\1/' )) 658if test -n " ${ git_log_format } " ;then 659 (echo " ${ missing_numbers } " ;echo " ${ missing_hashes } " )| 660_git --no-pager -C " ${ VIM_SOURCE_DIR } " log--decorate-refs= 'refs/tags/*' --reverse --no-walk --stdin --format= "%H%x00%d%x00: ${ git_log_format } " | 661awk -F '\0' '{ print $2 ? $2$3 : $1$3 }' 662else 663echo " ${ missing_numbers } " 664echo " ${ missing_hashes } " 665fi 666} 667 668# Prints a human-formatted list of Vim commits, with instructional messages. 669# Passes "$@" onto list_missing_vimpatches (args for git-log). 670show_vimpatches () { 671get_vim_sources update 672printf "Vim patches missing from Neovim:\n" 673 674 local -Aruntime_commits 675for commit in $( _git -C " ${ VIM_SOURCE_DIR } " log --format= "%H %D" -- runtime | sed -Ee 's/,\? tag: / /g' ) ;do 676runtime_commits [$ commit ]=1 677done 678 679list_missing_vimpatches 1" $ @" | while read -r vim_commit;do 680if [[" ${ runtime_commits [ $ vim_commit ]-} " ]];then 681printf ' • %s (+runtime)\n' " ${ vim_commit } " 682else 683printf ' • %s\n' " ${ vim_commit } " 684fi 685done 686 687cat <<EOF 688 689Instructions: 690To port one of the above patches to Neovim, execute this script with the patch revision as argument and follow the instructions, e.g. 691' ${ BASENAME } -p v8.1.1234', or ' ${ BASENAME } -P v8.1.1234' 692 693NOTE: Please port the _oldest_ patch if you possibly can. 694You can use ' ${ BASENAME } -l path/to/file' to see what patches are missing for a file. 695EOF 696} 697 698list_missing_previous_vimpatches_for_patch () { 699 localfor_vim_patch =" ${ 1 } " 700 localvim_commit vim_tag 701assign_commit_details " ${ for_vim_patch } " 702 703 localfile 704 local -amissing_list 705 local -afnames 706while IFS =read -r line ;do 707fnames +=(" $ line " ) 708done < <( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id --name-only -r " ${ vim_commit } " -- . ':!src/version.c' ) 709 locali =0 710 localn =${# fnames [@]} 711printf '=== getting missing patches for %d files ===\n' " $ n " 712if [[ -z" ${ vim_tag } " ]];then 713printf 'NOTE: "%s" is not a Vim tag - listing all oldest missing patches\n' " ${ for_vim_patch } " >&2 714fi 715for fname in " ${ fnames [@]} " ;do 716i =$((i +1 )) 717printf '[%.*d/%d] %s: ' " ${# n } " " $ i " " $ n " " $ fname " 718 719list_missing_vimpatches 1-- " ${ fname } " | while read -r missing_vim_commit_info;do 720if [[ -z" ${ missing_vim_commit_info } " ]];then 721printf -- "-\r" 722else 723printf -- "-\r" 724 localmissing_vim_commit =" ${ missing_vim_commit_info %%:*} " 725if [[ -z" ${ vim_tag } " ]] || [[" ${ missing_vim_commit } " < " ${ vim_tag } " ]];then 726printf -- "%s\n" " $ missing_vim_commit_info " 727missing_list +=(" $ missing_vim_commit_info " ) 728else 729printf -- "-\r" 730fi 731fi 732done 733done 734 735set +u# Avoid "unbound variable" with bash < 4.4 below. 736if [[ -z" ${ missing_list [*]} " ]];then 737msg_ok 'no missing previous Vim patches' 738set -u 739return 0 740fi 741set -u 742 743 local -amissing_unique 744 localstat 745while IFS =read -r line;do 746 localcommit =" ${ line %%:*} " 747stat =" $( git -C " ${ VIM_SOURCE_DIR } " show --format= --shortstat " ${ commit } " ) " 748missing_unique +=(" $( printf '%s\n %s' " $ line " " $ stat " ) " ) 749done < <( printf '%s\n' " ${ missing_list [@]} " | sort -u ) 750 751msg_err " $( printf '%d missing previous Vim patches:' ${# missing_unique [@]}) " 752printf ' - %s\n' " ${ missing_unique [@]} " 753return 1 754} 755 756review_commit () { 757 localnvim_commit_url =" ${ 1 } " 758 localnvim_patch_url =" ${ nvim_commit_url } .patch" 759 760 localgit_patch_prefix ='Subject: \[PATCH\] ' 761 localnvim_patch 762nvim_patch =" $( curl -Ssf " ${ nvim_patch_url } " ) " 763 localvim_version 764vim_version =" $( head -n 4 <<< " ${ nvim_patch } " | sed -nEe 's/'" ${ git_patch_prefix } "'vim-patch:([a-z0-9.]*)(:.*){0,1}$/\1/p' ) " 765 766echo 767if [[ -n" ${ vim_version } " ]];then 768msg_ok "Detected Vim patch ' ${ vim_version } '." 769else 770msg_err "Could not detect the Vim patch number." 771echo " This script assumes that the PR contains only commits" 772echo " with 'vim-patch:XXX' in their title." 773echo 774printf -- '%s\n\n' " $( head -n 4 <<< " ${ nvim_patch } " ) " 775 localreply 776read -p "Continue reviewing (y/N)? " -n 1-r reply 777if [[" ${ reply } " == y ]];then 778echo 779return 780fi 781exit 1 782fi 783 784assign_commit_details " ${ vim_version } " 785 786echo 787echo "Creating files." 788echo " ${ nvim_patch } " > " ${ NVIM_SOURCE_DIR } /n ${ patch_file } " 789msg_ok "Saved pull request diff to ' ${ NVIM_SOURCE_DIR } /n ${ patch_file } '." 790CREATED_FILES +=(" ${ NVIM_SOURCE_DIR } /n ${ patch_file } " ) 791 792 localnvim ="nvim -u NONE -n -i NONE --headless" 7932 > /dev/null$ nvim --cmd 'set dir=/tmp' +'1,/^$/g/^ /-1join' +w +q" ${ NVIM_SOURCE_DIR } /n ${ patch_file } " 794 795 localexpected_commit_message 796expected_commit_message =" $( commit_message ) " 797 localmessage_length 798message_length =" $( wc -l <<< " ${ expected_commit_message } " ) " 799 localcommit_message 800commit_message =" $( tail -n +4 " ${ NVIM_SOURCE_DIR } /n ${ patch_file } " | head -n " ${ message_length } " ) " 801if [[" ${ commit_message # " $ git_patch_prefix " } " ==" ${ expected_commit_message } " ]];then 802msg_ok "Found expected commit message." 803else 804msg_err "Wrong commit message." 805echo " Expected:" 806echo " ${ expected_commit_message } " 807echo " Actual:" 808echo " ${ commit_message # " $ git_patch_prefix " } " 809fi 810 811get_vimpatch " ${ vim_version } " 812CREATED_FILES +=(" ${ NVIM_SOURCE_DIR } / ${ patch_file } " ) 813 814echo 815echo "Launching nvim." 816nvim -c "cd ${ NVIM_SOURCE_DIR } " \ 817-O " ${ NVIM_SOURCE_DIR } / ${ patch_file } " " ${ NVIM_SOURCE_DIR } /n ${ patch_file } " 818} 819 820review_pr () { 821require_executable curl 822require_executable nvim 823require_executable jq 824 825get_vim_sources 826 827 localpr =" ${ 1 } " 828echo 829echo "Downloading data for pull request # ${ pr } ." 830 831 local -apr_commit_urls 832while IFS =read -r pr_commit_url;do 833pr_commit_urls +=(" $ pr_commit_url " ) 834done < <( curl -Ssf "https://api.github.com/repos/neovim/neovim/pulls/ ${ pr } /commits" \ 835| jq -r '.[].html_url' ) 836 837echo "Found ${# pr_commit_urls [@]} commit(s)." 838 839 localpr_commit_url 840 localreply 841for pr_commit_url in " ${ pr_commit_urls [@]} " ;do 842review_commit " ${ pr_commit_url } " 843if [[" ${ pr_commit_url } " !=" ${ pr_commit_urls [-1]} " ]];then 844read -p "Continue with next commit (Y/n)? " -n 1-r reply 845echo 846if [[" ${ reply } " == n ]];then 847break 848fi 849fi 850done 851 852clean_files 853} 854 855is_na_patch () { 856 localpatch =$ 1 857 localNA_REGEXP =" $ NVIM_SOURCE_DIR /scripts/vim_na_regexp.txt" 858 localNA_FILELIST =" $ NVIM_SOURCE_DIR /scripts/vim_na_files.txt" 859 localNA_HUNKS_C =" $ NVIM_SOURCE_DIR /scripts/vim_na_hunks_c.txt" 860 localNA_HUNKS_H =" $ NVIM_SOURCE_DIR /scripts/vim_na_hunks_h.txt" 861 localNA_HUNKS_HELP =" $ NVIM_SOURCE_DIR /scripts/vim_na_hunks_help.txt" 862 localNA_HUNKS_VIM =" $ NVIM_SOURCE_DIR /scripts/vim_na_hunks_vim.txt" 863 864 localFILES_REMAINING HUNKS HUNK_NUM_FINAL 865FILES_REMAINING =" $( diff <( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b --name-only " $ patch " | grep -v -f " $ NA_REGEXP " ) " $ NA_FILELIST " | 866grep '^<' | sed 's/^< //' ) " ||true 867test -z " $ FILES_REMAINING " && return 0 868 869for file in $ FILES_REMAINING ;do 870case ${ file } in 871 runtime/doc/*.txt| runtime/pack/dist/opt/*/doc/*.txt) 872HUNKS =$( git -c core.attributesfile= " $ NVIM_SOURCE_DIR " /.gitattributes -c 'diff.helphelp.xfuncname=^.*\*[^*[:space:]]+\*$' -C " ${ VIM_SOURCE_DIR } " \ 873diff-tree --no-commit-id -r -b -U0 \ 874'-I^\s+$' \ 875'-I^[-=]+$' \ 876'-I^(Functions:|GUI|Other)\s~$' \ 877'-I^[A-Z]\s+\*\+sodium\*\s+compiled with ' \ 878'-I^\|(ch|popup)_[_a-z]+\(\)\|' \ 879'-I^popup_[_a-z]+\(' \ 880'-I^sodium\s+Compiled with ' \ 881'-I\*\s+For Vim version [0-9]\.[0-9]\.\s+Last change: [0-9]+ [A-Z][a-z]+ [0-9]+' \ 882'-I compiled (with|without) .*\(\|.+\|\) feature\.$' \ 883'-I\{.+ (available|compiled) (with|without) .+\}' \ 884'-I\|(added|changed|patches|version)-[0-9]+\.[0-9]+\|' \ 885'-I\|:(cscope|export|import|redrawtabpanel)\|' \ 886'-I\|52\.6\|' \ 887'-I\|channel-open-[^|]+\|' \ 888'-I\|comment-install\|' \ 889'-I\|os_haiku.txt\|' \ 890'-I\|popup-windows\|' \ 891'-I\|tabpanel\|' \ 892'-I\|xdg\.vim\|' \ 893'-I\sGTK\s?4\s' \ 894'-I\spopup window\s' \ 895'-I\sterm_start\(\)\s' \ 896'-I\-gui=gtk' \ 897" $ patch " -- " ${ file } " ) 898if test -n " $ HUNKS " ;then 899HUNK_NUM_FINAL =$( echo " $ HUNKS " | grep '^@@ .* @@' | sed 's/^@@ .* @@ //' | grep -cv -f " $ NA_HUNKS_HELP " ) 900test " $ HUNK_NUM_FINAL " -ne 0&& return 1 901fi 902 ;; 903 runtime/syntax/vim.vim) 904HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 905'-I^\s+$' \ 906'-I^" Last Change:\s' \ 907'-I^\s*syn\s+keyword\s+(vimCommand|vimFuncName)\s+contained\s+' \ 908'-I^\s*syn\s+keyword\s+vimAutoEvent\s+contained\s+[^U]' \ 909'-I^\s*syn\s+match\s+vimFuncName\s+contained\s+"\\<nvim_' \ 910" $ patch " -- " ${ file } " ) 911test -n " $ HUNKS " && return 1 912 ;; 913 src/po/Make*) 914HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 915'-I^\$\([_A-Z]+\)\.pot:' \ 916" $ patch " -- " ${ file } " ) 917if test -n " $ HUNKS " ;then 918# shellcheck disable=SC2016 919HUNK_NUM_FINAL =$( echo " $ HUNKS " | grep '^@@ .* @@' | sed 's/^@@ .* @@ //' | grep -cv \ 920-e '^\$([_A-Z]\+)\.pot:' \ 921-e '^clean:' \ 922-e '^g\?vim\.desktop:' \ 923) 924test " $ HUNK_NUM_FINAL " -ne 0&& return 1 925fi 926 ;; 927 src/testdir/Makefile) 928HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 929'-IREDIR_TEST_TO_NULL = ' \ 930" $ patch " -- " ${ file } " ) 931test -n " $ HUNKS " && return 1 932 ;; 933 src/testdir/Make_all.mak) 934HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 935'-I\stest8[67]\.out \\$' \ 936" $ patch " -- " ${ file } " ) 937if test -n " $ HUNKS " ;then 938HUNK_NUM_FINAL =$( echo " $ HUNKS " | grep '^@@ .* @@' | sed 's/^@@ .* @@ //' | grep -cv -e '^NEW_TESTS\(\|_RES\) = \\$' ) 939test " $ HUNK_NUM_FINAL " -ne 0&& return 1 940fi 941 ;; 942 src/testdir/*.vim) 943HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 944" $ patch " -- " ${ file } " ) 945if test -n " $ HUNKS " ;then 946HUNK_NUM_FINAL =$( echo " $ HUNKS " | grep '^@@ .* @@' | sed 's/^@@ .* @@ //' | grep -cv -f " $ NA_HUNKS_VIM " ) 947test " $ HUNK_NUM_FINAL " -ne 0&& return 1 948fi 949 ;; 950 *.h) 951HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 952'-I^\s+$' \ 953'-I^\s*/?\*/?$' \ 954'-I^\s*(//|/?\*).*\s([vV]im9|E[0-9]{,4} unused|E[0-9]{4} - |FEAT_|JSON-RPC|channel|job|popup|sound|terminal)' \ 955'-I^#\s*((ifdef|ifndef|undef)|(if|elif)\s.*defined\().*(FEAT_[^_]|USE_GTK)' \ 956'-I^#\s*(else|endif)' \ 957'-I^#\s*define\s+(FEAT|POPUPWIN|XDG|t)_[^_]' \ 958'-I^\s+(&&|\|\|)\s.*defined\(.*FEAT_[^_]' \ 959'-IEVENT_TERMINALWINOPEN' \ 960'-I^#\s*define\s+(ASSIGN_VAR|POPF_CURSORLINE)\s' \ 961'-I^typedef enum \{$' \ 962'-I^\s+(CH_MODE|POPCLOSE)_[A-Z]+,?(\s+//.+)?$' \ 963'-I^\} popclose_T;$' \ 964'-I^EXTERN\schar\s+\*popup_transparent' \ 965'-I^EXTERN\sint\s+[_a-z]+_for_testing\s' \ 966'-I^EXTERN type_T static_types\[' \ 967'-I^EXTERN type_T t_.* INIT[2-9]\(' \ 968'-I^EXTERN\swin_T\s+\*popup_dragwin' \ 969'-I^EXTERN char e_(abstract|const|class|enum|final|interface|public|static|type)_' \ 970'-I^EXTERN char e_.*def_function' \ 971'-I^EXTERN char e_.*enddef' \ 972'-I^EXTERN char e_.*vim9' \ 973'-I^EXTERN char e_[_a-z]+_channel' \ 974'-I^EXTERN char e_cannot_add(_redraw|)_listener_in_listener_callback' \ 975'-I^EXTERN char e_cannot_declare_.*variable_str' \ 976'-I^EXTERN char e_cannot_define_new_.+_as_static' \ 977'-I^EXTERN char e_cannot_listen_on_port' \ 978'-I^EXTERN char e_cannot_open_a_popup_window_to_a_closing_buffer' \ 979'-I^EXTERN char e_cannot_use_a_return_type_with_new' \ 980'-I^EXTERN char e_dictionary_not_set' \ 981'-I^EXTERN char e_dictnull' \ 982'-I^EXTERN char e_gethostbyname_in_channel_' \ 983'-I^EXTERN char e_invalid_identifier_in_defineannotype' \ 984'-I\sINIT\(= .+"E[0-9]+: (Abstract|Const|Class|Enum|Final|Interface|Public|Static|Type) ' \ 985'-I\sINIT\(= .+"E[0-9]+: .*:def ' \ 986'-I\sINIT\(= .+"E[0-9]+: .*enddef"' \ 987'-I\sINIT\(= .+"E[0-9]+: .*([vV]im9|interface)' \ 988'-I\sINIT\(= .+"E[0-9]+: .* (ch|channel)_[_a-z]+\(\)' \ 989'-I\sINIT\(= .+"E649: Invalid identifier name in defineAnnoType' \ 990'-I\sINIT\(= .+"E1016: Cannot declare .* variable: ' \ 991'-I\sINIT\(= .+"E1103: Dictionary not set' \ 992'-I\sINIT\(= .+"E1365: Cannot use a return type with the \\"new\\" function"' \ 993'-I\sINIT\(= .+"E1370: Cannot define a .+ as static' \ 994'-I\sINIT\(= .+"E15[0-9]+: Cannot use .*listener_add in a .* listener callback"' \ 995'-I\sINIT\(= .+"E1551: Cannot open a popup window to a closing buffer' \ 996'-I\sINIT\(= .+"E157[34]: ' \ 997'-I\s(bool|char(|_u)|int)\s+w_popup_image_[_a-zA-Z]+;' \ 998'-I\schar(|_u)\s+\*w_popup_title;' \ 999'-I\sint\s+ch_[_a-zA-Z]+;' \ 1000'-I\sint\s+sv_const;' \ 1001'-I\sint\s+w_(filter_mode|firstline|popup_drag|want_scrollbar);' \ 1002'-I\slist_T\s+\*w_popup_mask;' \ 1003'-I\spopclose_T\sw_popup_close;' \ 1004'-I\s\*?w_popup_prop_[_a-z]+;' \ 1005" $ patch " -- " ${ file } " ) 1006if test -n " $ HUNKS " ;then 1007HUNK_NUM_FINAL =$( echo " $ HUNKS " | grep '^@@ .* @@' | sed 's/^@@ .* @@ //' | grep -cv -f " $ NA_HUNKS_H " ) 1008test " $ HUNK_NUM_FINAL " -ne 0&& return 1 1009fi 1010 ;; 1011 *.c) 1012HUNKS =$( git -C " ${ VIM_SOURCE_DIR } " diff-tree --no-commit-id -r -b -U0 \ 1013'-I^\s+$' \ 1014'-I^\s*/?\*/?$' \ 1015'-I^\s*(//|/?\*).*\s([vV]im9|E[0-9]{4} - |FEAT_|channel|job|popup|sound|terminal|uf_type_list)' \ 1016'-I^#\s*((ifdef|ifndef|undef)|(if|elif)\s.*defined\().*(FEAT_[^_]|USE_GTK)' \ 1017'-I^#\s*(else|endif)' \ 1018'-I^#\s*define\s+(FEAT|POPUPWIN|XDG|t)_[^_]' \ 1019'-I^\s+(&&|\|\|)\s.*defined\(.*FEAT_[^_]' \ 1020'-IEVENT_TERMINALWINOPEN' \ 1021'-I^#\s*include\s+<proto/' \ 1022'-I^\s+\{"ch_[_a-z]+",.*\sFEARG_[1-9],\s+arg[1-9]+_' \ 1023'-I^\s+\{"(popup|prop|sound)_[_a-z]+",.*f_(popup|prop|sound)_[_a-z]+\)?},$' \ 1024'-I^\s+ret_[a-z]+,\s+(JOB|PROP)_FUNC\(f_.+\)},$' \ 1025'-I^\s*(static)?\s(char(|_u)|hashtab_T|int|void)( \*)?$' \ 1026'-I^static\s(char(|_u)|hashtab_T|int|void)\s\*?[^*]+\(.+\);$' \ 1027'-I#\s*define.*ex_ni$' \ 1028'-I[.>]b_p_key' \ 1029'-I[_.>]sc_version = ' \ 1030'-I[_.>]uf_script_ctx_version = ' \ 1031'-I[_.>]uf_type_list' \ 1032'-I = skip_type\(.+\);$' \ 1033'-Icheck_typval_type\(.+\)' \ 1034'-Icrypt_get_method_nr\(.+\)' \ 1035'-Imsg\(.*".*GTK.*"\)' \ 1036'-I\spopup_set_firstline\(.+\);' \ 1037'-I\sredraw_tabpanel =' \ 1038'-I\sterm_focus_change\(.+\);$' \ 1039'-I\supdate_vim9_script_var\(.+\);$' \ 1040'-I\svim_free\(.*w_popup_title\);' \ 1041" $ patch " -- " ${ file } " ) 1042if test -n " $ HUNKS " ;then 1043HUNK_NUM_FINAL =$( echo " $ HUNKS " | grep '^@@ .* @@' | sed 's/^@@ .* @@ //' | grep -cv -f " $ NA_HUNKS_C " ) 1044test " $ HUNK_NUM_FINAL " -ne 0&& return 1 1045fi 1046 ;; 1047 *) 1048return 1 1049 ;; 1050esac 1051done 1052 1053return 0 1054} 1055 1056list_na_patches () { 1057list_missing_vimpatches 0| while read -r patch;do 1058if is_na_patch " $ patch " ;then 1059if (echo " $ patch " | grep -q '^v[0-9]\.[0-9]\.[0-9]' )&& _git -C " ${ VIM_SOURCE_DIR } " show-ref--exists "refs/tags/ $ patch " 2 > /dev/null;then 1060echo "vim-patch: ${ patch :1} : $( _git -C " ${ VIM_SOURCE_DIR } " log -1 --format= "%s" " $ patch " ) " 1061else 1062echo "vim-patch: $( _git -C " ${ VIM_SOURCE_DIR } " log -1 --oneline " $ patch " ) " 1063fi 1064fi 1065done 1066} 1067 1068while getopts "hlLmnMVp:P:g:r:s" opt;do 1069case ${ opt } in 1070 h) 1071usage 1072exit 0 1073 ;; 1074 l) 1075shift # remove opt 1076show_vimpatches " $ @" 1077exit 0 1078 ;; 1079 L) 1080shift # remove opt 1081list_missing_vimpatches 0" $ @" 1082exit 0 1083 ;; 1084 M) 1085list_vimpatch_numbers 1086exit 0 1087 ;; 1088 m) 1089shift # remove opt 1090list_missing_previous_vimpatches_for_patch " $ @" 1091exit 0 1092 ;; 1093 n) 1094list_na_patches 1095exit 0 1096 ;; 1097 p) 1098stage_patch " ${ OPTARG } " 1099exit 1100 ;; 1101 P) 1102stage_patch " ${ OPTARG } " TRY_APPLY 1103exit 0 1104 ;; 1105 g) 1106get_vimpatch " ${ OPTARG } " 1107exit 0 1108 ;; 1109 r) 1110review_pr " ${ OPTARG } " 1111exit 0 1112 ;; 1113 s) 1114shift # remove opt 1115submit_pr " $ @" 1116exit 0 1117 ;; 1118 V) 1119get_vim_sources update 1120exit 0 1121 ;; 1122 *) 1123exit 1 1124 ;; 1125esac 1126done 1127 1128usage 1129 1130# vim: et sw=2