diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-12-26 03:38:42 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-12-27 12:30:55 +0100 |
commit | 7773bbd0989d798b29486a669775a81cd4ec6d3b (patch) | |
tree | e3a514e9fd13623fcbb16e4806d73de2782df4fc | |
parent | 903ed09a61b15a63c4909d4fad7b098fa2368d1d (diff) | |
download | rneovim-7773bbd0989d798b29486a669775a81cd4ec6d3b.tar.gz rneovim-7773bbd0989d798b29486a669775a81cd4ec6d3b.tar.bz2 rneovim-7773bbd0989d798b29486a669775a81cd4ec6d3b.zip |
vimpatch.lua: automate version.c
Invoke it like this:
VIM_SOURCE_DIR=~/neovim/.vim-src/ nvim -i NONE -u NONE --headless +'luafile ./scripts/vimpatch.lua' +q
-rwxr-xr-x | scripts/vim-patch.sh | 41 | ||||
-rwxr-xr-x | scripts/vimpatch.lua | 67 |
2 files changed, 93 insertions, 15 deletions
diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index b82d21b03e..c6ff280bb5 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -14,25 +14,23 @@ readonly BRANCH_PREFIX="vim-" CREATED_FILES=() usage() { - echo "Helper script for porting Vim patches. For more information, see" + echo "Port Vim patches to Neovim" echo "https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim" echo echo "Usage: ${BASENAME} [-h | -l | -p vim-revision | -r pr-number]" echo echo "Options:" echo " -h Show this message and exit." - echo " -l Show list of missing Vim patches." - echo " -L Print missing Vim patches in machine-readable form." - echo " -p {vim-revision} Download and generate the specified Vim patch." - echo " vim-revision can be a version number '8.0.xxx'" - echo " or a valid Git ref (hash, tag, etc.)." - echo " -P {vim-revision} Download, generate and apply the Vim patch." - echo " -g {vim-revision} Download the Vim patch vim-revision." - echo " vim-revision can be a version number of the " - echo " format '7.4.xxx' or a Git commit hash." - echo " -s Submit a vim-patch pull request to Neovim." - echo " -r {pr-number} Review a vim-patch pull request to Neovim." - echo ' -V Clones the Vim source code to $VIM_SOURCE_DIR.' + echo " -l List missing Vim patches." + echo " -L List missing Vim patches (for scripts)." + echo " -M List all merged patch-numbers (at current v:version)." + echo " -p {vim-revision} Download and generate a Vim patch. vim-revision" + echo " can be a Vim version (8.0.xxx) or a Git hash." + echo " -P {vim-revision} Download, generate and apply a Vim patch." + echo " -g {vim-revision} Download a Vim patch." + echo " -s Create a vim-patch pull request." + echo " -r {pr-number} Review a vim-patch pull request." + echo ' -V Clone the Vim source code to $VIM_SOURCE_DIR.' echo echo ' $VIM_SOURCE_DIR controls where Vim sources are found' echo " (default: '${VIM_SOURCE_DIR_DEFAULT}')" @@ -334,7 +332,7 @@ 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. +# Prints all (sorted) "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. @@ -345,6 +343,15 @@ list_vimpatch_tokens() { | uniq } +# Prints all patch-numbers (for the current v:version) for which there is +# a "vim-patch:xxx" token in the Nvim git log. +list_vimpatch_numbers() { + # Transform "vim-patch:X.Y.ZZZZ" to "ZZZZ". + list_vimpatch_tokens | while read vimpatch_token; do + echo "$vimpatch_token" | grep '8\.0\.' | sed 's/.*vim-patch:8\.0\.\([0-9a-z]\+\).*/\1/' + done +} + # 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 @@ -494,7 +501,7 @@ review_pr() { clean_files } -while getopts "hlLVp:P:g:r:s" opt; do +while getopts "hlLMVp:P:g:r:s" opt; do case ${opt} in h) usage @@ -508,6 +515,10 @@ while getopts "hlLVp:P:g:r:s" opt; do list_missing_vimpatches exit 0 ;; + M) + list_vimpatch_numbers + exit 0 + ;; p) stage_patch "${OPTARG}" exit 0 diff --git a/scripts/vimpatch.lua b/scripts/vimpatch.lua new file mode 100755 index 0000000000..0924f3d718 --- /dev/null +++ b/scripts/vimpatch.lua @@ -0,0 +1,67 @@ +-- Updates version.c list of applied Vim patches. +-- +-- Usage: +-- VIM_SOURCE_DIR=~/neovim/.vim-src/ nvim -i NONE -u NONE --headless +'luafile ./scripts/vimpatch.lua' +q + +local nvim = vim.api + +local function pprint(o) + print(nvim.nvim_call_function('string', { o })) +end + +local function systemlist(...) + local rv = nvim.nvim_call_function('systemlist', ...) + local err = nvim.nvim_get_vvar('shell_error') + local args_str = nvim.nvim_call_function('string', ...) + if 0 ~= err then + error('command failed: '..args_str) + end + return rv +end + +local function vimpatch_sh_list_numbers() + return systemlist( { { 'bash', '-c', 'scripts/vim-patch.sh -M', } } ) +end + +-- Generates the lines to be inserted into the src/version.c +-- `included_patches[]` definition. +local function gen_version_c_lines() + -- Set of merged Vim 8.0.zzzz patch numbers. + local merged_patch_numbers = {} + local highest = 0 + for _, n in ipairs(vimpatch_sh_list_numbers()) do + if n then + merged_patch_numbers[tonumber(n)] = true + highest = math.max(highest, n) + end + end + + local lines = {} + for i = highest, 0, -1 do + local is_merged = (nil ~= merged_patch_numbers[i]) + if is_merged then + table.insert(lines, string.format(' %s,', i)) + else + table.insert(lines, string.format(' // %s,', i)) + end + end + + return lines +end + +local function patch_version_c() + local lines = gen_version_c_lines() + + nvim.nvim_command('silent noswapfile noautocmd edit src/nvim/version.c') + nvim.nvim_command('/static const int included_patches') + -- Delete the existing lines. + nvim.nvim_command('silent normal! j0d/};\rk') + -- Insert the lines. + nvim.nvim_call_function('append', { + nvim.nvim_eval('line(".")'), + lines, + }) + nvim.nvim_command('silent write') +end + +patch_version_c() |