Updating plugin loader
This commit is contained in:
parent
29b409c3f3
commit
e812bf5427
@ -73,6 +73,7 @@ let s:plug_tab = get(s:, 'plug_tab', -1)
|
|||||||
let s:plug_buf = get(s:, 'plug_buf', -1)
|
let s:plug_buf = get(s:, 'plug_buf', -1)
|
||||||
let s:mac_gui = has('gui_macvim') && has('gui_running')
|
let s:mac_gui = has('gui_macvim') && has('gui_running')
|
||||||
let s:is_win = has('win32') || has('win64')
|
let s:is_win = has('win32') || has('win64')
|
||||||
|
let s:ruby = has('ruby') && (v:version >= 703 || v:version == 702 && has('patch374'))
|
||||||
let s:nvim = has('nvim') && !s:is_win
|
let s:nvim = has('nvim') && !s:is_win
|
||||||
let s:me = resolve(expand('<sfile>:p'))
|
let s:me = resolve(expand('<sfile>:p'))
|
||||||
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
|
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
|
||||||
@ -114,7 +115,7 @@ function! s:define_commands()
|
|||||||
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', [<f-args>])
|
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', [<f-args>])
|
||||||
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('<bang>' == '!', [<f-args>])
|
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('<bang>' == '!', [<f-args>])
|
||||||
command! -nargs=0 -bar -bang PlugClean call s:clean('<bang>' == '!')
|
command! -nargs=0 -bar -bang PlugClean call s:clean('<bang>' == '!')
|
||||||
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:me | endif
|
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(s:me) | endif
|
||||||
command! -nargs=0 -bar PlugStatus call s:status()
|
command! -nargs=0 -bar PlugStatus call s:status()
|
||||||
command! -nargs=0 -bar PlugDiff call s:diff()
|
command! -nargs=0 -bar PlugDiff call s:diff()
|
||||||
command! -nargs=? -bar PlugSnapshot call s:snapshot(<f-args>)
|
command! -nargs=? -bar PlugSnapshot call s:snapshot(<f-args>)
|
||||||
@ -131,7 +132,7 @@ endfunction
|
|||||||
function! s:source(from, ...)
|
function! s:source(from, ...)
|
||||||
for pattern in a:000
|
for pattern in a:000
|
||||||
for vim in s:lines(globpath(a:from, pattern))
|
for vim in s:lines(globpath(a:from, pattern))
|
||||||
execute 'source' vim
|
execute 'source' s:esc(vim)
|
||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
@ -234,6 +235,23 @@ function! s:trim(str)
|
|||||||
return substitute(a:str, '[\/]\+$', '', '')
|
return substitute(a:str, '[\/]\+$', '', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:git_version_requirement(...)
|
||||||
|
let s:git_version = get(s:, 'git_version',
|
||||||
|
\ map(split(split(s:system('git --version'))[-1], '\.'), 'str2nr(v:val)'))
|
||||||
|
for idx in range(0, a:0 - 1)
|
||||||
|
let v = get(s:git_version, idx, 0)
|
||||||
|
if v < a:000[idx] | return 0
|
||||||
|
elseif v > a:000[idx] | return 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:progress_opt(base)
|
||||||
|
return a:base && !s:is_win &&
|
||||||
|
\ s:git_version_requirement(1, 7, 1) ? '--progress' : ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
if s:is_win
|
if s:is_win
|
||||||
function! s:rtp(spec)
|
function! s:rtp(spec)
|
||||||
return s:path(a:spec.dir . get(a:spec, 'rtp', ''))
|
return s:path(a:spec.dir . get(a:spec, 'rtp', ''))
|
||||||
@ -309,9 +327,9 @@ function! s:reorg_rtp()
|
|||||||
let s:middle = get(s:, 'middle', &rtp)
|
let s:middle = get(s:, 'middle', &rtp)
|
||||||
let rtps = map(s:loaded_names(), 's:rtp(g:plugs[v:val])')
|
let rtps = map(s:loaded_names(), 's:rtp(g:plugs[v:val])')
|
||||||
let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), 'isdirectory(v:val)')
|
let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), 'isdirectory(v:val)')
|
||||||
let rtp = join(map(rtps, 's:escrtp(v:val)'), ',')
|
let rtp = join(map(rtps, 'escape(v:val, ",")'), ',')
|
||||||
\ . ','.s:middle.','
|
\ . ','.s:middle.','
|
||||||
\ . join(map(afters, 's:escrtp(v:val)'), ',')
|
\ . join(map(afters, 'escape(v:val, ",")'), ',')
|
||||||
let &rtp = substitute(substitute(rtp, ',,*', ',', 'g'), '^,\|,$', '', 'g')
|
let &rtp = substitute(substitute(rtp, ',,*', ',', 'g'), '^,\|,$', '', 'g')
|
||||||
let s:prtp = &rtp
|
let s:prtp = &rtp
|
||||||
|
|
||||||
@ -717,7 +735,7 @@ function! s:update_impl(pull, force, args) abort
|
|||||||
\ 'pull': a:pull,
|
\ 'pull': a:pull,
|
||||||
\ 'force': a:force,
|
\ 'force': a:force,
|
||||||
\ 'new': {},
|
\ 'new': {},
|
||||||
\ 'threads': (has('ruby') || s:nvim) ? min([len(todo), threads]) : 1,
|
\ 'threads': (s:ruby || s:nvim) ? min([len(todo), threads]) : 1,
|
||||||
\ 'bar': '',
|
\ 'bar': '',
|
||||||
\ 'fin': 0
|
\ 'fin': 0
|
||||||
\ }
|
\ }
|
||||||
@ -726,7 +744,7 @@ function! s:update_impl(pull, force, args) abort
|
|||||||
call append(0, ['', ''])
|
call append(0, ['', ''])
|
||||||
normal! 2G
|
normal! 2G
|
||||||
|
|
||||||
if has('ruby') && s:update.threads > 1
|
if s:ruby && s:update.threads > 1
|
||||||
try
|
try
|
||||||
let imd = &imd
|
let imd = &imd
|
||||||
if s:mac_gui
|
if s:mac_gui
|
||||||
@ -736,7 +754,7 @@ function! s:update_impl(pull, force, args) abort
|
|||||||
catch
|
catch
|
||||||
let lines = getline(4, '$')
|
let lines = getline(4, '$')
|
||||||
let printed = {}
|
let printed = {}
|
||||||
silent 4,$d _
|
silent! 4,$d _
|
||||||
for line in lines
|
for line in lines
|
||||||
let name = s:extract_name(line, '.', '')
|
let name = s:extract_name(line, '.', '')
|
||||||
if empty(name) || !has_key(printed, name)
|
if empty(name) || !has_key(printed, name)
|
||||||
@ -777,7 +795,7 @@ function! s:job_abort()
|
|||||||
for [name, j] in items(s:jobs)
|
for [name, j] in items(s:jobs)
|
||||||
silent! call jobstop(j.jobid)
|
silent! call jobstop(j.jobid)
|
||||||
if j.new
|
if j.new
|
||||||
call system('rm -rf ' . s:shellesc(g:plugs[name].dir))
|
call s:system('rm -rf ' . s:shellesc(g:plugs[name].dir))
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
let s:jobs = {}
|
let s:jobs = {}
|
||||||
@ -901,6 +919,8 @@ function! s:update_vim()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:tick()
|
function! s:tick()
|
||||||
|
let pull = s:update.pull
|
||||||
|
let prog = s:progress_opt(s:nvim)
|
||||||
while 1 " Without TCO, Vim stack is bound to explode
|
while 1 " Without TCO, Vim stack is bound to explode
|
||||||
if empty(s:update.todo)
|
if empty(s:update.todo)
|
||||||
if empty(s:jobs) && !s:update.fin
|
if empty(s:jobs) && !s:update.fin
|
||||||
@ -912,7 +932,6 @@ while 1 " Without TCO, Vim stack is bound to explode
|
|||||||
|
|
||||||
let name = keys(s:update.todo)[0]
|
let name = keys(s:update.todo)[0]
|
||||||
let spec = remove(s:update.todo, name)
|
let spec = remove(s:update.todo, name)
|
||||||
let pull = s:update.pull
|
|
||||||
let new = !isdirectory(spec.dir)
|
let new = !isdirectory(spec.dir)
|
||||||
|
|
||||||
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
|
call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...')
|
||||||
@ -923,8 +942,8 @@ while 1 " Without TCO, Vim stack is bound to explode
|
|||||||
if valid
|
if valid
|
||||||
if pull
|
if pull
|
||||||
call s:spawn(name,
|
call s:spawn(name,
|
||||||
\ printf('(git fetch --progress 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only origin/%s 2>&1 && git submodule update --init --recursive 2>&1)',
|
\ printf('(git fetch %s 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only origin/%s 2>&1 && git submodule update --init --recursive 2>&1)',
|
||||||
\ s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir })
|
\ prog, s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir })
|
||||||
else
|
else
|
||||||
let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 }
|
let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 }
|
||||||
endif
|
endif
|
||||||
@ -933,7 +952,8 @@ while 1 " Without TCO, Vim stack is bound to explode
|
|||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
call s:spawn(name,
|
call s:spawn(name,
|
||||||
\ printf('git clone --progress --recursive %s -b %s %s 2>&1',
|
\ printf('git clone %s --recursive %s -b %s %s 2>&1',
|
||||||
|
\ prog,
|
||||||
\ s:shellesc(spec.uri),
|
\ s:shellesc(spec.uri),
|
||||||
\ s:shellesc(spec.branch),
|
\ s:shellesc(spec.branch),
|
||||||
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
|
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
|
||||||
@ -1106,7 +1126,7 @@ function! s:update_ruby()
|
|||||||
end
|
end
|
||||||
} if VIM::evaluate('s:mac_gui') == 1
|
} if VIM::evaluate('s:mac_gui') == 1
|
||||||
|
|
||||||
progress = iswin ? '' : '--progress'
|
progress = VIM::evaluate('s:progress_opt(1)')
|
||||||
nthr.times do
|
nthr.times do
|
||||||
mtx.synchronize do
|
mtx.synchronize do
|
||||||
threads << Thread.new {
|
threads << Thread.new {
|
||||||
@ -1187,12 +1207,20 @@ function! s:format_message(bullet, name, message)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:with_cd(cmd, dir)
|
function! s:with_cd(cmd, dir)
|
||||||
return 'cd '.s:esc(a:dir).' && '.a:cmd
|
return (s:is_win ? 'cd /d ' : 'cd ').s:esc(a:dir).' && '.a:cmd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:system(cmd, ...)
|
function! s:system(cmd, ...)
|
||||||
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
|
try
|
||||||
return system(s:is_win ? '('.cmd.')' : cmd)
|
let sh = &shell
|
||||||
|
if !s:is_win
|
||||||
|
set shell=sh
|
||||||
|
endif
|
||||||
|
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
|
||||||
|
return system(s:is_win ? '('.cmd.')' : cmd)
|
||||||
|
finally
|
||||||
|
let &shell = sh
|
||||||
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:system_chomp(...)
|
function! s:system_chomp(...)
|
||||||
@ -1252,6 +1280,7 @@ function! s:clean(force)
|
|||||||
|
|
||||||
let allowed = {}
|
let allowed = {}
|
||||||
for dir in dirs
|
for dir in dirs
|
||||||
|
let allowed[s:dirpath(fnamemodify(dir, ':h:h'))] = 1
|
||||||
let allowed[dir] = 1
|
let allowed[dir] = 1
|
||||||
for child in s:glob_dir(dir)
|
for child in s:glob_dir(dir)
|
||||||
let allowed[child] = 1
|
let allowed[child] = 1
|
||||||
@ -1280,7 +1309,7 @@ function! s:clean(force)
|
|||||||
if yes
|
if yes
|
||||||
for dir in todo
|
for dir in todo
|
||||||
if isdirectory(dir)
|
if isdirectory(dir)
|
||||||
call system((s:is_win ? 'rmdir /S /Q ' : 'rm -rf ') . s:shellesc(dir))
|
call s:system((s:is_win ? 'rmdir /S /Q ' : 'rm -rf ') . s:shellesc(dir))
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
call append(line('$'), 'Removed.')
|
call append(line('$'), 'Removed.')
|
||||||
@ -1297,11 +1326,11 @@ function! s:upgrade()
|
|||||||
redraw
|
redraw
|
||||||
try
|
try
|
||||||
if executable('curl')
|
if executable('curl')
|
||||||
let output = system(printf('curl -fLo %s %s', s:shellesc(new), s:plug_src))
|
let output = s:system(printf('curl -fLo %s %s', s:shellesc(new), s:plug_src))
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
throw get(s:lines(output), -1, v:shell_error)
|
throw get(s:lines(output), -1, v:shell_error)
|
||||||
endif
|
endif
|
||||||
elseif has('ruby')
|
elseif s:ruby
|
||||||
call s:upgrade_using_ruby(new)
|
call s:upgrade_using_ruby(new)
|
||||||
else
|
else
|
||||||
return s:err('curl executable or ruby support not found')
|
return s:err('curl executable or ruby support not found')
|
||||||
@ -1510,7 +1539,7 @@ function! s:snapshot(...) abort
|
|||||||
\ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '',
|
\ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '',
|
||||||
\ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.s:esc(home)]] :
|
\ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.s:esc(home)]] :
|
||||||
\ ['sh', '$PLUG_HOME',
|
\ ['sh', '$PLUG_HOME',
|
||||||
\ ['#!/bin/bash', '# Generated by vim-plug', '# '.strftime("%c"), '',
|
\ ['#!/bin/sh', '# Generated by vim-plug', '# '.strftime("%c"), '',
|
||||||
\ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]]
|
\ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]]
|
||||||
|
|
||||||
call s:prepare()
|
call s:prepare()
|
||||||
@ -1533,11 +1562,12 @@ function! s:snapshot(...) abort
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
if a:0 > 0
|
if a:0 > 0
|
||||||
let fn = s:esc(expand(a:1))
|
let fn = expand(a:1)
|
||||||
|
let fne = s:esc(fn)
|
||||||
call writefile(getline(1, '$'), fn)
|
call writefile(getline(1, '$'), fn)
|
||||||
if !s:is_win | call system('chmod +x ' . fn) | endif
|
if !s:is_win | call s:system('chmod +x ' . fne) | endif
|
||||||
echo 'Saved to '.a:1
|
echo 'Saved to '.a:1
|
||||||
silent execute 'e' fn
|
silent execute 'e' fne
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user