58
58
" More information: https://github.com/junegunn/vim-plug
59
59
"
60
60
"
61
- " Copyright (c) 2015 Junegunn Choi
61
+ " Copyright (c) 2016 Junegunn Choi
62
62
"
63
63
" MIT License
64
64
"
@@ -563,14 +563,14 @@ function! s:syntax()
563
563
syn match plugStar / ^*/
564
564
syn match plugMessage / \( ^- \)\@ <=.*/
565
565
syn match plugName / \( ^- \)\@ <=[^ ]*:/
566
- syn match plugSha / \% (: \)\@ <=[0-9a-z ]\{ 4,}$/
566
+ syn match plugSha / \% (: \)\@ <=[0-9a-f ]\{ 4,}$/
567
567
syn match plugTag / (tag: [^)]\+ )/
568
568
syn match plugInstall / \( ^+ \)\@ <=[^:]*/
569
569
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
571
571
syn match plugEdge / ^ \X\+ $/
572
572
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
574
574
syn match plugRelDate / ([^)]*)$/ contained
575
575
syn match plugNotLoaded / (not loaded)$/
576
576
syn match plugError / ^x.*/
@@ -708,31 +708,43 @@ function! s:assign_name()
708
708
silent ! execute ' f' fnameescape (name)
709
709
endfunction
710
710
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
+
711
733
function ! s: do (pull, force, todo )
712
734
for [name, spec] in items (a: todo )
713
735
if ! isdirectory (spec.dir )
714
736
continue
715
737
endif
716
738
let installed = has_key (s: update .new , name)
717
739
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 ))
719
741
if a: force || installed || updated
720
742
execute ' cd' s: esc (spec.dir )
721
743
call append (3 , ' - Post-update hook for ' . name .' ... ' )
722
744
let error = ' '
723
745
let type = type (spec.do )
724
746
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 )
736
748
elseif type == s: TYPE .funcref
737
749
try
738
750
let status = installed ? ' installed' : (updated ? ' updated' : ' unchanged' )
@@ -745,6 +757,10 @@ function! s:do(pull, force, todo)
745
757
endif
746
758
call setline (4 , empty (error ) ? (getline (4 ) . ' OK' )
747
759
\ : (' x' . getline (4 )[1 :] . error ))
760
+ if ! empty (error )
761
+ call add (s: update .errors, name)
762
+ call s: regress_bar ()
763
+ endif
748
764
cd -
749
765
endif
750
766
endfor
@@ -754,32 +770,14 @@ function! s:hash_match(a, b)
754
770
return stridx (a: a , a: b ) == 0 || stridx (a: b , a: a ) == 0
755
771
endfunction
756
772
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
783
781
endfunction
784
782
785
783
function ! s: finish (pull)
@@ -788,7 +786,7 @@ function! s:finish(pull)
788
786
let s = new_frozen > 1 ? ' s' : ' '
789
787
call append (3 , printf (' - Installed %d frozen plugin%s' , new_frozen, s ))
790
788
endif
791
- call append (3 , ' - Finishing ... ' )
789
+ call append (3 , ' - Finishing ... ' ) | 4
792
790
redraw
793
791
call plug#helptags ()
794
792
call plug#end ()
@@ -931,13 +929,52 @@ function! s:update_impl(pull, force, args) abort
931
929
endif
932
930
endfunction
933
931
932
+ function ! s: log4 (name, msg)
933
+ call setline (4 , printf (' - %s (%s)' , a: msg , a: name ))
934
+ redraw
935
+ endfunction
936
+
934
937
function ! s: update_finish ()
935
938
if exists (' s:git_terminal_prompt' )
936
939
let $GIT_TERMINAL_PROMPT = s: git_terminal_prompt
937
940
endif
938
941
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")' ))
941
978
call s: finish (s: update .pull)
942
979
call setline (1 , ' Updated. Elapsed time: ' . split (reltimestr (reltime (s: update .start )))[0 ] . ' sec.' )
943
980
call s: switch_out (' normal! gg' )
@@ -1025,7 +1062,7 @@ function! s:reap(name)
1025
1062
endif
1026
1063
let s: update .bar .= job.error ? ' x' : ' ='
1027
1064
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)
1029
1066
call s: bar ()
1030
1067
1031
1068
call remove (s: jobs , a: name )
@@ -1042,7 +1079,7 @@ function! s:bar()
1042
1079
endfunction
1043
1080
1044
1081
function ! s: logpos (name)
1045
- for i in range (1 , line (' $' ))
1082
+ for i in range (4 , line (' $' ))
1046
1083
if getline (i ) = ~# ' ^[-+x*] ' .a: name .' :'
1047
1084
return i
1048
1085
endif
@@ -1093,17 +1130,12 @@ while 1 " Without TCO, Vim stack is bound to explode
1093
1130
redraw
1094
1131
1095
1132
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
-
1099
1133
if ! new
1100
1134
let error = s: git_validate (spec, 0 )
1101
1135
if empty (error )
1102
1136
if pull
1103
1137
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 })
1107
1139
else
1108
1140
let s: jobs [name] = { ' running' : 0 , ' result' : ' Already installed' , ' error' : 0 }
1109
1141
endif
@@ -1112,11 +1144,10 @@ while 1 " Without TCO, Vim stack is bound to explode
1112
1144
endif
1113
1145
else
1114
1146
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' ,
1116
1148
\ has_tag ? ' ' : s: clone_opt ,
1117
1149
\ prog,
1118
1150
\ s: shellesc (spec.uri),
1119
- \ checkout,
1120
1151
\ s: shellesc (s: trim (spec.dir ))), { ' new' : 1 })
1121
1152
endif
1122
1153
@@ -1345,10 +1376,7 @@ class Plugin(object):
1345
1376
self .args = args
1346
1377
self .buf_q = buf_q
1347
1378
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 )
1352
1380
1353
1381
def manage (self ):
1354
1382
try :
@@ -1384,9 +1412,9 @@ class Plugin(object):
1384
1412
1385
1413
self .write (Action.INSTALL, self .name, [' Installing ...' ])
1386
1414
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 (
1388
1416
' ' if self .tag else G_CLONE_OPT, G_PROGRESS, self .args [' uri' ],
1389
- self .checkout, esc (target))
1417
+ esc (target))
1390
1418
com = Command (cmd, None, G_TIMEOUT, callback, clean (target))
1391
1419
result = com .execute (G_RETRIES)
1392
1420
self .write (Action.DONE, self .name, result[-1 :])
@@ -1412,11 +1440,7 @@ class Plugin(object):
1412
1440
self .write (Action.UPDATE, self .name, [' Updating ...' ])
1413
1441
callback = functools.partial (self .write , Action.UPDATE, self .name)
1414
1442
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)
1420
1444
com = Command (cmd, self .args [' dir' ], G_TIMEOUT, callback)
1421
1445
result = com .execute (G_RETRIES)
1422
1446
self .write (Action.DONE, self .name, result[-1 :])
@@ -1508,7 +1532,7 @@ def main():
1508
1532
while not buf_q.empty () or thr.active_count () != start_cnt:
1509
1533
try :
1510
1534
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)
1512
1536
buf_q.task_done ()
1513
1537
except queue.Empty:
1514
1538
pass
@@ -1602,7 +1626,7 @@ function! s:update_ruby()
1602
1626
end
1603
1627
result =
1604
1628
if type || type .nil?
1605
- [" #{b} #{name}: #{result.lines.to_a.last}" ]
1629
+ [" #{b} #{name}: #{result.lines.to_a.last || 'OK' }" ]
1606
1630
elsif result = ~ /^Interrupted|^Timeout/
1607
1631
[" #{b} #{name}: #{result}" ]
1608
1632
else
@@ -1692,10 +1716,7 @@ function! s:update_ruby()
1692
1716
threads << Thread.new {
1693
1717
while pair = take1.call
1694
1718
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 ]
1699
1720
exists = File.directory ? dir
1700
1721
ok, result =
1701
1722
if exists
@@ -1716,15 +1737,15 @@ function! s:update_ruby()
1716
1737
if pull
1717
1738
log .call name, ' Updating ...' , :update
1718
1739
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
1720
1741
else
1721
1742
[true, skip ]
1722
1743
end
1723
1744
end
1724
1745
else
1725
1746
d = esc dir .sub (% r {[\\ /]+ $ }, ' ' )
1726
1747
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 {
1728
1749
FileUtils.rm_rf dir
1729
1750
}
1730
1751
end
@@ -2023,7 +2044,7 @@ function! s:preview_commit()
2023
2044
let b: plug_preview = ! s: is_preview_window_open ()
2024
2045
endif
2025
2046
2026
- let sha = matchstr (getline (' .' ), ' ^ \X*\zs[0-9a-z ]\{7}' )
2047
+ let sha = matchstr (getline (' .' ), ' ^ \X*\zs[0-9a-f ]\{7}' )
2027
2048
if empty (sha)
2028
2049
return
2029
2050
endif
@@ -2036,7 +2057,7 @@ function! s:preview_commit()
2036
2057
execute ' pedit' sha
2037
2058
wincmd P
2038
2059
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
2040
2061
normal ! gg" _dd
2041
2062
setlocal nomodifiable
2042
2063
nnoremap <silent> <buffer> q :q<cr>
0 commit comments