diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2023-06-07 22:30:26 +0100 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | c5152f3e8303d5cb241fc3eb3f339755719c45ad (patch) | |
| tree | 8466591c9e34bfd398dd086a815b4b5f21c22699 /scripts/update-lockfile.lua | |
| parent | fix: expand tiers in ignore_install (diff) | |
| download | nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.tar nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.tar.gz nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.tar.bz2 nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.tar.lz nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.tar.xz nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.tar.zst nvim-treesitter-c5152f3e8303d5cb241fc3eb3f339755719c45ad.zip | |
refactor: use vim.system (#4923)
Diffstat (limited to 'scripts/update-lockfile.lua')
| -rwxr-xr-x | scripts/update-lockfile.lua | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/scripts/update-lockfile.lua b/scripts/update-lockfile.lua index 497f1bc0f..e07cf416f 100755 --- a/scripts/update-lockfile.lua +++ b/scripts/update-lockfile.lua @@ -4,38 +4,53 @@ local util = require('nvim-treesitter.util') -- Load previous lockfile local filename = require('nvim-treesitter.install').get_package_path('lockfile.json') -local lockfile = vim.json.decode(util.read_file(filename)) +-- local old_lockfile = vim.json.decode(util.read_file(filename)) --[[@as table<string,{revision:string}>]] ----@type string? -local skip_lang_string = os.getenv('LOCKFILE_SKIP') -local skip_langs = skip_lang_string and vim.split(skip_lang_string, ',') or {} -vim.print('Skipping languages: ', skip_langs) +---@type table<string,{revision:string}> +local new_lockfile = {} -local sorted_parsers = {} -for k, v in pairs(require('nvim-treesitter.parsers').configs) do - table.insert(sorted_parsers, { name = k, parser = v }) -end -table.sort(sorted_parsers, function(a, b) - return a.name < b.name -end) +local parsers = require('nvim-treesitter.parsers').configs + +local jobs = {} --- @type table<string,SystemObj> -- check for new revisions -for _, v in ipairs(sorted_parsers) do - if not vim.list_contains(skip_langs, v.name) and v.parser.install_info then - local cmd = 'git ls-remote ' .. v.parser.install_info.url - if v.parser.install_info.branch then - cmd = cmd .. ' | grep refs/heads/' .. v.parser.install_info.branch - end - local sha = vim.split(vim.fn.systemlist(cmd)[1], '\t')[1] - lockfile[v.name] = { revision = sha } - print(v.name .. ': ' .. sha) +for k, p in pairs(parsers) do + if not p.install_info then + print('Skipping ' .. k) else - print('Skipping ' .. v.name) + jobs[k] = vim.system({ 'git', 'ls-remote', p.install_info.url }) + end + + if #vim.tbl_keys(jobs) % 100 == 0 or next(parsers, k) == nil then + for name, job in pairs(jobs) do + local stdout = vim.split(job:wait().stdout, '\n') + jobs[name] = nil + + local branch = parsers[name].install_info.branch + + local line = 1 + if branch then + for j, l in ipairs(stdout) do + if l:find(vim.pesc(branch)) then + line = j + break + end + end + end + + local sha = vim.split(stdout[line], '\t')[1] + new_lockfile[name] = { revision = sha } + print(name .. ': ' .. sha) + end end end -lockfile = vim.json.encode(lockfile) +assert(#vim.tbl_keys(jobs) == 0) + +local lockfile_json = vim.json.encode(new_lockfile) --[[@as string]] if vim.fn.executable('jq') == 1 then - lockfile = vim.fn.system('jq --sort-keys', lockfile) + lockfile_json = + assert(vim.system({ 'jq', '--sort-keys' }, { stdin = lockfile_json }):wait().stdout) end -util.write_file(filename, lockfile) + +util.write_file(filename, lockfile_json) |
