Fix #4: parallel installer work on Windows
This commit is contained in:
parent
f36a558a67
commit
8bfcf21f22
23
plug.vim
23
plug.vim
|
@ -330,7 +330,8 @@ function! s:update_parallel(pull, threads)
|
||||||
require 'thread'
|
require 'thread'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
st = Time.now
|
st = Time.now
|
||||||
cd = VIM::evaluate('s:is_win').to_i == 1 ? 'cd /d' : 'cd'
|
iswin = VIM::evaluate('s:is_win').to_i == 1
|
||||||
|
cd = iswin ? 'cd /d' : 'cd'
|
||||||
pull = VIM::evaluate('a:pull').to_i == 1
|
pull = VIM::evaluate('a:pull').to_i == 1
|
||||||
base = VIM::evaluate('g:plug_home')
|
base = VIM::evaluate('g:plug_home')
|
||||||
all = VIM::evaluate('copy(g:plugs)')
|
all = VIM::evaluate('copy(g:plugs)')
|
||||||
|
@ -343,7 +344,7 @@ function! s:update_parallel(pull, threads)
|
||||||
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
|
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
|
||||||
$curbuf[2] = '[' + ('=' * cnt).ljust(tot) + ']'
|
$curbuf[2] = '[' + ('=' * cnt).ljust(tot) + ']'
|
||||||
VIM::command('normal! 2G')
|
VIM::command('normal! 2G')
|
||||||
VIM::command('redraw')
|
VIM::command('redraw') unless iswin
|
||||||
}
|
}
|
||||||
log = proc { |name, result, ok|
|
log = proc { |name, result, ok|
|
||||||
mtx.synchronize do
|
mtx.synchronize do
|
||||||
|
@ -354,6 +355,14 @@ function! s:update_parallel(pull, threads)
|
||||||
logh.call
|
logh.call
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
bt = iswin ? proc { |cmd|
|
||||||
|
tmp = VIM::evaluate('tempname()')
|
||||||
|
system("#{cmd} > #{tmp}")
|
||||||
|
data = File.read(tmp).chomp
|
||||||
|
File.unlink tmp rescue nil
|
||||||
|
data
|
||||||
|
} : proc { |cmd| `#{cmd}`.chomp }
|
||||||
|
|
||||||
until all.empty?
|
until all.empty?
|
||||||
names = all.keys
|
names = all.keys
|
||||||
[names.length, VIM::evaluate('a:threads').to_i].min.times.map { |i|
|
[names.length, VIM::evaluate('a:threads').to_i].min.times.map { |i|
|
||||||
|
@ -363,10 +372,10 @@ function! s:update_parallel(pull, threads)
|
||||||
dir, uri, branch = pair.last.values_at *%w[dir uri branch]
|
dir, uri, branch = pair.last.values_at *%w[dir uri branch]
|
||||||
ok, result =
|
ok, result =
|
||||||
if File.directory? dir
|
if File.directory? dir
|
||||||
current_uri = `#{cd} #{dir} && git config remote.origin.url`.chomp
|
current_uri = bt.call "#{cd} #{dir} && git config remote.origin.url"
|
||||||
if $? == 0 && current_uri == uri
|
if $? == 0 && current_uri == uri
|
||||||
if pull
|
if pull
|
||||||
output = `#{cd} #{dir} && git checkout -q #{branch} 2>&1 && git pull origin #{branch} 2>&1`
|
output = bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && git pull origin #{branch} 2>&1"
|
||||||
[$? == 0, output]
|
[$? == 0, output]
|
||||||
else
|
else
|
||||||
[true, skip]
|
[true, skip]
|
||||||
|
@ -377,11 +386,11 @@ function! s:update_parallel(pull, threads)
|
||||||
else
|
else
|
||||||
FileUtils.mkdir_p(base)
|
FileUtils.mkdir_p(base)
|
||||||
d = dir.sub(%r{[\\/]+$}, '')
|
d = dir.sub(%r{[\\/]+$}, '')
|
||||||
r = `#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{d} 2>&1`
|
r = bt.call "#{cd} #{base} && git clone --recursive #{uri} -b #{branch} #{d} 2>&1"
|
||||||
[$? == 0, r]
|
[$? == 0, r]
|
||||||
end
|
end
|
||||||
result = result.lines.to_a.last.strip
|
result = result.lines.to_a.last
|
||||||
log.call name, result, ok
|
log.call name, (result && result.strip), ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}.each(&:join)
|
}.each(&:join)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user