Refactoring
This commit is contained in:
parent
fcecc3c868
commit
6c2b6c4f08
@ -47,7 +47,7 @@ function! sy#start() abort
|
|||||||
\ 'path' : sy_path,
|
\ 'path' : sy_path,
|
||||||
\ 'buffer': bufnr(''),
|
\ 'buffer': bufnr(''),
|
||||||
\ 'active': 0,
|
\ 'active': 0,
|
||||||
\ 'type' : 'unknown',
|
\ 'vcs' : 'unknown',
|
||||||
\ 'hunks' : [],
|
\ 'hunks' : [],
|
||||||
\ 'id_top': g:id_top,
|
\ 'id_top': g:id_top,
|
||||||
\ 'stats' : [-1, -1, -1] }
|
\ 'stats' : [-1, -1, -1] }
|
||||||
@ -60,17 +60,17 @@ function! sy#start() abort
|
|||||||
elseif !b:sy.active
|
elseif !b:sy.active
|
||||||
call sy#verbose('Inactive buffer.')
|
call sy#verbose('Inactive buffer.')
|
||||||
return
|
return
|
||||||
elseif b:sy.type == 'unknown'
|
elseif b:sy.vcs == 'unknown'
|
||||||
call sy#verbose('Retry detecting VCS.')
|
call sy#verbose('Retry detecting VCS.')
|
||||||
call sy#repo#detect(0)
|
call sy#repo#detect(0)
|
||||||
else
|
else
|
||||||
call sy#verbose('Updating signs.')
|
call sy#verbose('Updating signs.')
|
||||||
call sy#repo#get_diff_start(b:sy.type, 0)
|
call sy#repo#get_diff_start(b:sy.vcs, 0)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! sy#set_signs(diff, do_register) abort
|
function! sy#set_signs(diff, do_register) abort
|
||||||
if b:sy.type == 'unknown'
|
if b:sy.vcs == 'unknown'
|
||||||
call sy#verbose('No VCS found. Disabling.')
|
call sy#verbose('No VCS found. Disabling.')
|
||||||
call sy#disable()
|
call sy#disable()
|
||||||
return
|
return
|
||||||
@ -81,7 +81,7 @@ function! sy#set_signs(diff, do_register) abort
|
|||||||
let b:sy.stats = [0, 0, 0]
|
let b:sy.stats = [0, 0, 0]
|
||||||
let dir = fnamemodify(b:sy.path, ':h')
|
let dir = fnamemodify(b:sy.path, ':h')
|
||||||
if !has_key(g:sy_cache, dir)
|
if !has_key(g:sy_cache, dir)
|
||||||
let g:sy_cache[dir] = b:sy.type
|
let g:sy_cache[dir] = b:sy.vcs
|
||||||
endif
|
endif
|
||||||
if empty(a:diff)
|
if empty(a:diff)
|
||||||
call sy#verbose('No changes found.')
|
call sy#verbose('No changes found.')
|
||||||
|
@ -14,7 +14,7 @@ function! sy#debug#list_active_buffers() abort
|
|||||||
|
|
||||||
echo "\n". path ."\n". repeat('=', strlen(path))
|
echo "\n". path ."\n". repeat('=', strlen(path))
|
||||||
|
|
||||||
for k in ['active', 'buffer', 'type', 'stats', 'id_top']
|
for k in ['active', 'buffer', 'vcs', 'stats', 'id_top']
|
||||||
if k == 'stats'
|
if k == 'stats'
|
||||||
echo printf("%10s = %d added, %d changed, %d removed\n",
|
echo printf("%10s = %d added, %d changed, %d removed\n",
|
||||||
\ k,
|
\ k,
|
||||||
|
@ -15,8 +15,8 @@ function! sy#repo#detect(do_register) abort
|
|||||||
\ g:sy_cache[b:sy_info.dir] .'"')
|
\ g:sy_cache[b:sy_info.dir] .'"')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
for type in vcs_list
|
for vcs in vcs_list
|
||||||
call sy#repo#get_diff_start(type, a:do_register)
|
call sy#repo#get_diff_start(vcs, a:do_register)
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ function! sy#repo#get_diff_start(vcs, do_register) abort
|
|||||||
\ 'do_register': a:do_register,
|
\ 'do_register': a:do_register,
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
let cmd = s:expand_cmd(g:signify_vcs_cmds[a:vcs], b:sy_info.file)
|
let cmd = s:expand_cmd(a:vcs)
|
||||||
let cmd = (has('win32') && &shell =~ 'cmd') ? cmd : ['sh', '-c', cmd]
|
let cmd = (has('win32') && &shell =~ 'cmd') ? cmd : ['sh', '-c', cmd]
|
||||||
|
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
@ -94,10 +94,10 @@ function! sy#repo#get_diff_start(vcs, do_register) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:get_diff_end {{{1
|
" Function: s:get_diff_end {{{1
|
||||||
function! s:get_diff_end(found_diff, type, diff, do_register) abort
|
function! s:get_diff_end(found_diff, vcs, diff, do_register) abort
|
||||||
call sy#verbose('s:get_diff_end()', a:type)
|
call sy#verbose('s:get_diff_end()', a:vcs)
|
||||||
if a:found_diff
|
if a:found_diff
|
||||||
let b:sy.type = a:type
|
let b:sy.vcs = a:vcs
|
||||||
endif
|
endif
|
||||||
if !a:do_register
|
if !a:do_register
|
||||||
let b:sy.id_top = g:id_top
|
let b:sy.id_top = g:id_top
|
||||||
@ -202,28 +202,14 @@ function! sy#repo#debug_detection()
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let vcs_args = {
|
|
||||||
\ 'git': [g:signify_vcs_cmds.git, b:sy_info.file],
|
|
||||||
\ 'hg': [g:signify_vcs_cmds.hg, b:sy_info.path],
|
|
||||||
\ 'svn': [g:signify_vcs_cmds.svn, b:sy_info.path],
|
|
||||||
\ 'darcs': [g:signify_vcs_cmds.darcs, b:sy_info.path],
|
|
||||||
\ 'bzr': [g:signify_vcs_cmds.bzr, b:sy_info.path],
|
|
||||||
\ 'fossil': [g:signify_vcs_cmds.fossil, b:sy_info.path],
|
|
||||||
\ 'cvs': [g:signify_vcs_cmds.cvs, b:sy_info.file],
|
|
||||||
\ 'rcs': [g:signify_vcs_cmds.rcs, b:sy_info.path],
|
|
||||||
\ 'accurev': [g:signify_vcs_cmds.accurev, b:sy_info.file],
|
|
||||||
\ 'perforce': [g:signify_vcs_cmds.perforce, b:sy_info.path],
|
|
||||||
\ 'tfs': [g:signify_vcs_cmds.tfs, b:sy_info.file],
|
|
||||||
\ }
|
|
||||||
|
|
||||||
for vcs in s:vcs_list
|
for vcs in s:vcs_list
|
||||||
let cmd = s:expand_cmd(vcs_args[vcs][0], vcs_args[vcs][1])
|
let cmd = s:expand_cmd(vcs)
|
||||||
echohl Statement
|
echohl Statement
|
||||||
echo cmd
|
echo cmd
|
||||||
echo repeat('=', len(cmd))
|
echo repeat('=', len(cmd))
|
||||||
echohl NONE
|
echohl NONE
|
||||||
|
|
||||||
let diff = call('s:run', vcs_args[vcs])
|
let diff = s:run(vcs)
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
echohl ErrorMsg
|
echohl ErrorMsg
|
||||||
echo diff
|
echo diff
|
||||||
@ -235,20 +221,26 @@ function! sy#repo#debug_detection()
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Function: s:get_vcs_path {{{1
|
||||||
|
function! s:get_vcs_path(vcs) abort
|
||||||
|
return (a:vcs =~# '\v(git|cvs|accurev|tfs)') ? b:sy_info.file : b:sy_info.path
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Function: s:expand_cmd {{{1
|
" Function: s:expand_cmd {{{1
|
||||||
function! s:expand_cmd(cmd, path) abort
|
function! s:expand_cmd(vcs) abort
|
||||||
let cmd = s:replace(a:cmd, '%f', a:path)
|
let cmd = g:signify_vcs_cmds[a:vcs]
|
||||||
let cmd = s:replace(cmd, '%d', s:difftool)
|
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:vcs))
|
||||||
let cmd = s:replace(cmd, '%n', s:devnull)
|
let cmd = s:replace(cmd, '%d', s:difftool)
|
||||||
|
let cmd = s:replace(cmd, '%n', s:devnull)
|
||||||
let b:sy_info.cmd = cmd
|
let b:sy_info.cmd = cmd
|
||||||
return cmd
|
return cmd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function: s:run {{{1
|
" Function: s:run {{{1
|
||||||
function! s:run(cmd, path)
|
function! s:run(vcs)
|
||||||
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
|
||||||
try
|
try
|
||||||
let ret = system(s:expand_cmd(a:cmd, a:path))
|
let ret = system(s:expand_cmd(a:vcs))
|
||||||
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user