First changes

This commit is contained in:
Marco Hinz 2017-01-17 14:22:19 +01:00
parent 379db4ad0b
commit 3ad10c65b5
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F
2 changed files with 87 additions and 31 deletions

View File

@ -55,12 +55,52 @@ function! sy#start() abort
" register buffer as active " register buffer as active
let b:sy.active = 1 let b:sy.active = 1
let [ diff, b:sy.type ] = sy#repo#detect() call sy#repo#detect(1)
" let [ diff, b:sy.type ] = sy#repo#detect()
" if b:sy.type == 'unknown'
" call sy#disable()
" return
" endif
" " register file as active with found VCS
" let b:sy.stats = [0, 0, 0]
" let dir = fnamemodify(b:sy.path, ':h')
" if !has_key(g:sy_cache, dir)
" let g:sy_cache[dir] = b:sy.type
" endif
" if empty(diff)
" " no changes found
" return
" endif
" inactive buffer.. bail out
elseif !b:sy.active
return
" retry detecting VCS
elseif b:sy.type == 'unknown'
call sy#repo#detect(0)
" update signs
else
let diff = sy#repo#get_diff_{b:sy.type}()[1]
let b:sy.id_top = g:id_top
endif
call sy#update_signs(diff, type)
endfunction
function! sy#update_signs(diff, type, do_register) abort
if b:sy.type == 'unknown' if b:sy.type == 'unknown'
echomsg 'DEBUG: type unknown'
" no VCS found
call sy#disable() call sy#disable()
return return
endif endif
if do_register
" register file as active with found VCS " register file as active with found VCS
let b:sy.stats = [0, 0, 0] let b:sy.stats = [0, 0, 0]
@ -73,24 +113,6 @@ function! sy#start() abort
" no changes found " no changes found
return return
endif endif
" inactive buffer.. bail out
elseif !b:sy.active
return
" retry detecting VCS
elseif b:sy.type == 'unknown'
let [ diff, b:sy.type ] = sy#repo#detect()
if b:sy.type == 'unknown'
" no VCS found
call sy#disable()
return
endif
" update signs
else
let diff = sy#repo#get_diff_{b:sy.type}()[1]
let b:sy.id_top = g:id_top
endif endif
if get(g:, 'signify_line_highlight') if get(g:, 'signify_line_highlight')
@ -99,7 +121,7 @@ function! sy#start() abort
call sy#highlight#line_disable() call sy#highlight#line_disable()
endif endif
call sy#sign#process_diff(diff) call sy#sign#process_diff(a:diff)
let b:sy.id_top = (g:id_top - 1) let b:sy.id_top = (g:id_top - 1)

View File

@ -16,19 +16,53 @@ function! sy#repo#detect() abort
endif endif
for type in vcs_list for type in vcs_list
let [istype, diff] = sy#repo#get_diff_{type}() call sy#repo#get_diff_{type}()
if istype
return [diff, type]
endif
endfor endfor
" let [istype, diff] = sy#repo#get_diff_{type}()
" if istype
" return [diff, type]
" endif
" endfor
return ['', 'unknown'] " return ['', 'unknown']
endfunction
" Function: s:callback_stdout_nvim {{{1
function! s:callback_stdout_nvim(_job_id, data, _event) dict abort
if empty(self.stdoutbuf) || empty(self.stdoutbuf[-1])
let self.stdoutbuf += a:data
else
let self.stdoutbuf = self.stdoutbuf[:2]
\ + [self.stdoutbuf[-1] . get(a:data, 0, '')
\ + a:data[1:]
endif
endfunction
" Function: s:callback_exit {{{1
function! s:callback_exit(_job_id, exitcode, _event) dict abort
let [found_diff, diff] = a:exitcode ? [0, ''] : [1, diff]
call sy#update_signs(found_diff, diff)
endfunction endfunction
" Function: #get_diff_git {{{1 " Function: #get_diff_git {{{1
function! sy#repo#get_diff_git() abort function! sy#repo#get_diff_git() abort
let diff = s:run(g:signify_vcs_cmds.git, b:sy_info.file) let cmd = (has('win32') && &shell =~ 'cmd')
return v:shell_error ? [0, ''] : [1, diff] \ ? g:signify_vcs_cmds.git
\ : ['sh', '-c', g:signify_vcs_cmds.git]
let cmd = s:expand_cmd(cmd, b:sy_info.file)
if exists('s:job_id_git')
silent! call jobstop(s:job_id_git)
endif
execute b:sy_info.chdir fnameescape(b:sy_info.dir)
try
let s:job_id_git = jobstart(cmd, {
\ 'stdoutbuf': [],
\ 'on_stdout': function('s:callback_stdout_nvim'),
\ 'on_exit': function('s:callback_exit'),
\ })
finally
execute b:sy_info.chdir b:sy_info.cwd
endtry
endfunction endfunction
" Function: #get_diff_hg {{{1 " Function: #get_diff_hg {{{1