Skip to content

Commit 6a5ae55

Browse files
committed
update color, clean settings
1 parent 6991063 commit 6a5ae55

File tree

4 files changed

+261
-87
lines changed

4 files changed

+261
-87
lines changed

Diff for: .vim/autoload/plug.vim

+97-76
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
" More information: https://github.com/junegunn/vim-plug
5959
"
6060
"
61-
" Copyright (c) 2015 Junegunn Choi
61+
" Copyright (c) 2016 Junegunn Choi
6262
"
6363
" MIT License
6464
"
@@ -563,14 +563,14 @@ function! s:syntax()
563563
syn match plugStar /^*/
564564
syn match plugMessage /\(^- \)\@<=.*/
565565
syn match plugName /\(^- \)\@<=[^ ]*:/
566-
syn match plugSha /\%(: \)\@<=[0-9a-z]\{4,}$/
566+
syn match plugSha /\%(: \)\@<=[0-9a-f]\{4,}$/
567567
syn match plugTag /(tag: [^)]\+)/
568568
syn match plugInstall /\(^+ \)\@<=[^:]*/
569569
syn match plugUpdate /\(^* \)\@<=[^:]*/
570-
syn match plugCommit /^ \X*[0-9a-z]\{7} .*/ contains=plugRelDate,plugEdge,plugTag
570+
syn match plugCommit /^ \X*[0-9a-f]\{7} .*/ contains=plugRelDate,plugEdge,plugTag
571571
syn match plugEdge /^ \X\+$/
572572
syn match plugEdge /^ \X*/ contained nextgroup=plugSha
573-
syn match plugSha /[0-9a-z]\{7}/ contained
573+
syn match plugSha /[0-9a-f]\{7}/ contained
574574
syn match plugRelDate /([^)]*)$/ contained
575575
syn match plugNotLoaded /(not loaded)$/
576576
syn match plugError /^x.*/
@@ -708,31 +708,43 @@ function! s:assign_name()
708708
silent! execute 'f' fnameescape(name)
709709
endfunction
710710

711+
function! s:bang(cmd, ...)
712+
try
713+
" FIXME: Escaping is incomplete. We could use shellescape with eval,
714+
" but it won't work on Windows.
715+
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
716+
let g:_plug_bang = '!'.escape(cmd, '#!%')
717+
execute "normal! :execute g:_plug_bang\<cr>\<cr>"
718+
finally
719+
unlet g:_plug_bang
720+
endtry
721+
return v:shell_error ? 'Exit status: ' . v:shell_error : ''
722+
endfunction
723+
724+
function! s:regress_bar()
725+
let bar = substitute(getline(2)[1:-2], '.*\zs=', 'x', '')
726+
call s:progress_bar(2, bar, len(bar))
727+
endfunction
728+
729+
function! s:is_updated(dir)
730+
return !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', a:dir))
731+
endfunction
732+
711733
function! s:do(pull, force, todo)
712734
for [name, spec] in items(a:todo)
713735
if !isdirectory(spec.dir)
714736
continue
715737
endif
716738
let installed = has_key(s:update.new, name)
717739
let updated = installed ? 0 :
718-
\ (a:pull && index(s:update.errors, name) < 0 && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"', spec.dir)))
740+
\ (a:pull && index(s:update.errors, name) < 0 && s:is_updated(spec.dir))
719741
if a:force || installed || updated
720742
execute 'cd' s:esc(spec.dir)
721743
call append(3, '- Post-update hook for '. name .' ... ')
722744
let error = ''
723745
let type = type(spec.do)
724746
if type == s:TYPE.string
725-
try
726-
" FIXME: Escaping is incomplete. We could use shellescape with eval,
727-
" but it won't work on Windows.
728-
let g:_plug_do = '!'.escape(spec.do, '#!%')
729-
execute "normal! :execute g:_plug_do\<cr>\<cr>"
730-
finally
731-
if v:shell_error
732-
let error = 'Exit status: ' . v:shell_error
733-
endif
734-
unlet g:_plug_do
735-
endtry
747+
let error = s:bang(spec.do)
736748
elseif type == s:TYPE.funcref
737749
try
738750
let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged')
@@ -745,6 +757,10 @@ function! s:do(pull, force, todo)
745757
endif
746758
call setline(4, empty(error) ? (getline(4) . 'OK')
747759
\ : ('x' . getline(4)[1:] . error))
760+
if !empty(error)
761+
call add(s:update.errors, name)
762+
call s:regress_bar()
763+
endif
748764
cd -
749765
endif
750766
endfor
@@ -754,32 +770,14 @@ function! s:hash_match(a, b)
754770
return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0
755771
endfunction
756772

757-
function! s:checkout(plugs)
758-
for [name, spec] in items(a:plugs)
759-
let sha = spec.commit
760-
call append(3, '- Checking out '.sha[:6].' of '.name.' ... ')
761-
redraw
762-
763-
let error = []
764-
let output = s:lines(s:system('git rev-parse HEAD', spec.dir))
765-
if v:shell_error
766-
let error = output
767-
elseif !s:hash_match(sha, output[0])
768-
let output = s:lines(s:system(
769-
\ 'git fetch --depth 999999 && git checkout '.sha, spec.dir))
770-
if v:shell_error
771-
let error = output
772-
endif
773-
endif
774-
if empty(error)
775-
call setline(4, getline(4) . 'OK')
776-
else
777-
call setline(4, 'x'.getline(4)[1:] . 'Error')
778-
for line in reverse(error)
779-
call append(4, ' '.line)
780-
endfor
781-
endif
782-
endfor
773+
function! s:checkout(spec)
774+
let sha = a:spec.commit
775+
let output = s:system('git rev-parse HEAD', a:spec.dir)
776+
if !v:shell_error && !s:hash_match(sha, s:lines(output)[0])
777+
let output = s:system(
778+
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha), a:spec.dir)
779+
endif
780+
return output
783781
endfunction
784782

