1
0

update plug.vim

This commit is contained in:
valeth 2016-04-17 23:16:04 +02:00
parent 41532ca40a
commit 5e72459953

View File

@ -26,7 +26,7 @@
" "
" " Using a non-master branch " " Using a non-master branch
" Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } " Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
"
" " Plugin options " " Plugin options
" Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' } " Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
" "
@ -117,13 +117,13 @@ function! s:define_commands()
if !executable('git') if !executable('git')
return s:err('`git` executable not found. vim-plug requires git.') return s:err('`git` executable not found. vim-plug requires git.')
endif endif
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', [<f-args>]) command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(<bang>0, [<f-args>])
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('<bang>' == '!', [<f-args>]) command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(<bang>0, [<f-args>])
command! -nargs=0 -bar -bang PlugClean call s:clean('<bang>' == '!') command! -nargs=0 -bar -bang PlugClean call s:clean(<bang>0)
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(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 PlugStatus call s:status()
command! -nargs=0 -bar PlugDiff call s:diff() command! -nargs=0 -bar PlugDiff call s:diff()
command! -nargs=? -bar PlugSnapshot call s:snapshot(<f-args>) command! -nargs=? -bar -bang -complete=file PlugSnapshot call s:snapshot(<bang>0, <f-args>)
endfunction endfunction
function! s:to_a(v) function! s:to_a(v)
@ -146,6 +146,16 @@ function! s:assoc(dict, key, val)
let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) let a:dict[a:key] = add(get(a:dict, a:key, []), a:val)
endfunction endfunction
function! s:ask(message)
call inputsave()
echohl WarningMsg
let proceed = input(a:message.' (y/N) ') =~? '^y'
echohl None
call inputrestore()
echo "\r"
return proceed
endfunction
function! plug#end() function! plug#end()
if !exists('g:plugs') if !exists('g:plugs')
return s:err('Call plug#begin() first') return s:err('Call plug#begin() first')
@ -521,16 +531,20 @@ function! s:syntax()
syn match plugStar /^*/ syn match plugStar /^*/
syn match plugMessage /\(^- \)\@<=.*/ syn match plugMessage /\(^- \)\@<=.*/
syn match plugName /\(^- \)\@<=[^ ]*:/ syn match plugName /\(^- \)\@<=[^ ]*:/
syn match plugSha /\%(: \)\@<=[0-9a-z]\{4,}$/
syn match plugTag /(tag: [^)]\+)/
syn match plugInstall /\(^+ \)\@<=[^:]*/ syn match plugInstall /\(^+ \)\@<=[^:]*/
syn match plugUpdate /\(^* \)\@<=[^:]*/ syn match plugUpdate /\(^* \)\@<=[^:]*/
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha,plugTag
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
syn match plugRelDate /([^)]*)$/ contained syn match plugRelDate /([^)]*)$/ contained
syn match plugNotLoaded /(not loaded)$/ syn match plugNotLoaded /(not loaded)$/
syn match plugError /^x.*/ syn match plugError /^x.*/
syn match plugH2 /^.*:\n-\+$/
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
hi def link plug1 Title hi def link plug1 Title
hi def link plug2 Repeat hi def link plug2 Repeat
hi def link plugH2 Type
hi def link plugX Exception hi def link plugX Exception
hi def link plugBracket Structure hi def link plugBracket Structure
hi def link plugNumber Number hi def link plugNumber Number
@ -547,6 +561,7 @@ function! s:syntax()
hi def link plugError Error hi def link plugError Error
hi def link plugRelDate Comment hi def link plugRelDate Comment
hi def link plugSha Identifier hi def link plugSha Identifier
hi def link plugTag Constant
hi def link plugNotLoaded Comment hi def link plugNotLoaded Comment
endfunction endfunction
@ -1168,10 +1183,12 @@ class Buffer(object):
pass pass
class Command(object): class Command(object):
CD = 'cd /d' if G_IS_WIN else 'cd'
def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None): def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None):
self.cmd = cmd self.cmd = cmd
if cmd_dir: if cmd_dir:
self.cmd = 'cd {0} && {1}'.format(cmd_dir, self.cmd) self.cmd = '{0} {1} && {2}'.format(Command.CD, cmd_dir, self.cmd)
self.timeout = timeout self.timeout = timeout
self.callback = cb if cb else (lambda msg: None) self.callback = cb if cb else (lambda msg: None)
self.clean = clean if clean else (lambda: None) self.clean = clean if clean else (lambda: None)
@ -1305,6 +1322,8 @@ class Plugin(object):
def install(self): def install(self):
target = self.args['dir'] target = self.args['dir']
if target[-1] == '\\':
target = target[0:-1]
def clean(target): def clean(target):
def _clean(): def _clean():
@ -1631,8 +1650,8 @@ function! s:update_ruby()
exists = File.directory? dir exists = File.directory? dir
ok, result = ok, result =
if exists if exists
dir = iswin ? dir : esc(dir) chdir = "#{cd} #{iswin ? dir : esc(dir)}"
ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil ret, data = bt.call "#{chdir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil
current_uri = data.lines.to_a.last current_uri = data.lines.to_a.last
if !ret if !ret
if data =~ /^Interrupted|^Timeout/ if data =~ /^Interrupted|^Timeout/
@ -1648,7 +1667,7 @@ function! s:update_ruby()
if pull if pull
log.call name, 'Updating ...', :update log.call name, 'Updating ...', :update
fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : '' fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : ''
bt.call "#{cd} #{dir} && git fetch #{fetch_opt} #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm}", name, :update, nil bt.call "#{chdir} && git fetch #{fetch_opt} #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm}", name, :update, nil
else else
[true, skip] [true, skip]
end end
@ -1813,10 +1832,7 @@ function! s:clean(force)
if empty(todo) if empty(todo)
call append(line('$'), 'Already clean.') call append(line('$'), 'Already clean.')
else else
call inputsave() if a:force || s:ask('Proceed?')
let yes = a:force || (input('Proceed? (y/N) ') =~? '^y')
call inputrestore()
if yes
for dir in todo for dir in todo
call s:rm_rf(dir) call s:rm_rf(dir)
endfor endfor
@ -1982,41 +1998,63 @@ function! s:section(flags)
call search('\(^[x-] \)\@<=[^:]\+:', a:flags) call search('\(^[x-] \)\@<=[^:]\+:', a:flags)
endfunction endfunction
function! s:format_git_log(line)
let [sha, refs, subject, date] = split(a:line, nr2char(1))
let tag = matchstr(refs, 'tag: [^,)]\+')
let tag = empty(tag) ? ' ' : ' ('.tag.') '
return printf(' %s%s%s (%s)', sha, tag, subject, date)
endfunction
function! s:append_ul(lnum, text)
call append(a:lnum, ['', a:text, repeat('-', len(a:text))])
endfunction
function! s:diff() function! s:diff()
call s:prepare() call s:prepare()
call append(0, 'Collecting updated changes ...') call append(0, ['Collecting changes ...', ''])
normal! gg let cnts = [0, 0]
redraw let bar = ''
let total = filter(copy(g:plugs), 's:is_managed(v:key) && isdirectory(v:val.dir)')
let cnt = 0 call s:progress_bar(2, bar, len(total))
for [k, v] in filter(items(g:plugs), '!has_key(v:val[1], "commit")') for origin in [1, 0]
if !isdirectory(v.dir) || !s:is_managed(k) call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:')
continue for [k, v] in reverse(sort(items(filter(copy(total), (origin ? '' : '!').'(has_key(v:val, "commit") || has_key(v:val, "tag"))'))))
endif let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..'
let diff = s:system_chomp('git log --pretty=format:"%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir)
let diff = s:system_chomp('git log --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"', v.dir) if !empty(diff)
if !empty(diff) let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : ''
call append(1, '') call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)')))
call append(2, '- '.k.':') let cnts[origin] += 1
call append(3, map(s:lines(diff), '" ". v:val')) endif
let cnt += 1 let bar .= '='
normal! gg call s:progress_bar(2, bar, len(total))
normal! 2G
redraw redraw
endfor
if !cnts[origin]
call append(5, ['', 'N/A'])
endif endif
endfor endfor
call setline(1, printf('%d plugin(s) updated.', cnts[0])
\ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : ''))
call setline(1, cnt == 0 ? 'No updates.' : 'Last update:') if cnts[0] || cnts[1]
nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr> nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr>
nnoremap <silent> <buffer> o :silent! call <SID>preview_commit()<cr> nnoremap <silent> <buffer> o :silent! call <SID>preview_commit()<cr>
nnoremap <silent> <buffer> X :call <SID>revert()<cr> endif
normal! gg if cnts[0]
setlocal nomodifiable nnoremap <silent> <buffer> X :call <SID>revert()<cr>
if cnt > 0
echo "Press 'X' on each block to revert the update" echo "Press 'X' on each block to revert the update"
endif endif
normal! gg
setlocal nomodifiable
endfunction endfunction
function! s:revert() function! s:revert()
if search('^Pending updates', 'bnW')
return
endif
let name = s:find_name(line('.')) let name = s:find_name(line('.'))
if empty(name) || !has_key(g:plugs, name) || if empty(name) || !has_key(g:plugs, name) ||
\ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y' \ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y'
@ -2030,42 +2068,35 @@ function! s:revert()
echo 'Reverted.' echo 'Reverted.'
endfunction endfunction
function! s:snapshot(...) abort function! s:snapshot(force, ...) abort
let home = get(s:, 'plug_home_org', g:plug_home)
let [type, var, header] = s:is_win ?
\ ['dosbatch', '%PLUG_HOME%',
\ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '',
\ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.home]] :
\ ['sh', '$PLUG_HOME',
\ ['#!/bin/sh', '# Generated by vim-plug', '# '.strftime("%c"), '',
\ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]]
call s:prepare() call s:prepare()
execute 'setf' type setf vim
call append(0, header) call append(0, ['" Generated by vim-plug',
call append('$', '') \ '" '.strftime("%c"),
\ '" :source this file in vim to restore the snapshot',
\ '" or execute: vim -S snapshot.vim',
\ '', '', 'PlugUpdate!'])
1 1
redraw let anchor = line('$') - 3
let names = sort(keys(filter(copy(g:plugs),
let dirs = sort(map(values(filter(copy(g:plugs), \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)')))
\'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)')), 'v:val.dir')) for name in reverse(names)
let anchor = line('$') - 1 let sha = s:system_chomp('git rev-parse --short HEAD', g:plugs[name].dir)
for dir in reverse(dirs)
let sha = s:system_chomp('git rev-parse --short HEAD', dir)
if !empty(sha) if !empty(sha)
call append(anchor, printf('cd %s && git reset --hard %s', call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha))
\ substitute(dir, '^\V'.escape(g:plug_home, '\'), var, ''), sha))
redraw redraw
endif endif
endfor endfor
if a:0 > 0 if a:0 > 0
let fn = expand(a:1) let fn = expand(a:1)
let fne = s:esc(fn) if filereadable(fn) && !(a:force || s:ask(a:1.' already exists. Overwrite?'))
return
endif
call writefile(getline(1, '$'), fn) call writefile(getline(1, '$'), fn)
if !s:is_win | call s:system('chmod +x ' . fne) | endif echo 'Saved as '.a:1
echo 'Saved to '.a:1 silent execute 'e' s:esc(fn)
silent execute 'e' fne setf vim
endif endif
endfunction endfunction