Skip to content

Commit

Permalink
upgrade plug again
Browse files Browse the repository at this point in the history
  • Loading branch information
jigish committed May 16, 2017
1 parent a3c9e57 commit c74a44b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 29 deletions.
2 changes: 1 addition & 1 deletion nvim/autoload/plug.vim
Expand Up @@ -579,7 +579,7 @@ function! s:infer_properties(name, repo)
let uri = repo
else
if repo !~ '/'
let repo = 'vim-scripts/'. repo
throw printf('Invalid argument: %s (implicit `vim-scripts'' expansion is deprecated)', repo)
endif
let fmt = get(g:, 'plug_url_format', 'https://git::@github.com/%s.git')
let uri = printf(fmt, repo)
Expand Down
84 changes: 56 additions & 28 deletions nvim/autoload/plug.vim.old
Expand Up @@ -18,7 +18,7 @@
" " Any valid git URL is allowed
" Plug 'https://github.com/junegunn/vim-github-dashboard.git'
"
" " Group dependencies, vim-snippets depends on ultisnips
" " Multiple Plug commands can be written in a single line using | separators
" Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
"
" " On-demand loading
Expand All @@ -40,7 +40,7 @@
" " Unmanaged plugin (manually installed and updated)
" Plug '~/my-prototype-plugin'
"
" " Add plugins to &runtimepath
" " Initialize plugin system
" call plug#end()
"
" Then reload .vimrc and :PlugInstall to install plugins.
Expand All @@ -61,7 +61,7 @@
" More information: https://github.com/junegunn/vim-plug
"
"
" Copyright (c) 2016 Junegunn Choi
" Copyright (c) 2017 Junegunn Choi
"
" MIT License
"
Expand Down Expand Up @@ -97,7 +97,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:nvim = has('nvim') && exists('*jobwait') && !s:is_win
let s:nvim = has('nvim-0.2') || (has('nvim') && exists('*jobwait') && !s:is_win)
let s:vim8 = has('patch-8.0.0039') && exists('*job_start')
let s:me = resolve(expand('<sfile>:p'))
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
Expand Down Expand Up @@ -426,7 +426,10 @@ function! s:dobufread(names)
let path = s:rtp(g:plugs[name]).'/**'
for dir in ['ftdetect', 'ftplugin']
if len(finddir(dir, path))
return s:doautocmd('BufRead')
if exists('#BufRead')
doautocmd BufRead
endif
return
endif
endfor
endfor
Expand All @@ -444,11 +447,15 @@ function! plug#load(...)
let s = len(unknowns) > 1 ? 's' : ''
return s:err(printf('Unknown plugin%s: %s', s, join(unknowns, ', ')))
end
for name in a:000
call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
endfor
call s:dobufread(a:000)
return 1
let unloaded = filter(copy(a:000), '!get(s:loaded, v:val, 0)')
if !empty(unloaded)
for name in unloaded
call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
endfor
call s:dobufread(unloaded)
return 1
end
return 0
endfunction

function! s:remove_triggers(name)
Expand Down Expand Up @@ -618,10 +625,10 @@ function! s:syntax()
syn match plugTag /(tag: [^)]\+)/
syn match plugInstall /\(^+ \)\@<=[^:]*/
syn match plugUpdate /\(^* \)\@<=[^:]*/
syn match plugCommit /^ \X*[0-9a-f]\{7} .*/ contains=plugRelDate,plugEdge,plugTag
syn match plugCommit /^ \X*[0-9a-f]\{7,9} .*/ contains=plugRelDate,plugEdge,plugTag
syn match plugEdge /^ \X\+$/
syn match plugEdge /^ \X*/ contained nextgroup=plugSha
syn match plugSha /[0-9a-f]\{7}/ contained
syn match plugSha /[0-9a-f]\{7,9}/ contained
syn match plugRelDate /([^)]*)$/ contained
syn match plugNotLoaded /(not loaded)$/
syn match plugError /^x.*/
Expand Down Expand Up @@ -817,6 +824,10 @@ function! s:do(pull, force, todo)
let type = type(spec.do)
if type == s:TYPE.string
if spec.do[0] == ':'
if !get(s:loaded, name, 0)
let s:loaded[name] = 1
call s:reorg_rtp()
endif
call s:load_plugin(spec)
try
execute spec.do[1:]
Expand Down Expand Up @@ -861,7 +872,7 @@ function! s:checkout(spec)
let output = s:system('git rev-parse HEAD', a:spec.dir)
if !v:shell_error && !s:hash_match(sha, s:lines(output)[0])
let output = s:system(
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha), a:spec.dir)
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha).' --', a:spec.dir)
endif
return output
endfunction
Expand Down Expand Up @@ -919,7 +930,8 @@ function! s:check_ruby()
endfunction

function! s:update_impl(pull, force, args) abort
let args = copy(a:args)
let sync = index(a:args, '--sync') >= 0 || has('vim_starting')
let args = filter(copy(a:args), 'v:val != "--sync"')
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
\ remove(args, -1) : get(g:, 'plug_threads', 16)

Expand Down Expand Up @@ -955,7 +967,7 @@ function! s:update_impl(pull, force, args) abort

let use_job = s:nvim || s:vim8
let python = (has('python') || has('python3')) && !use_job
let ruby = has('ruby') && !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && s:check_ruby()
let ruby = has('ruby') && !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && threads > 1 && s:check_ruby()