785783
function! s:finish(pull)
@@ -788,7 +786,7 @@ function! s:finish(pull)
788786
let s = new_frozen > 1 ? 's' : ''
789787
call append(3, printf('- Installed %d frozen plugin%s', new_frozen, s))
790788
endif
791-
call append(3, '- Finishing ... ')
789+
call append(3, '- Finishing ... ') | 4
792790
redraw
793791
call plug#helptags()
794792
call plug#end()
@@ -931,13 +929,52 @@ function! s:update_impl(pull, force, args) abort
931929
endif
932930
endfunction
933931

932+
function! s:log4(name, msg)
933+
call setline(4, printf('- %s (%s)', a:msg, a:name))
934+
redraw
935+
endfunction
936+
934937
function! s:update_finish()
935938
if exists('s:git_terminal_prompt')
936939
let $GIT_TERMINAL_PROMPT = s:git_terminal_prompt
937940
endif
938941
if s:switch_in()
939-
call s:checkout(filter(copy(s:update.all), 'has_key(v:val, "commit")'))
940-
call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'has_key(v:val, "do")'))
942+
call append(3, '- Updating ...') | 4
943+
for [name, spec] in items(filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && (s:update.pull || has_key(s:update.new, v:key))'))
944+
let pos = s:logpos(name)
945+
if !pos
946+
continue
947+
endif
948+
if has_key(spec, 'commit')
949+
call s:log4(name, 'Checking out '.spec.commit)
950+
let out = s:checkout(spec)
951+
elseif has_key(spec, 'tag')
952+
call s:log4(name, 'Checking out '.spec.tag)
953+
let out = s:system('git checkout -q '.s:esc(spec.tag).' 2>&1', spec.dir)
954+
else
955+
let branch = s:esc(get(spec, 'branch', 'master'))
956+
call s:log4(name, 'Merging origin/'.branch)
957+
let out = s:system('git checkout -q '.branch.' 2>&1'
958+
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir)
959+
endif
960+
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
961+
\ (has_key(s:update.new, name) || s:is_updated(spec.dir))
962+
call s:log4(name, 'Updating submodules. This may take a while.')
963+
let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir)
964+
endif
965+
let msg = printf('%s %s: %s', v:shell_error ? 'x': '-', name, get(s:lines(out), -1, ''))
966+
if v:shell_error
967+
call add(s:update.errors, name)
968+
call s:regress_bar()
969+
execute pos 'd _'
970+
call append(4, msg) | 4
971+
elseif !empty(out)
972+
call setline(pos, msg)
973+
endif
974+
redraw
975+
endfor
976+
4 d _
977+
call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && has_key(v:val, "do")'))
941978
call s:finish(s:update.pull)
942979
call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.')
943980
call s:switch_out('normal! gg')
@@ -1025,7 +1062,7 @@ function! s:reap(name)
10251062
endif
10261063
let s:update.bar .= job.error ? 'x' : '='
10271064

