Improve parallel update process
This commit is contained in:
parent
bc438626ba
commit
0c1a96b6b2
2 changed files with 29 additions and 24 deletions
12
README.md
12
README.md
|
@ -1,15 +1,15 @@
|
||||||
vim-plug
|
vim-plug
|
||||||
========
|
========
|
||||||
|
|
||||||
Vim plugin manager.
|
A single-file Vim plugin manager.
|
||||||
|
|
||||||
### Why?
|
### Wh..why?
|
||||||
|
|
||||||
Because I can?
|
... because I can?
|
||||||
|
|
||||||
### Pros.
|
### Pros.
|
||||||
|
|
||||||
- Marginally simpler
|
- Easier to setup
|
||||||
- Parallel installation/update (requires +ruby)
|
- Parallel installation/update (requires +ruby)
|
||||||
- Alternative directory structure: user/repo/branch
|
- Alternative directory structure: user/repo/branch
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ Download plug.vim and put it in ~/.vim/autoload
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mkdir -p ~/.vim/autoload
|
mkdir -p ~/.vim/autoload
|
||||||
curl -fL -o ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim
|
curl -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim
|
||||||
```
|
```
|
||||||
|
|
||||||
Edit your .vimrc
|
Edit your .vimrc
|
||||||
|
@ -50,5 +50,5 @@ You can change the location of the plugins with `plug#init(path)` call.
|
||||||
| PlugClean | Remove unused directories |
|
| PlugClean | Remove unused directories |
|
||||||
| PlugUpgrade | Upgrade vim-plug itself |
|
| PlugUpgrade | Upgrade vim-plug itself |
|
||||||
|
|
||||||
(Default #threads = Number of plugins)
|
(Default number of threads = `g:plug_threads` or 16)
|
||||||
|
|
||||||
|
|
41
plug.vim
41
plug.vim
|
@ -4,7 +4,7 @@
|
||||||
" Download plug.vim and put it in ~/.vim/autoload
|
" Download plug.vim and put it in ~/.vim/autoload
|
||||||
"
|
"
|
||||||
" mkdir -p ~/.vim/autoload
|
" mkdir -p ~/.vim/autoload
|
||||||
" curl -fL -o ~/.vim/autoload/plug.vim \
|
" curl -fLo ~/.vim/autoload/plug.vim \
|
||||||
" https://raw.github.com/junegunn/vim-plug/master/plug.vim
|
" https://raw.github.com/junegunn/vim-plug/master/plug.vim
|
||||||
"
|
"
|
||||||
" Edit your .vimrc
|
" Edit your .vimrc
|
||||||
|
@ -188,7 +188,8 @@ endfunction
|
||||||
|
|
||||||
function! s:update_impl(pull, args)
|
function! s:update_impl(pull, args)
|
||||||
if has('ruby') && get(g:, 'plug_parallel', 1)
|
if has('ruby') && get(g:, 'plug_parallel', 1)
|
||||||
let threads = len(a:args) > 0 ? a:args[0] : len(g:plug)
|
let threads = min(
|
||||||
|
\ [len(g:plug), len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)])
|
||||||
else
|
else
|
||||||
let threads = 1
|
let threads = 1
|
||||||
endif
|
endif
|
||||||
|
@ -255,11 +256,23 @@ function! s:update_parallel(pull, threads)
|
||||||
total = all.length
|
total = all.length
|
||||||
cnt = 0
|
cnt = 0
|
||||||
skip = 'Already installed'
|
skip = 'Already installed'
|
||||||
all.each_slice(VIM::evaluate('a:threads').to_i).each do |slice|
|
mtx = Mutex.new
|
||||||
slice.map { |pair|
|
take1 = proc { mtx.synchronize { all.shift } }
|
||||||
spec = pair.last
|
log = proc { |name, result, ok|
|
||||||
Thread.new do
|
mtx.synchronize {
|
||||||
name, dir, uri, branch = spec.values_at *%w[name dir uri branch]
|
result = '(x) ' + result unless ok
|
||||||
|
result = "- #{name}: #{result}"
|
||||||
|
$curbuf[1] = "Updating plugins (#{cnt += 1}/#{total})"
|
||||||
|
$curbuf[2] = '[' + ('=' * cnt).ljust(total) + ']'
|
||||||
|
$curbuf.append $curbuf.count, result
|
||||||
|
VIM::command('normal! 2G')
|
||||||
|
VIM::command('redraw')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VIM::evaluate('a:threads').to_i.times.map { |i|
|
||||||
|
Thread.new(i) do |ii|
|
||||||
|
while pair = take1.call
|
||||||
|
name, dir, uri, branch = pair.last.values_at *%w[name dir uri branch]
|
||||||
result =
|
result =
|
||||||
if File.directory? dir
|
if File.directory? dir
|
||||||
pull ? `#{cd} #{dir} && git pull 2>&1` : skip
|
pull ? `#{cd} #{dir} && git pull 2>&1` : skip
|
||||||
|
@ -267,18 +280,10 @@ function! s:update_parallel(pull, threads)
|
||||||
FileUtils.mkdir_p(base)
|
FileUtils.mkdir_p(base)
|
||||||
`#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{dir} 2>&1`
|
`#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{dir} 2>&1`
|
||||||
end.lines.to_a.last.strip
|
end.lines.to_a.last.strip
|
||||||
result = '(x) ' + result if $? != 0 && result != skip
|
log.call name, result, ($? == 0 || result == skip)
|
||||||
Thread.current[:result] = "- #{name}: #{result}"
|
|
||||||
end
|
end
|
||||||
}.each do |t|
|
|
||||||
t.join
|
|
||||||
$curbuf[1] = "Updating plugins (#{cnt += 1}/#{total})"
|
|
||||||
$curbuf[2] = '[' + ('=' * cnt).ljust(total) + ']'
|
|
||||||
$curbuf.append $curbuf.count, t[:result]
|
|
||||||
VIM::command('normal! 2G')
|
|
||||||
VIM::command('redraw')
|
|
||||||
end
|
end
|
||||||
end
|
}.each(&:join)
|
||||||
$curbuf[1] = "Updated. Elapsed time: #{"%.6f" % (Time.now - st)} sec."
|
$curbuf[1] = "Updated. Elapsed time: #{"%.6f" % (Time.now - st)} sec."
|
||||||
EOF
|
EOF
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -345,7 +350,7 @@ function! s:upgrade()
|
||||||
redraw
|
redraw
|
||||||
let mv = s:is_win ? 'move /Y' : 'mv -f'
|
let mv = s:is_win ? 'move /Y' : 'mv -f'
|
||||||
call system(printf(
|
call system(printf(
|
||||||
\ "curl -fL -o %s %s && ".mv." %s %s.old && ".mv." %s %s",
|
\ "curl -fLo %s %s && ".mv." %s %s.old && ".mv." %s %s",
|
||||||
\ new, s:plug_source, mee, mee, new, mee))
|
\ new, s:plug_source, mee, mee, new, mee))
|
||||||
if v:shell_error == 0
|
if v:shell_error == 0
|
||||||
unlet g:loaded_plug
|
unlet g:loaded_plug
|
||||||
|
|
Loading…
Reference in a new issue