let s:update = {
\ 'start': reltime(),
Expand All @@ -978,6 +990,10 @@ function! s:update_impl(pull, force, args) abort
let s:clone_opt = get(g:, 'plug_shallow', 1) ?
\ '--depth 1' . (s:git_version_requirement(1, 7, 10) ? ' --no-single-branch' : '') : ''

if has('win32unix')
let s:clone_opt .= ' -c core.eol=lf -c core.autocrlf=input'
endif

" Python version requirement (>= 2.7)
if python && !has('python3') && !ruby && !use_job && s:update.threads > 1
redir => pyv
Expand Down Expand Up @@ -1020,7 +1036,7 @@ function! s:update_impl(pull, force, args) abort
endtry
else
call s:update_vim()
while use_job && has('vim_starting')
while use_job && sync
sleep 100m
if s:update.fin
break
Expand Down Expand Up @@ -1051,19 +1067,19 @@ function! s:update_finish()
elseif has_key(spec, 'tag')
let tag = spec.tag
if tag =~ '\*'
let tags = s:lines(s:system('git tag --list '.string(tag).' --sort -version:refname 2>&1', spec.dir))
let tags = s:lines(s:system('git tag --list '.s:shellesc(tag).' --sort -version:refname 2>&1', spec.dir))
if !v:shell_error && !empty(tags)
let tag = tags[0]
call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag))
call append(3, '')
endif
endif
call s:log4(name, 'Checking out '.tag)
let out = s:system('git checkout -q '.s:esc(tag).' 2>&1', spec.dir)
let out = s:system('git checkout -q '.s:esc(tag).' -- 2>&1', spec.dir)
else
let branch = s:esc(get(spec, 'branch', 'master'))
call s:log4(name, 'Merging origin/'.branch)
let out = s:system('git checkout -q '.branch.' 2>&1'
let out = s:system('git checkout -q '.branch.' -- 2>&1'
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir)
endif
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
Expand Down Expand Up @@ -1153,7 +1169,7 @@ function! s:job_cb(fn, job, ch, data)
call call(a:fn, [a:job, a:data])
endfunction

function! s:nvim_cb(job_id, data, event) abort
function! s:nvim_cb(job_id, data, event) dict abort
return a:event == 'stdout' ?
\ s:job_cb('s:job_out_cb', self, 0, join(a:data, "\n")) :
\ s:job_cb('s:job_exit_cb', self, 0, a:data)
Expand Down Expand Up @@ -1181,7 +1197,7 @@ function! s:spawn(name, cmd, opts)
\ 'Invalid arguments (or job table is full)']
endif
elseif s:vim8
let jid = job_start(argv, {
let jid = job_start(s:is_win ? join(argv, ' ') : argv, {
\ 'out_cb': function('s:job_cb', ['s:job_out_cb', job]),
\ 'exit_cb': function('s:job_cb', ['s:job_exit_cb', job]),
\ 'out_mode': 'raw'
Expand Down Expand Up @@ -1764,6 +1780,7 @@ function! s:update_ruby()
tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1
nthr = VIM::evaluate('s:update.threads').to_i
maxy = VIM::evaluate('winheight(".")').to_i
vim7 = VIM::evaluate('v:version').to_i <= 703 && RUBY_PLATFORM =~ /darwin/
cd = iswin ? 'cd /d' : 'cd'
tot = VIM::evaluate('len(s:update.todo)') || 0
bar = ''
Expand Down Expand Up @@ -1853,11 +1870,17 @@ function! s:update_ruby()
main = Thread.current
threads = []
watcher = Thread.new {
require 'io/console' # >= Ruby 1.9
nil until IO.console.getch == 3.chr
if vim7
while VIM::evaluate('getchar(1)')
sleep 0.1
end
else
require 'io/console' # >= Ruby 1.9
nil until IO.console.getch == 3.chr
end
mtx.synchronize do
running = false
threads.each { |t| t.raise Interrupt }
threads.each { |t| t.raise Interrupt } unless vim7
end
threads.each { |t| t.join rescue nil }
main.kill
Expand Down Expand Up @@ -2003,7 +2026,7 @@ function! s:git_validate(spec, check_branch)
" Check tag
if has_key(a:spec, 'tag')
let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir)
if a:spec.tag !=# tag
if a:spec.tag !=# tag && a:spec.tag !~ '\*'
let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.',
\ (empty(tag) ? 'N/A' : tag), a:spec.tag)
endif
Expand Down Expand Up @@ -2270,7 +2293,7 @@ function! s:preview_commit()
let b:plug_preview = !s:is_preview_window_open()
endif

let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7}')
let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7,9}')
if empty(sha)
return
endif
Expand All @@ -2288,7 +2311,12 @@ function! s:preview_commit()
wincmd P
endif
setlocal previewwindow filetype=git buftype=nofile nobuflisted modifiable
execute 'silent %!cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
try
let [sh, shrd] = s:chsh(1)
execute 'silent %!cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
finally
let [&shell, &shellredir] = [sh, shrd]
endtry
setlocal nomodifiable
nnoremap <silent> <buffer> q :q<cr>
wincmd p
Expand Down Expand Up @@ -2370,7 +2398,7 @@ function! s:revert()
return
endif

call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch), g:plugs[name].dir)
call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch).' --', g:plugs[name].dir)
setlocal modifiable
normal! "_dap
setlocal nomodifiable
Expand Down

0 comments on commit c74a44b

Please sign in to comment.