Spawn multiple threads unless g:plug_threads is set to 1

This commit is contained in:
Junegunn Choi 2013-09-25 12:30:02 +09:00
parent 214b4fb6fa
commit 2cf0c4fda5
2 changed files with 15 additions and 21 deletions

View file

@ -73,16 +73,14 @@ installation.
A `Plugfile` should contain a set of `Plug` commands for the dependent plugins.
I've created two dummy repositories with Plugfiles as an example to this scheme.
I've created three dummy repositories with Plugfiles as an example to this
scheme.
- [junegunn/dummy1](https://github.com/junegunn/dummy1)
- `Plug 'junegunn/vim-scroll-position'`
- `Plug 'junegunn/dummy2'`
- [junegunn/dummy2](https://github.com/junegunn/dummy2)
- `Plug 'junegunn/Zenburn'`
- `Plug 'junegunn/jellybeans.vim'`
- `Plug 'junegunn/dummy1'`
- (Circular dependencies are ignored)
- [junegunn/dummy1](https://github.com/junegunn/dummy1/blob/master/Plugfile)
- Plugfile includes `Plug 'junegunn/dummy2'`
- [junegunn/dummy2](https://github.com/junegunn/dummy2/blob/master/Plugfile)
- Plugfile includes `Plug 'junegunn/dummy3'`
- [junegunn/dummy3](https://github.com/junegunn/dummy3/blob/master/Plugfile)
If you put `Plug 'junegunn/dummy1'` in your configuration file, and run
`:PlugInstall`,

View file

@ -217,12 +217,7 @@ function! s:finish()
endfunction
function! s:update_impl(pull, args)
if has('ruby') && get(g:, 'plug_parallel', 1)
let threads = min(
\ [len(g:plugs), len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)])
else
let threads = 1
endif
let threads = len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)
call s:prepare()
call append(0, a:pull ? 'Updating plugins' : 'Installing plugins')
@ -230,7 +225,7 @@ function! s:update_impl(pull, args)
normal! 2G
redraw
if threads > 1
if has('ruby') && threads > 1
call s:update_parallel(a:pull, threads)
else
call s:update_serial(a:pull)
@ -255,8 +250,9 @@ function! s:extend(names)
return filter(copy(g:plugs), '!has_key(prev, v:key)')
endfunction
function! s:update_progress(cnt, total)
call setline(1, "Updating plugins (".a:cnt."/".a:total.")")
function! s:update_progress(pull, cnt, total)
call setline(1, (a:pull ? 'Updating' : 'Installing').
\ " plugins (".a:cnt."/".a:total.")")
call s:progress_bar(2, a:cnt, a:total)
normal! 2G
redraw
@ -300,13 +296,13 @@ function! s:update_serial(pull)
let result = '(x) ' . result
endif
call append(3, '- ' . name . ': ' . result)
call s:update_progress(len(done), total)
call s:update_progress(a:pull, len(done), total)
endfor
if !empty(s:extend(keys(todo)))
let todo = filter(copy(g:plugs), '!has_key(done, v:key)')
let total += len(todo)
call s:update_progress(len(done), total)
call s:update_progress(a:pull, len(done), total)
else
break
endif
@ -330,7 +326,7 @@ function! s:update_parallel(pull, threads)
take1 = proc { mtx.synchronize { all.shift } }
logh = proc {
cnt, tot = done.length, VIM::evaluate('len(g:plugs)')
$curbuf[1] = "Updating plugins (#{cnt}/#{tot})"
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
$curbuf[2] = '[' + ('=' * cnt).ljust(tot) + ']'
VIM::command('normal! 2G')
VIM::command('redraw')