From 12f28b1336c08357c332e599c3a07445298293af Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Fri, 13 Apr 2018 15:01:47 +0200 Subject: [PATCH] Refactor cmd expansion --- autoload/sy/repo.vim | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index f3d6a7f..b802c3d 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -225,7 +225,7 @@ function! sy#repo#debug_detection() endif for vcs in s:vcs_list - let cmd = s:expand_cmd(vcs) + let cmd = s:expand_cmd(vcs, g:signify_vcs_cmds) echohl Statement echo 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' return 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) let ft = &filetype tabedit % @@ -279,7 +279,7 @@ endfunction " Function: s:initialize_job {{{1 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('nvim') let cmd = &shell =~ 'cmd' ? vcs_cmd : ['sh', '-c', vcs_cmd] @@ -303,17 +303,8 @@ function! s:get_vcs_path(vcs) abort endfunction " Function: s:expand_cmd {{{1 -function! s:expand_cmd(vcs) abort - let cmd = g:signify_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] +function! s:expand_cmd(vcs, vcs_cmds) abort + 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) @@ -325,7 +316,7 @@ function! s:run(vcs) let [cwd, chdir] = sy#util#chdir() try 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 " This exception message can be seen via :SignifyDebugUnknown. " E.g. unquoted VCS programs in vcd_cmds can lead to E484.