feat(vim-patch.sh): -M lists all ported patches

Start from current "v:version".
Exclude reverted patches.
Normalize left-zero-pad patch numbers to avoid grep inverse pattern
file like scripts/vim_na_regexp.txt.
Track reverted patches in vimpatch_token_reverts.txt
because no convention in git-log.

TODO: Track patch numbers per v:version in version.c.
This commit is contained in:
Jan Edmund Lazo
2025-11-17 03:05:05 -05:00
parent 5299967551
commit 361671870e
3 changed files with 50 additions and 23 deletions

View File

@@ -33,7 +33,7 @@ usage() {
echo " -l [git-log opts] List missing Vim patches."
echo " -L [git-log opts] List missing Vim patches (for scripts)."
echo " -m {vim-revision} List previous (older) missing Vim patches."
echo " -M List all merged patch-numbers (at current v:version)."
echo " -M List all merged patch-numbers (since current v:version) in ascending order."
echo " -n List possible N/A Vim patches."
echo " -p {vim-revision} Download and generate a Vim patch. vim-revision"
echo " can be a Vim version (8.1.xxx) or a Git hash."
@@ -570,13 +570,23 @@ list_vimpatch_tokens() {
| sed -nEe 's/^(vim-patch:([0-9]+\.[^ ]+|[0-9a-z]{7,7})).*/\1/p'
}
# Prints all patch-numbers (for the current v:version) for which there is
# a "vim-patch:xxx" token in the Nvim git log.
# Prints all merged patches (since current v:version) in ascending order.
#
# Search "vim-patch:xxx" tokens in the Nvim git log.
# Ignore tokens older than current v:version.
# Left-pad the patch number of "vim-patch:xxx" for stable sort + dedupe.
# Filter reverted Vim tokens.
list_vimpatch_numbers() {
# Transform "vim-patch:X.Y.ZZZZ" to "ZZZZ".
list_vimpatch_tokens | while read -r vimpatch_token; do
echo "$vimpatch_token" | grep -F '8.1.' | sed -Ee 's/.*vim-patch:8\.1\.([0-9a-z]+).*/\1/'
done
local patch_pat='(8\.[12]|9\.[0-9])\.[0-9]{1,4}'
diff "${NVIM_SOURCE_DIR}/scripts/vimpatch_token_reverts.txt" <(
git -C "${NVIM_SOURCE_DIR}" log --format="%s%n%b" -E --grep="^[* ]*vim-patch:${patch_pat}" |
grep -oE "^[* ]*vim-patch:${patch_pat}" |
sed -nEe 's/^[* ]*vim-patch:('"${patch_pat}"').*$/\1/p' |
awk '{split($0, a, "."); printf "%d.%d.%04d\n", a[1], a[2], a[3]}' |
sort |
uniq ) |
grep -e '^> ' |
sed -e 's/^> //'
}
declare -A tokens

View File

@@ -15,31 +15,45 @@ local function systemlist(...)
return rv
end
local function vimpatch_sh_list_numbers()
local function vimpatch_sh_list_tokens()
return systemlist({ { 'bash', '-c', 'scripts/vim-patch.sh -M' } })
end
-- Generates the lines to be inserted into the src/version.c
-- Generates the lines to be inserted into the src/nvim/version.c
-- `included_patches[]` definition.
local function gen_version_c_lines()
-- Set of merged Vim 8.1.zzzz patch numbers.
local merged_patch_numbers = {}
local highest = 0
for _, n in ipairs(vimpatch_sh_list_numbers()) do
n = tonumber(n)
if n then
merged_patch_numbers[n] = true
highest = math.max(highest, n)
-- Sets of merged Vim x.y.zzzz patch numbers.
local merged_patch_sets = {}
for _, token in ipairs(vimpatch_sh_list_tokens()) do
local major_version, minor_version, patch_num = string.match(token, '^(%d+).(%d+).(%d+)$')
local n = tonumber(patch_num)
-- TODO(@janlazo): Allow multiple Vim versions
-- if n then
if n and major_version == '8' and minor_version == '1' then
local major_minor_version = major_version * 100 + minor_version
merged_patch_sets[major_minor_version] = merged_patch_sets[major_minor_version] or {}
table.insert(merged_patch_sets[major_minor_version], n)
end
end
local sorted_versions = {}
for k, _ in pairs(merged_patch_sets) do
table.insert(sorted_versions, k)
end
table.sort(sorted_versions)
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))
for _, major_minor_version in ipairs(sorted_versions) do
-- table.insert(lines, string.format(' // major minor version: %s', major_minor_version))
local patch_set = merged_patch_sets[major_minor_version]
for i = #patch_set, 1, -1 do
local patch = patch_set[i]
table.insert(lines, string.format(' %s,', patch))
if patch > 0 then
local oldest_unmerged_patch = patch_set[i - 1] and (patch_set[i - 1] + 1) or 0
for unmerged_patch = patch -1, oldest_unmerged_patch, -1 do
table.insert(lines, string.format(' // %s,', unmerged_patch))
end
end
end
end

View File

@@ -0,0 +1,3 @@
8.1.2294
9.1.0055
9.2.1731