Updating plugin loader

This commit is contained in:
Alex Yatskov 2015-02-15 11:19:01 +09:00
parent 29b409c3f3
commit e812bf5427

View File

@ -73,6 +73,7 @@ let s:plug_tab = get(s:, 'plug_tab', -1)
let s:plug_buf = get(s:, 'plug_buf', -1)
let s:mac_gui = has('gui_macvim') && has('gui_running')
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:me = resolve(expand('<sfile>:p'))
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 PlugUpdate call s:update('<bang>' == '!', [<f-args>])
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 PlugDiff call s:diff()
command! -nargs=? -bar PlugSnapshot call s:snapshot(<f-args>)
@ -131,7 +132,7 @@ endfunction
function! s:source(from, ...)
for pattern in a:000
for vim in s:lines(globpath(a:from, pattern))
execute 'source' vim
execute 'source' s:esc(vim)
endfor
endfor
endfunction
@ -234,6 +235,23 @@ function! s:trim(str)
return substitute(a:str, '[\/]\+$', '', '')
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
function! s:rtp(spec)
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 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 rtp = join(map(rtps, 's:escrtp(v:val)'), ',')
let rtp = join(map(rtps, 'escape(v:val, ",")'), ',')
\ . ','.s:middle.','
\ . join(map(afters, 's:escrtp(v:val)'), ',')
\ . join(map(afters, 'escape(v:val, ",")'), ',')
let &rtp = substitute(substitute(rtp, ',,*', ',', 'g'), '^,\|,$', '', 'g')
let s:prtp = &rtp
@ -717,7 +735,7 @@ function! s:update_impl(pull, force, args) abort
\ 'pull': a:pull,
\ 'force': a:force,
\ 'new': {},
\ 'threads': (has('ruby') || s:nvim) ? min([len(todo), threads]) : 1,
\ 'threads': (s:ruby || s:nvim) ? min([len(todo), threads]) : 1,
\ 'bar': '',
\ 'fin': 0
\ }
@ -726,7 +744,7 @@ function! s:update_impl(pull, force, args) abort
call append(0, ['', ''])
normal! 2G
if has('ruby') && s:update.threads > 1
if s:ruby && s:update.threads > 1
try
let imd = &imd
if s:mac_gui
@ -736,7 +754,7 @@ function! s:update_impl(pull, force, args) abort
catch
let lines = getline(4, '$')
let printed = {}
silent 4,$d _
silent! 4,$d _
for line in lines
let name = s:extract_name(line, '.', '')
if empty(name) || !has_key(printed, name)
@ -777,7 +795,7 @@ function! s:job_abort()
for [name, j] in items(s:jobs)
silent! call jobstop(j.jobid)
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
endfor
let s:jobs = {}
@ -901,6 +919,8 @@ function! s:update_vim()
endfunction
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
if empty(s:update.todo)
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 spec = remove(s:update.todo, name)
let pull = s:update.pull
let new = !isdirectory(spec.dir)
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 pull
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)',
\ s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir })
\ 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)',
\ prog, s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir })
else
let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 }
endif
@ -933,7 +952,8 @@ while 1 " Without TCO, Vim stack is bound to explode
endif
else
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.branch),
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
@ -1106,7 +1126,7 @@ function! s:update_ruby()
end
} if VIM::evaluate('s:mac_gui') == 1
progress = iswin ? '' : '--progress'
progress = VIM::evaluate('s:progress_opt(1)')
nthr.times do
mtx.synchronize do
threads << Thread.new {
@ -1187,12 +1207,20 @@ function! s:format_message(bullet, name, message)
endfunction
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
function! s:system(cmd, ...)
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
return system(s:is_win ? '('.cmd.')' : cmd)
try
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
function! s:system_chomp(...)
@ -1252,6 +1280,7 @@ function! s:clean(force)
let allowed = {}
for dir in dirs
let allowed[s:dirpath(fnamemodify(dir, ':h:h'))] = 1
let allowed[dir] = 1
for child in s:glob_dir(dir)
let allowed[child] = 1
@ -1280,7 +1309,7 @@ function! s:clean(force)
if yes
for dir in todo
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
endfor
call append(line('$'), 'Removed.')
@ -1297,11 +1326,11 @@ function! s:upgrade()
redraw
try
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
throw get(s:lines(output), -1, v:shell_error)
endif
elseif has('ruby')
elseif s:ruby
call s:upgrade_using_ruby(new)
else
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"), '',
\ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.s:esc(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)]]
call s:prepare()
@ -1533,11 +1562,12 @@ function! s:snapshot(...) abort
endfor
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)
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
silent execute 'e' fn
silent execute 'e' fne
endif
endfunction