Refactor cmd expansion

This commit is contained in:
Marco Hinz 2018-04-13 15:01:47 +02:00
parent b199f9eec0
commit 12f28b1336
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F

View File

@ -225,7 +225,7 @@ function! sy#repo#debug_detection()
endif endif
for vcs in s:vcs_list for vcs in s:vcs_list
let cmd = s:expand_cmd(vcs) let cmd = s:expand_cmd(vcs, g:signify_vcs_cmds)
echohl Statement echohl Statement
echo cmd echo cmd
echo repeat('=', len(cmd)) echo repeat('=', len(cmd))
@ -255,7 +255,7 @@ function! sy#repo#diffmode() abort
echomsg 'Open an issue for it at: https://github.com/mhinz/vim-signify/issues' echomsg 'Open an issue for it at: https://github.com/mhinz/vim-signify/issues'
return return
endif endif
let cmd = s:expand_cmd_diffmode(vcs) let cmd = s:expand_cmd(vcs, g:signify_vcs_cmds_diffmode)
call sy#verbose('SignifyDiff: '. cmd, vcs) call sy#verbose('SignifyDiff: '. cmd, vcs)
let ft = &filetype let ft = &filetype
tabedit % tabedit %
@ -279,7 +279,7 @@ endfunction
" Function: s:initialize_job {{{1 " Function: s:initialize_job {{{1
function! s:initialize_job(vcs) abort function! s:initialize_job(vcs) abort
let vcs_cmd = s:expand_cmd(a:vcs) let vcs_cmd = s:expand_cmd(a:vcs, g:signify_vcs_cmds)
if has('win32') if has('win32')
if has('nvim') if has('nvim')
let cmd = &shell =~ 'cmd' ? vcs_cmd : ['sh', '-c', vcs_cmd] let cmd = &shell =~ 'cmd' ? vcs_cmd : ['sh', '-c', vcs_cmd]
@ -303,17 +303,8 @@ function! s:get_vcs_path(vcs) abort
endfunction endfunction
" Function: s:expand_cmd {{{1 " Function: s:expand_cmd {{{1
function! s:expand_cmd(vcs) abort function! s:expand_cmd(vcs, vcs_cmds) abort
let cmd = g:signify_vcs_cmds[a:vcs] let cmd = a:vcs_cmds[a:vcs]
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:vcs))
let cmd = s:replace(cmd, '%d', s:difftool)
let cmd = s:replace(cmd, '%n', s:devnull)
return cmd
endfunction
" Function: s:expand_cmd_diffmode {{{1
function! s:expand_cmd_diffmode(vcs) abort
let cmd = g:signify_vcs_cmds_diffmode[a:vcs]
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:vcs)) let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:vcs))
let cmd = s:replace(cmd, '%d', s:difftool) let cmd = s:replace(cmd, '%d', s:difftool)
let cmd = s:replace(cmd, '%n', s:devnull) let cmd = s:replace(cmd, '%n', s:devnull)
@ -325,7 +316,7 @@ function! s:run(vcs)
let [cwd, chdir] = sy#util#chdir() let [cwd, chdir] = sy#util#chdir()
try try
execute chdir fnameescape(b:sy.info.dir) execute chdir fnameescape(b:sy.info.dir)
let ret = system(s:expand_cmd(a:vcs)) let ret = system(s:expand_cmd(a:vcs, g:signify_vcs_cmds))
catch catch
" This exception message can be seen via :SignifyDebugUnknown. " This exception message can be seen via :SignifyDebugUnknown.
" E.g. unquoted VCS programs in vcd_cmds can lead to E484. " E.g. unquoted VCS programs in vcd_cmds can lead to E484.