1028-
call s:log(job.error ? 'x' : '-', a:name, job.result)
1065+
call s:log(job.error ? 'x' : '-', a:name, empty(job.result) ? 'OK' : job.result)
10291066
call s:bar()
10301067

10311068
call remove(s:jobs, a:name)
@@ -1042,7 +1079,7 @@ function! s:bar()
10421079
endfunction
10431080

10441081
function! s:logpos(name)
1045-
for i in range(1, line('$'))
1082+
for i in range(4, line('$'))
10461083
if getline(i) =~# '^[-+x*] '.a:name.':'
10471084
return i
10481085
endif
@@ -1093,17 +1130,12 @@ while 1 " Without TCO, Vim stack is bound to explode
10931130
redraw
10941131

10951132
let has_tag = has_key(spec, 'tag')
1096-
let checkout = s:shellesc(has_tag ? spec.tag : spec.branch)
1097-
let merge = s:shellesc(has_tag ? spec.tag : 'origin/'.spec.branch)
1098-
10991133
if !new
11001134
let error = s:git_validate(spec, 0)
11011135
if empty(error)
11021136
if pull
11031137
let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : ''
1104-
call s:spawn(name,
1105-
\ printf('(git fetch %s %s 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only %s 2>&1 && git submodule update --init --recursive 2>&1)',
1106-
\ fetch_opt, prog, checkout, merge), { 'dir': spec.dir })
1138+
call s:spawn(name, printf('git fetch %s %s 2>&1', fetch_opt, prog), { 'dir': spec.dir })
11071139
else
11081140
let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 }
11091141
endif
@@ -1112,11 +1144,10 @@ while 1 " Without TCO, Vim stack is bound to explode
11121144
endif
11131145
else
11141146
call s:spawn(name,
1115-
\ printf('git clone %s %s --recursive %s -b %s %s 2>&1',
1147+
\ printf('git clone %s %s %s %s 2>&1',
11161148
\ has_tag ? '' : s:clone_opt,
11171149
\ prog,
11181150
\ s:shellesc(spec.uri),
1119-
\ checkout,
11201151
\ s:shellesc(s:trim(spec.dir))), { 'new': 1 })
11211152
endif
11221153

@@ -1345,10 +1376,7 @@ class Plugin(object):
13451376
self.args = args
13461377
self.buf_q = buf_q
13471378
self.lock = lock
1348-
tag = args.get('tag', 0)
1349-
self.checkout = esc(tag if tag else args['branch'])
1350-
self.merge = esc(tag if tag else 'origin/' + args['branch'])
1351-
self.tag = tag
1379+
self.tag = args.get('tag', 0)
13521380

13531381
def manage(self):
13541382
try:
@@ -1384,9 +1412,9 @@ class Plugin(object):
13841412

13851413
self.write(Action.INSTALL, self.name, ['Installing ...'])
13861414
callback = functools.partial(self.write, Action.INSTALL, self.name)
1387-
cmd = 'git clone {0} {1} --recursive {2} -b {3} {4} 2>&1'.format(
1415+
cmd = 'git clone {0} {1} {2} {3} 2>&1'.format(
13881416
'' if self.tag else G_CLONE_OPT, G_PROGRESS, self.args['uri'],
1389-
self.checkout, esc(target))
1417+
esc(target))
13901418
com = Command(cmd, None, G_TIMEOUT, callback, clean(target))
13911419
result = com.execute(G_RETRIES)
13921420
self.write(Action.DONE, self.name, result[-1:])
@@ -1412,11 +1440,7 @@ class Plugin(object):
14121440
self.write(Action.UPDATE, self.name, ['Updating ...'])
14131441
callback = functools.partial(self.write, Action.UPDATE, self.name)
14141442
fetch_opt = '--depth 99999999' if self.tag and os.path.isfile(os.path.join(self.args['dir'], '.git/shallow')) else ''
1415-
cmds = ['git fetch {0} {1}'.format(fetch_opt, G_PROGRESS),
1416-
'git checkout -q {0}'.format(self.checkout),
1417-
'git merge --ff-only {0}'.format(self.merge),
1418-
'git submodule update --init --recursive']
1419-
cmd = ' 2>&1 && '.join(cmds)
1443+
cmd = 'git fetch {0} {1} 2>&1'.format(fetch_opt, G_PROGRESS)
14201444
com = Command(cmd, self.args['dir'], G_TIMEOUT, callback)
14211445
result = com.execute(G_RETRIES)
14221446
self.write(Action.DONE, self.name, result[-1:])
@@ -1508,7 +1532,7 @@ def main():
15081532
while not buf_q.empty() or thr.active_count() != start_cnt:
15091533
try:
15101534
action, name, msg = buf_q.get(True, 0.25)
1511-
buf.write(action, name, msg)
1535+
buf.write(action, name, ['OK'] if not msg else msg)
15121536
buf_q.task_done()
15131537
except queue.Empty:
15141538
pass
@@ -1602,7 +1626,7 @@ function! s:update_ruby()
16021626
end
16031627
result =
16041628
if type || type.nil?
1605-
["#{b} #{name}: #{result.lines.to_a.last}"]
1629+
["#{b} #{name}: #{result.lines.to_a.last || 'OK'}"]
16061630
elsif result =~ /^Interrupted|^Timeout/
16071631
["#{b} #{name}: #{result}"]
16081632
else
@@ -1692,10 +1716,7 @@ function! s:update_ruby()
16921716
threads << Thread.new {
16931717
while pair = take1.call
16941718
name = pair.first
1695-
dir, uri, branch, tag = pair.last.values_at *%w[dir uri branch tag]
1696-
checkout = esc(tag ? tag : branch)
1697-
merge = esc(tag ? tag : "origin/#{branch}")
1698-
subm = "git submodule update --init --recursive 2>&1"
1719+
dir, uri, tag = pair.last.values_at *%w[dir uri tag]
16991720
exists = File.directory? dir
17001721
ok, result =
17011722
if exists
@@ -1716,15 +1737,15 @@ function! s:update_ruby()
17161737
if pull
17171738
log.call name, 'Updating ...', :update
17181739
fetch_opt = (tag && File.exist?(File.join(dir, '.git/shallow'))) ? '--depth 99999999' : ''
1719-
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
1740+
bt.call "#{chdir} && git fetch #{fetch_opt} #{progress} 2>&1", name, :update, nil
17201741
else
17211742
[true, skip]
17221743
end
17231744
end
17241745
else
17251746
d = esc dir.sub(%r{[\\/]+$}, '')
17261747
log.call name, 'Installing ...', :install
1727-
bt.call "git clone #{clone_opt unless tag} #{progress} --recursive #{uri} -b #{checkout} #{d} 2>&1", name, :install, proc {
1748+
bt.call "git clone #{clone_opt unless tag} #{progress} #{uri} #{d} 2>&1", name, :install, proc {
17281749
FileUtils.rm_rf dir
17291750
}
17301751
end
@@ -2023,7 +2044,7 @@ function! s:preview_commit()
20232044
let b:plug_preview = !s:is_preview_window_open()
20242045
endif
20252046

2026-
let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-z]\{7}')
2047+
let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7}')
20272048
if empty(sha)
20282049
return
20292050
endif
@@ -2036,7 +2057,7 @@ function! s:preview_commit()
20362057
execute 'pedit' sha
20372058
wincmd P
20382059
setlocal filetype=git buftype=nofile nobuflisted modifiable
2039-
execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --pretty=medium' sha
2060+
execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
20402061
normal! gg"_dd
20412062
setlocal nomodifiable
20422063
nnoremap <silent> <buffer> q :q<cr>

0 commit comments

Comments
 (0)